FIFO Scheduling and using the _time_delay()

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

FIFO Scheduling and using the _time_delay()

651 Views
RayS
Contributor I

Hello! I'm about 2-3 months into using Freescale Coldfire and MQX
My question is simple, hopefully...
Here is my setup info:

/* Task number, Entry point, Stack, Pri, String, Auto? */
{MAIN_TASK, Main_task, 2000, 9, "main", MQX_AUTO_START_TASK},
{COMMS_TASK, rs232_task, 1000, 10, "rs232", 0, 0, 0},
{TCP_TASK, TCP_task, 1000, 10, "tcpt", 0, 0, 0},
{UDP_TASK, UDP_task, 1000, 10, "udpt", 0, 0, 0},
{0, 0, 0, 0, 0, 0, }};

The Main task creates the RS232 task, TCp task and UDP task, that is all it does.
The RS232 I've configured as ISR based, so there is a 128 byte buffer to catch data, (I changed the original 64)
I assume there are also buffers with the sockets.
Each task uses an infinite while(1) loop with a non blocking recv(), so, I add a _time_delay(250)


When the task encounters the _time_delay(xxx) it proceeds to cleanup, storing the task info, and putting it in a delay queue, per the MQXUG...
However, it will NOT become Active again after 250, rather it will be placed AT THE BACK of the FIFO queue since all are the same priority...Am I correct in this assumption?
If this is true, it is not necessary to for me to use such a long time delay, 10 ms would be enough to quit running and go to the next task in the FIFO

Thanks for looking!

Ray

0 Kudos
1 Reply

288 Views
DavidS
NXP Employee
NXP Employee

Hi Ray,

The opeation sounds correct for fifo mode.

Since all task have the same level priority, when you _time_delay(xxx) the task sleeps and is awaken by the schedule.  If it is the highest prioirty it would then run.  But since it has same priority as the other two task, it goes to the end of the line.  Your other two tasks must block in order for the fifo ordering to change.

 

Another option would be to use Round Robin (each task keeps the same priority level) but add a time slice value flag and value (in msec) to the task template.

Ex:

const TASK_TEMPLATE_STRUCT  MQX_template_list[] =
{
   /* Task Index,   Function,    Stack,  Priority,  Name,       Attributes,          Param, Time Slice */
    { SERVER_TASK,  server_task, 2000,   8,         "server",   MQX_AUTO_START_TASK, 0,     0 },
    { CLIENT_TASK1,  client_task1, 1000,   8,         "client1",  MQX_TIME_SLICE_TASK, 0,     125 },       

    { CLIENT_TASK2,  client_task2, 1000,   8,         "client2",  MQX_TIME_SLICE_TASK, 0,     125 },       

    { CLIENT_TASK3,  client_task3, 1000,   8,         "client3",  MQX_TIME_SLICE_TASK, 0,     125 },   


    { 0 }
};

 

Here each of the CLIENT tasks runs for 125ms, then blocks, goes to the end of the fifo when awaken, and after the other two CLIENT task have had their chance to run, the CLIENT_TASK1 will run again.

Hope this helps.

Regards,

David