FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [July 2005 Threads] Using vTaskSuspend/vTaskResumePosted by Nobody/Anonymous on July 5, 2005 Hello!
I want to use vTaskSuspend to suspend a task from sampling values. When the task is not suspended I use vTaskDelayUntil in order to get the task to execute every 1000 ticks. BUT, when the task has been suspended for some time and then resumed this delay does not apply for some reason. The task executes without any delay until it has "caught up" with the time somehow??!! Why is this and how do I fix it??
Thanks! /MB
RE: Using vTaskSuspend/vTaskResumePosted by Richard on July 5, 2005 Taking the example:
void vTaskFunction( void * pvParameters ) { portTickType xLastWakeTime; const portTickType xFrequency = 10;
____// Initialise the xLastWakeTime variable with the ____current time. ____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.
Regards.
RE: Using vTaskSuspend/vTaskResumePosted by Nobody/Anonymous on July 5, 2005 That's absolutely fine, I understood! It solved my problem! Thanks
//MB
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|