If I summarize:
vTaskDelay(n) will delay a task by a minimum of n-1 ticks. It could be more depending on scheduling, but it can certainly be less than n.
May I propose to update the documentation on the website to reflect this behavior ?
The documentation currently states:
Delay a task for a given number of ticks. The actual time that the task remains blocked depends on the tick rate. The constantā¦
I recommend something along the lines of:
Delay a task for a given number of ticks. The actual time that the task remains blocked depends on the tick rate and the moment in the tick when the function is called. The minimum time the task will block is could be shorter by up to 1 tick. The constantā¦
We can certainly update the vTaskDelay() documentation - but this behaviour isnāt specific to vTaskDelay() - any function that accepts a block time in ticks (reading from or writing to a queue, stream buffer, message buffer, semaphore, mutex, etc.) has the resolution of the tick frequency, which is an integer. So it may be better to either introduce another section on the website, perhaps under ātask statesā where it talks about entering the Blocked state, or in the book, if that doensāt already mention it (maybe section 3.7 āTime Measurement and the Tick Interruptā).
This has also bitten me in the past until I realized that all functions that take a block time n (in ticks) blocks up to n ticks (and when you realize, itās pretty obvious why). To put it another way, if you block/delay for 1 tick, it blocks until the next tick occurs, and so forth.
I think it would be a good idea to document this somewhere where itās unlikely people will miss it.
The big problem is that the only place people canāt miss it is to repeat it every time it is mentioned (or at least add a reference note each time it is mentioned) which gets very repetitive.
People historically show that they are very bad at looking at general overview sections because they want to just get coding.
Glad to see that Iām not the only one who struggled with this. I think @rtelās suggestion might be the best here:
So it may be better to either introduce another section on the website, perhaps under ātask statesā where it talks about entering the Blocked state
My suggestion is the following then
To have a short dedicated page on the website that explains that on all APIs with delays or timeouts, the first tick is a actual the fraction of a tick (small diagram would help here)
In each API reference page where such delay of timeout parameter is used, have a blanket statement with a link to the dedicated page. āMore info on ticks resolution in the blocked stateā
Hello @maharvey! I realize itās been a while, but I want to let you know Iāve applied your feedback to the FreeRTOS documentation. You can find a detailed page on the tick resolution here as well as a dedicated FAQ item linking to this here.
If you feel like something needs to be better worded or diagrams corrected, donāt hesitate to use the āReport and Error on this pageā option.