What is the effect if a task is suspended with vTaskSuspend() that has vTaskDelayUntil() in the task?
When the task is resumed - will it pick up with the tick count as is before it was suspended or does the
tick count resume after vTaskResume() is called?
For example - let’s say that task1() has an xFrequency 250 - it runs at
xTickCount = 250
Let’s say it is suspended at xTickCount = 260.
Let’s say it is resumed at xTickCount = 270.
Does the task run again at xTickCount = 500 or xTickCount = 510 (520)?
The vTaskDelayUntil() maintains an absolute time at which the task is to execute again. There is only a single tick count maintained by the kernel, which is continuously measuring the passing of time. vTaskDelayUntil() will suspend the task until the tick count has equalled the wake time (passed into vTaskDelayUntil()). If the wake time contains a time that has already passed then the task will not suspend at all.
The task calling vTaskDelayUntil() suspends itself.
When vTaskSuspend() is called the task suspends, and remains suspended until resumed by another task.
The value of xNextWakeTime does not change while the task is suspended, and the behavior is predictable. When the task is resumed it calls vTaskDelayUntil() again and will delay until the time at which you have requested to be unblocked which is 200 ticks after the previous time you unblocked. The fact you have been suspended in between has no bearing on this UNLESS you have been suspended for more than 200 ticks. If you have been suspended for more than 200 ticks then when you call xTaskDelayUntil() the time ( xNextWakeTime + 200 ) will already have passed. You are asking to be woken at a time that has already elapsed, so you don’t block at all.
OK - thanks. So - if the time for vTaskDelayUntil() has passed while the task has been suspended - it will execute immediately when vTaskResume() is called.
This makes sense - and thanks for clarifying. I’m glad it works this way.
Not sure if this was the question - but its a bit ambiguous maybe.
When task1 calls vTaskDelayUntil it is placed in a list of delayed tasks.
When task2 suspends task1, task1 is removed from the delayed list and placed in the suspended list. Tasks in the suspended list are just left to fester and are not touched.
When task2 resumes task1, task1 is removed from the suspended list and placed in the ready list. This will happen no matter what the elapsed time (more, equal to or less than 200). The resume supersedes the delay until.