Quality RTOS & Embedded Software

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


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 ]    [ Privacy ]    [ Sitemap ]    [ ]

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

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

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

Xilinx Microblaze and Zynq partner