cancel
Showing results for 
Search instead for 
Did you mean: 

Is it bad design to have a freeRTOS Task poll xTaskGetTickCount() with a vTaskDelay(1)?

LMorr.3
Senior II

I have a task which is responsible for triggering a pin, sometimes at a short period of a few ms. I created a freeRTOS Task which has a while(1) loop polling xTaskGetTickCount() with a vTaskDelay(1). If all my tasks have the same level priority ( for now ), is this enough for the task to allow other tasks to do their work? I tried designing my solution using interrupts but rather go with the polling solution if it is ok.

2 REPLIES 2
Nikita91
Lead II

In fact you are using an interrupt for your task: the tick interrupt!

It's very common to have a task waiting for the tick, as long as this task does very little.

You say "short period of a few ms": so perhaps you can use a delay of few ms...

If you want to drive the pin with a fairly precise timing, you must consider that the driving task has a higher priority than the others

It might be more efficient to wake the task only when it has something to do: maybe with task notification from another task.

If the work to do at every tick is very short you can consider using the tick hook Function. This is more efficient since it will avoid 2 context switching at every tick (the hook function is called from he tick interrupt handler).

As often there are several ways to do something...

Pavel A.
Evangelist III

Everything (almost) is relative. There are worse designs, so don't think this one is too bad.