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.
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