Vtaskdelayuntil placement

Hi,

I am wondering if there is any reason that vtaskdelayuntil should be at the beginning of the tasks while loop as shown here https://www.freertos.org/vtaskdelayuntil.html

 for( ;; )
 {
     // Wait for the next cycle.
     vTaskDelayUntil( &xLastWakeTime, xFrequency );

     // Perform action here.
 }

or

 for( ;; )
 {
     // Perform action here.

     // Wait for the next cycle.
     vTaskDelayUntil( &xLastWakeTime, xFrequency );
 }

many thanks

It purely depends on if you want to do the actions immediately after startup or only after the delay.

In many cases, the vTaskDelayUntil() will be replaced with the waiting for a queue or semaphore, in which case that will almost always be at the top of the loop (we don’t have the request to process until it happens). There are cases though where the wait is for something we have done to be completed and we are no ready to do it again, in which case we do want to do it at start, so the test is at the end.