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


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