Updated Jul 2025
xTaskDelayUntil()
task. h
1BaseType_t xTaskDelayUntil( TickType_t *pxPreviousWakeTime,2 const TickType_t xTimeIncrement );
INCLUDE\_xTaskDelayUntil
Delay a task until a specified time. This function can be used by periodic tasks to ensure a constant execution frequency.
This function differs from
vTaskDelay()
vTaskDelay()
vTaskDelay()
xTaskDelayUntil()
pxPreviousWakeTime
vTaskDelay()
vTaskDelay()
xTaskDelayUntil()
Whereas
vTaskDelay()
xTaskDelayUntil()
The macro
pdMS\_TO\_TICKS()
Parameters:
-
pxPreviousWakeTime
Pointer to a variable that holds the time at which the task was last unblocked. The variable must be initialised with the current time prior to its first use (see the example below). Following this the variable is automatically updated within
.xTaskDelayUntil() -
xTimeIncrement
The cycle time period. The task will be unblocked at time
. Calling(*pxPreviousWakeTime + xTimeIncrement)with the samexTaskDelayUntilparameter value will cause the task to execute with a fixed interval period.xTimeIncrement
Returns:
A value which can be used to check whether the task was actually delayed:
pdTRUE
pdFALSE
Example usage:
12// Perform an action every 10 ticks.3void vTaskFunction( void * pvParameters )4{5TickType_t xLastWakeTime;6const TickType_t xFrequency = 10;7BaseType_t xWasDelayed;89 // Initialise the xLastWakeTime variable with the current time.10 xLastWakeTime = xTaskGetTickCount ();11 for( ;; )12 {13 // Wait for the next cycle.14 xWasDelayed = xTaskDelayUntil( &xLastWakeTime, xFrequency );1516 // Perform action here. xWasDelayed value can be used to determine17 // whether a deadline was missed if the code here took too long.18 }19}20