This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RTOS/TM4C1294NCPDT: Semaphore post and pend inside task calling function

Part Number: TM4C1294NCPDT

Tool/software: TI-RTOS

Hi,

I want to use two print statements in each of my task,

1. CCS print that is done by System_printf("Strings");, hope this print is made through JTAG.

2.Uart Print that is done by me to print in Teraterm console, the following is the sample code that I have did in my code.

/*below initialization is made in main.c */

    Semaphore_Params_init(&Sem_Uart_Params);
    Semaphore_construct(&Sem_Uart_Struct, 1, &Sem_Uart_Params);
    /* Obtain instance handle */
    Sem_Uart_Handle = Semaphore_handle(&Sem_Uart_Struct);

/* below is the uart print function, that is used to call in every task */
void UartPrint( const char *fmt, ... )
{
 Semaphore_pend(Sem_Uart_Handle, BIOS_WAIT_FOREVER);

/*Code that works with the string*/

Semaphore_post(Sem_Uart_Handle);

}

/* below is the task I am using to print in ccs console as well as serial port console using uart*/

void task()

{

System_printf("Strings");

System_flush();

Uart_print("String");

}

My question is:

1. Can I use semaphore post and pend in a function, that is called inside a task?

2.i am using a mutex lock in uart print, so that another uart print will not act simultaneously missing any characters to print in console. The thing is, if I use many task, both the css and uart printing non-uniform

string characters to console.

3. both the console should print same characters only right? but the order is completely different.why?

  • Hi Manohar,

    Manohar B said:
    Can I use semaphore post and pend in a function, that is called inside a task?

    Yes. You can do this.

    Manohar B said:
    2.i am using a mutex lock in uart print, so that another uart print will not act simultaneously missing any characters to print in console. The thing is, if I use many task, both the css and uart printing non-uniform

    It depends on the priority of the tasks. Lets say you are going to print "hello" in task1 with priority 1 (low) and "weather" in a task2 with priority 2 (higher). If task1 is running and after System_flush but before Uart_print, task2 becomes ready to run (e.g. it's Task_sleep expired). Task2 will start to run and could call all 3 functions. So the final output would be CCS

    hello

    weather

    but on the UART it would be 

    weather 

    hello

    Note: the UART_write could block and therefore context switch to a lower priority task also.

    Todd

  • Thank you Todd,

    I am having a HWI inside which same ccs print and uart print I am using, The problem is I cannot use a ccs print or a uart print inside ISR. When print is getting stopped once ISR is raised.

    /*below is my ISR function */
    void DigitalInputISRHandler()
    {


    System_printf("HWI is raised \n");
    System_flush();

    Uart_print("HWI is raised \n");

    (* (volatile uint32_t *)clearFlagaddr) = bit_shift;
    GPIO_toggle(Board_LED0);
    }

    if I neither use the print, the LED is toggling whenever ISR is raised. But if I use either of the print, the whole program is getting stopped.

    My question:
    1. Uart print is the function created by me which having semaphore, is the problem is because of semaphore?
    2.What actually System_flush() function is doing? is this function also having semaphore?
    3.Why I cannot use neither of the print statements inside the ISR?


    Regards,
    Manohar
  • I expect you are using UART_write in the UartPrint function. This is a problem since you can only call this API from a Task. Internally it calls Semaphore_pend with a timeout which is not allowed in a ISR.

    I'm assuming you are using SysMin in the .cfg file. The System_printf/System_flush should work in this case. The System_printf writes the ASCII string to an internal buffer (overwritting if it is full). The System_flush flushes the data to a CIO buffer. When the CIO is full or if a newline is in the data, a breakpoint is hit and CCS reads the data and displays it to the CCS console. CCS resumes the target then. This occurring in an ISR should be fine (other than it messes up realtime). Can you confirm that you are using SysMin? If you call System_flush, what happens. Could you System stack not be big enough? You can check in Tools->ROV->Hwi->Module to see the system stack peak.

    Todd