Quality RTOS & Embedded Software

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




Loading

Using vTaskSuspend/vTaskResume

Posted 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/vTaskResume

Posted 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/vTaskResume

Posted by Nobody/Anonymous on July 5, 2005
That's absolutely fine, I understood! It solved my problem! Thanks

//MB


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




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists