vTaskDelay Parameter Query

Hi,

I’m new to FreeRTOS and I have a curious query about vTaskDelay. 1) What is the functional difference (besides datatype) and 2) are there specific use cases where one would be better than the other between passing literal 500, passing const TickType_t, and passing pdMS_TO_TICKS(500)? Thanks in advance!

FreeRTOS configures a time source to generate a periodic interrupt, which is called the tick interrupt. The interrupt is used to, among other things, unblock tasks that are blocked with a timeout and to switch between tasks. The tick interrupt rate can be configured using configTICK_RATE_HZ.

vTaskDelay will delay a task for a given number of tick periods. Hence, the parameter type is TickType_t .

vTaskDelay(500) will delay the task for 500 ticks, so the time your task will get delayed depends on your tick rate [configTICK_RATE_HZ]. Whereas macro pdMS_TO_TICKS() converts milliseconds to ticks. pdMS_TO_TICKS(500) gives 500 ms equivalent number of ticks, which will be based on yourconfigTICK_RATE_HZ. With vTaskDelay(pdMS_TO_TICKS(500)) even if your configTICK_RATE_HZ is changed later on, your task delay will be 500 ms.

1 Like