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


returning at *beginning* of task after vTaskD

Posted by IvanSB on April 19, 2011
I've 2 tasks one that parse input the other that execute actions:

vTaskAction(void *pvParameters ) {
for(;;) {
// resume here
switch (phase) {

case a_state1:

// do something
// do something else

vTaskInput(void *pvParameters ) {
for(;;) {
// change phase according to input

I'm using vTaskDelay because it frees CPU cycles inspite of using an internal counter to "delay".

Now suppose vTaskAction is waiting after it execude vTaskDelay, vTaskInput kicks in and change phase.

I'd like vTaskInput to be able to make vTaskAction to conditionally resume from the beginning of vTaskAction and not from the end of vTaskDelay.

Is there a way I can make a task wait (and not consume cpu cycles) and conditionally restart from where I stopped it OR "reset" the Task and start from the beginning eg. as if the Task was just created and resumed?

RE: returning at *beginning* of task after vTaskD

Posted by Dave on April 19, 2011
Instead of calling vTaskDelay( delay_time ), call xQueueReceive( ..., ..., delay_time ) so delay_time is the block time. Now if you want the task to restart, send a message to the queue telling the task to restart. If it does not receive a message on the queue it will time out and continue as before.

Another way might be to simply delete then restart the task, but that is probably not a good way.

RE: returning at *beginning* of task after vTaskD

Posted by IvanSB on April 20, 2011

If I push something in the queue from vTaskInput, vTaskAction will resume execution.

Is there a way to know how much time passed?

One way could be to use xTaskGetTickCount() but I'm not really sure if it gets the work done as I expect (eg. how overflow should be handled?).


RE: returning at *beginning* of task after vTaskD

Posted by Dave on April 21, 2011
The tick is an unsigned number so take the tick reading before waiting on the queue, and again after waiting on the queue, then take away the after time from the before time and overflows will not matter (the unsigned number will wrap round). That assumes only one overflow can happen while you are waiting. If there could be more than one overflow then FreeRTOS keeps an overflow count and has some private utilities for working out time differences, but that would need digging around in the code internals.

[ 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