Quality RTOS & Embedded Software

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


User timers for FreeRTOS?

Posted by Juha on March 9, 2010

In my application I need some timers. I will write those myself if I need to, but perhaps there is some code available already? I'm thinking of a system (in a relatively high priority task, perhaps?) that I can say something like "notify me every 500ms" or "do this after 12s". In more technical terms, start/stop a periodic/single_shot timer with somehow defining what to do at time out. Any pointers?

Thank you,


RE: User timers for FreeRTOS?

Posted by Richard Damon on March 9, 2010
Look at the vTaskDelay and vTaskDelayUntil functions. As long as the period is a multiple of your tick rate, getting a task to wait up periodically isn't a problem.

RE: User timers for FreeRTOS?

Posted by Juha on March 9, 2010
Yes, and the tick count is also available. However, I need to do things like starting a process that should be ready in two seconds. When doing that, I want the starting task to continue; I'll just set up a timer to send back a message after two seconds. If I get a message from the new process, I stop the timer and handle the new results. If I get a message from the timer, I'll do error handling.

I know FreeRTOS does not (yet :-) ) have this kind of services, but these can be readily created on top of it. As noted, I can write the timer code (timer task?) myself if I need to, but if there is something like this already, I rather not re-invent a wheel.

RE: User timers for FreeRTOS?

Posted by Richard on March 9, 2010
I do have a (very) old timer module that allows timers to be generated dynamically, each of which with a callback function. However I have never included it in the main download, primarily because this sort of timer is very difficult to implement efficiently. Timer implementations normally do horrible things like walk linked lists inside critical sections, or even inside tick interrupts. That is something I have always tried to avoid in FreeRTOS because of the obvious adverse effect it has on system responsiveness.

I would suggest also taking a look at using a tick hook function. Most timer functionality (in the smaller systems that FreeRTOS targets at least) can be implemented using a tick hook.


RE: User timers for FreeRTOS?

Posted by Richard Damon on March 9, 2010
Sounds like one way to implement this is when task1 starts task2, it also starts up a watchdog task3 that does a wait for a signal from task2 with a timeout. When task2 is done, it sets the signal waking up the watchdog (which could process the data if you wanted), but if task3 wakes up on timeout (signal by a failure to get the signal), then it flags the error.

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

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

Latest News

FreeRTOS v10.2.1 is available for immediate download. MIT licensed, includes 64-bit RISC-V, NXP Cortex-M33 demo & Nuvoton Cortex-M23 demo.

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

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

Cadence Tensilica Cortes

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