rtel wrote on Tuesday, July 05, 2005:
Taking the example:
void vTaskFunction( void * pvParameters )
const portTickType xFrequency = 10;
____// Initialise the xLastWakeTime variable with the
____xLastWakeTime = xTaskGetTickCount();
____for( ;; )
________// Wait for the next cycle.
________vTaskDelayUntil( &xLastWakeTime, xFrequency );
________// Perform action here.
xLastWakeTime holds the time in ticks the task was last unblocked from the vTaskDelayUntil() call. When vTaskDelayUntil() is called again the block time is added to xLastWakeTime to create the time at which the task should again be unblocked.
For example, if xLastWakeTime is 1000, the delay period is 100 and 50 ticks have passed since the task last unblocked then: xLastWakeTime is set to 1100, the current time is 1050 and the task will block for 50 ticks (until the actual time reaches the wanted unblock time).
Now if the time that has passed between calles is greater than the block time then the value of xLastWakeTime will be less than the current time and the task will not block.
For example, if xLastWakeTime is 1000, and the delay period is 100, but 200 ticks have passed since the task was last unblocked then: xLastWakeTime will be set to 1100 but the current time will be 1200. If the task wants to unblock at time 1100 but the time is already 1200 then the unblock time has passed and the task never blocks.
This is what will happen if you suspend the task - and is the correct behaviour. The tick count continues when the task is suspended so the wanted wake time will be less than the current time and the task will not block.
To get around this you will need to reinitialise xLastWakeTime when the task is unblocked using:
xLastWakeTime = xTaskGetTickCount();
This should only be done when the task unblocks, not each cycle of the loop.
This line will refresh the xLastWakeTime with the current time, so the generated block time is relative to the current time, not the time the task last unblocked.
Maybe I have made this sound too complex (?) it is not really.