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


How to control time-dependent tasks

Posted by lagavulin18 on May 16, 2014

How do you implement the following scenario typically with FreeRTOS?


Task1: priority 2, should run every 10 minutes for max. 2 minutes, then suspend Task2: priority 2, should run every day at 12.00, then suspend

I think I need a third (management-)task with a higher priority to control periodically the current time and resume/suspend the first two tasks, or is there another better design suggestion/approach?

I do not want complete solutions only food for thought! ;-)


How to control time-dependent tasks

Posted by richard_damon on May 16, 2014

The tasks can do the every so often themselves by using vTaskDelay/vTaskDelayUntil to wait for their next activation time (you will need something that gives you absolute time for #2, and likely 32 bit ticks if you don't want task 2 to need to wait up momentarily to see that it needs to go back to sleep for a while, unless your tick rate is slower the once a second (at 1 Hz, the max delay with 16 bit ticks is about 18 hours, and the tick rate is likely higher).

Having task 1 suspend after 2 minutes is a strange requirement. With a RTOS, normally a task will do the stuff it needs to do, and then wait until it needs to do it again. For it to abruptly stop (and presumably resume where it stopped 8 minutes later) is a very unusual type of situation. If task 1 is doing lots of small steps, then perhaps it could check an elapsed time after each on to decide if it should do the next or sit and wait. (Again this doesn't sound very RTOSish, maybe if you start the REAL problem, and not how to implement your solution, we might be able to give better help.)

How to control time-dependent tasks

Posted by davedoors on May 17, 2014

Agree with Richard D, maybe you are better describing the problem to get ideas for solutions.

Task 1 can use vTaskDelayUntil() to start ever 10 minutes, and either just look at the time periodically to know when to stop, or it could start a software timer with a 2 minute period when it starts and have the software timer tell it when to stop.

To know when 12.00 was you would need a real time clock, or be sent the time from a remote interface. If you have a real time clock then use it to set an alarm at 12.00 and wake task 2 from the alarm handler.

[ 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