vTaskDelayUntil() vs software timer

aprados wrote on Tuesday, January 15, 2019:

Hello all,

i´m quite new to the FreeRTOS world. I´m in the reading and learning phase now.

I was wondering, what are the advantages of using a software timer (for a function called periodically) instead of calling vTaskDelayUntil() in a function called by the scheduler?

Calling vTaskDelayUntil() would put the task on “blocked” state. In which state would be a software timer callback that is waiting to be triggered?

Thank you!

richarddamon wrote on Tuesday, January 15, 2019:

vTaskDelayUntil will create a new task to do the operation, while using a timer will have the code work as a call back of the Timer/Service Task.

Putting the code in a timer will have the advantage of possibly saving memory, as you don’t need to create a new task, with its stack, as you are using the stack of the Timer/Service task.

There are several disadvantages though:
A timer callback, since it uses the Timer/Service task will have the Priority of the Timer Service task, which means you can’t make it run at a higher or lower task priority.

A timer callback is not supposed to block (to avoid affecting other timer callbacks), so if the routine needs to do operations that will block you should use a task instead.

If the operation will take significant time, it should not be a timer callback as that will affect other timer callbacks.

Generally I use timer callbacks for very short, light weight operations, and use a task for heavier weight operations. I typically have the Timer task set as one of the, if not the, highest priority tasks, so timer callback should be operations that would qualify for that sort of priority and don’t need to block, which also implies the quick opeation.

1 Like