Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT




Loading

vTaskDelayUntil and vTaskSuspend

Posted by acehigh1971 on September 27, 2006
I would like to control a periodic task by suspending and resuming it with vTaskSuspend.

Suppose I have a task that is running:

aTask
{
for(;;)
{
..
..
..
vTaskDelayUntil(&LastWake,10/portTICK_RATE_MS);
}
}

and in another task I suspend this one by calling

vTaskSuspend(aTask_handle);


The problem which I encounter is that when I call:

vTaskResume(aTask_handle);

the task "aTask" runs for the amount of times needed to reach the current tick time continuosly and then runs again periodically as vTaskDelayUntil tells. Obviously other tasks interrupt it.
This is not good as when I resume this task I want that this task runs periodically again, immediatly.
It seems that the variable LastWake is not updated well if I do a suspend/resume.
Please note that if I do a suspend which lasts some minutes, the task runs for a lot of times continuously, not respecting the 10ms delay time.

Is there something I can do?
Am I wrong in using suspend and resume?
Am I wrong in using vTaskDelayUntil (obviously I don't want to use vTaskDelay as I want to perform the operations every 10 ms)?
Should I use instead a semaphore?

Any suggestion is appreciated, thanks.

RE: vTaskDelayUntil and vTaskSuspend

Posted by Nobody/Anonymous on September 27, 2006
When you block a task using TaskDelayUntil it is moved onto the delayed list. If you then suspend it it will be moved from the delayed list to the suspended list. Finally calling TaskResume() will then move it from the suspended list to the ready list. The important thing here is that it will be moved to the ready list even if the block time has not expired - it does not remember that it came from the delayed task list. Its state was changed from delayed to suspended to ready.

The previous wake time will be updated prior to the task being moved from the delayed list to the suspended list, so this variable should remain correct.

If the task is moved from the suspended list to the ready list it could run before the wanted next execution time. You could prevent this by checking the tick count value after the call to vTaskDelayUntil() then adjust the wait time and call delay again.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS