Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

FreeRTOS : understanding vTaskDelay() import of Nordic SDK

using RF5_SDK_15.2.0 and looking at the one of the examples: blinky with freeRTOS:

nRF5_SDK_15.2.0_9412b96\examples\peripheral\blinky_freertos\main.c

I see that in the function call to  vTaskDelay there is no division by portTICK_PERIOD_MS

how do you guarantee vTaskDelay to work in ms time ? since this is contradicting the following article from freeRTOS : https://www.freertos.org/a00127.html

and another question related to this problem, in any case I do wish to divide by portTICK_PERIOD_MS, I might get division by zero error and in our source code we actually do because 

portTICK_PERIOD_MS is defined as : 

#define portTICK_PERIOD_MS          ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
and in our case configTICK_RATE_HZ is defined to be 1024 and the end result is zero since TickType_T is a uint32_t.
best regards , Yarin.
  • I think this example was written when we incorrectly used configTICK_RATE_HZ as 1000 which made the developer assume that 1 tick = 1ms.

    Later we realized that with RTC 1000 ticks cannot be produced so we change the tick rate to 1024 and yes that meant that each tick is around 0.9765ms.
    So it is documentation bug to say that TASK_DELAY is 200ms and not 200 ticks.

    how do you guarantee vTaskDelay to work in ms time ? since this is contradicting the following article from freeRTOS : https://www.freertos.org/a00127.html

    portTICK_PERIOD_MS is practically useless with this prescalar. Like you have figured out this will give 0 and hence all your conversions using this will be incorrect. There will be no exact conversion of ms to ticks without using float, so I can suggest you use something like this
    #define portMS_FROM_TICKS_CUSTOM(X)            ( (X * 1000) / configTICK_RATE_HZ )
    
    #define portTICKS_FROM_MS(X)                   ( (X *configTICK_RATE_HZ) / 1000 )
    This will be very inefficient the lower the X gets. If you want better accuracy with timings and conversions to be very accurate, then I do not think using RTC as main RTOS clock works for you. Then you need to use other high accuracy clocks.
Related