Luca Corna

Issue  with FreeRTOS  priorities

Discussion created by Luca Corna on May 10, 2019
Latest reply on May 14, 2019 by Erich Styger

Hallo,

I am developing my application on FreeRTOS port from NXP for ImX8.

 

I am creating just as demo 2 simple task. The first (loop_task) contains just a while(1) with a counter++. The second (uart_task) a while(1) with the API UART_RTOS_Send.

 

void loop_task()

{

   static int counter;

   while(1)

   counter++;

}

 

void uart_task()

{

   while(1)

   {

      UART_RTOS_Send(handle, &out_buffer, strlen(out_buffer));

   }

}

 

I have the following behaviors in the following cases:

 

case 1

#define configUSE_PREEMPTION       1

 

xTaskCreate(loop_task, "loop_task", 200, NULL, 3, NULL);

xTaskCreate(uart_task, "uart_task", 200, NULL, 4, NULL);

 

The uart task send the first time the buffer and then correctly yields. The scheduler put the loop_task in running. So far so good.

Then (depending on my tick configuration), when the uart_task is ready, the scheduler should put loop_task in ready and uart_task in running. But this does not happens. After the first "send" the uart_task starves. The situation I encounter should occur with #define configUSE_PREEMPTION    0.

 

case 2

#define configUSE_PREEMPTION       1

 

xTaskCreate(loop_task, "loop_task", 200, NULL, 2, NULL);

xTaskCreate(uart_task, "uart_task", 200, NULL, 4, NULL);

 

Just changing the loop_task from 3 to 2 made the application work as expected. Where is the trick? is it a bug of FreeRTOS port or what?

Outcomes