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



Posted by jmr on February 12, 2009
I didnt see a reference to timers in the API. Is there support in FREE RTOS for timers?

RE: timers

Posted by Dave on February 12, 2009
Richard has a timers module he can send you but most people just use the tick hook to do what they want.

RE: timers

Posted by jmr on February 12, 2009
Thanks I will check out the "tick hook"

RE: timers

Posted by jmr on February 12, 2009
Thanks I will check out the "tick hook"

RE: timers

Posted by larytet on December 4, 2010
I am porting this http://larytet.svn.sourceforge.net/viewvc/larytet/gmpC/AOS/aosTimer.h?view=markup timers to freeRTOS.

I can contribute the code under LGPL or GPL license if there is interest in such code. Please, let me know. Any API and implementation tips and ideas are highly appreciated.

Thank you.

RE: timers

Posted by Dave on December 4, 2010
Please do contribute, this would make a good palce

RE: timers

Posted by larytet on December 6, 2010

Please find here reworked API https://www.assembla.com/code/freertos/subversion/nodes/FreeRTOS_Posix/Timer/Timer.h

I will appreciate any feedback.

Thank you, Arkady.

RE: timers

Posted by Richard on December 6, 2010
Ah - interesting. Are you planning on a full (well as full as practical for a small embedded kernel) POSIX layer for FreeRTOS? If so you should post a link to it in the FreeRTOS Interactive forum when you think it is complete enough.

I have some ideas for how to add timers into FreeRTOS, but not in a POSIX way. I hope to do this, someday...you know how it is.

RE: timers

Posted by Richard on December 6, 2010
I should have provided some explanation as to why timers are not there currently..

The primary reason is that they are very difficult to implement in a deterministic and most importantly efficient way. There are on the other had very easy to implement indeed if you are not concerned with those kernel attributes in an particular application, but core code has to be more generically applicable.

Most dynamic timer implementations (where a timer can be created and destroyed at run time) require such timers to be stored in a linked list of one form or another - and accessing the timers from both interrupt code and task code means that their data structures have to be protected with a critical section. Also, timer lists by their nature are normally traversed within the tick interrupt. For the reasons mentioned above (interrupt responsiveness and determinism) there is nowhere in the FreeRTOS code where linked lists are traversed while interrupts are disabled.


RE: timers

Posted by larytet on December 7, 2010
I appreciate the feedback. I am not going to implement POSIX timers. Not in this development cycle.

Regarding performance I will avoid any not O(1) operations. Definitely no per tick traversing of the list of running timers is going to happen. Timer task(s) is going to sleep until the next timer expires. The suggested API will cover some rather large segment of application which require
- multilple coexisting timers
- timeout(s) known at compilation time
- set of different timers (different timeouts) is relatively small

See below application notes
* The system requires multiple (more than one) started timers with the same timeout. If your
* system needs only one or two timers at any moment it is easier to use tick hook. Typical
* application - data transfer timers serving multiple connections (sockets).
* In the system run one or more timers tasks handling different timer sets. Every timer
* set contains one or more timer lists.
* Function StartTimer allocates free entry from the stack of free timers and places
* the timer in the end of the timer list (FIFO). Complexity ~O(1)
* Timer task waits for the expiration of the nearest timer, calls application handler
* TimerExpired, find the next timer to be expired using sequential search in the
* set (always the first entry in a timer list). Timer task removes stopped timers from
* the list of running timers and returns the timers to the pool of free timers.
* Complexity ~ O(size of set)
* Function stop timer marks a running timer as stopped. Complexity ~O(1)

Thank you, Arkady.

RE: timers

Posted by larytet on December 7, 2010
Part II.

For some reason my previous reply failed to appear here.

I am trying to cover as many different scenarios as possible. For example, I let the application to avoid interrupt/task scheduler disable/enable operations by allowing to handle timers expiration and start/stop in the some context. Not every application will be designed this way, but this is definitely a good alternative to consider. The API allows to use a dedicated timer task or a timer interrupt.

I am investing significant effort in compilation time configuration.

Definitely this API is not for each and every case.

It is not generic enough if the application demands timers with precise (no rounding is possible) and arbitrary timeout. Such application requires some form of ordered by expiration time list of timers. Complexity of the start timer will likely not be O(1).

The API is not simple and small if the application requires only one or two timers which always expire (I think that there is a clever solution for this, but I need more time).

I need your help with the system requirements, different application designs (link task or interrupt) and so on.

Thank you, Arkady

RE: timers

Posted by larytet on December 12, 2010
I am finishing the implementation. I will appreciate code review. The source is here https://www.assembla.com/code/freertos/subversion/nodes/FreeRTOS_Posix/Timer

Any comment will help.

Thank you.

[ 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