one-shot timer in FreeRTOS

umnurw wrote on Thursday, February 10, 2011:


Is there any method to use one-shot timer in FreeRTOS?


rtel wrote on Thursday, February 10, 2011:

The current V6.1.1 implementation of FreeRTOS does not have a specific method of doing this, although it is perfectly possible to use the tick hook, and other methods, etc. to obtain this functionality.

V6.2.0 of FreeRTOS (not released yet) has a new specific timer implementation that has this functionality.  The implementation is in the head revision of the SVN repository now, although it is not complete yet because there is now overflow protection yet - I am adding that functionality today. 

The timer implementation is not documented yet, although there is a demo/test app for it FreeRTOS/Demo/Common/Minimal/TimerDemo.c - again this is in the head revision of SVN.  At the moment that file is a bit of a mess because there is a lot of test code in one large function.  It will be modularised before release.

Writing a timer implementation is actually very easy - what is not easy is writing an efficient timer implementation.  Often timers are written to execute in the interrupt context, which is not a good plan for the timer callback functions, and has an overhead on every single tick interrupt even when no timers need servicing.  Also, implementations can require linked lists to be walked either in an interrupt, or with interrupts disabled.  These are things that FreeRTOS never does.  The implementation I have come up with hopefully gets around both these points.  The timers are serviced by a timer daemon task, so executes in the task context.  Also, the task blocks until a timer actually needs servicing, so there is no overhead when timers are all just waiting to expire.


peter03 wrote on Monday, February 28, 2011:

When will v6.2.0. be released? I’d like to appy freeRTOS Timer methods.

rtel wrote on Monday, February 28, 2011:

It will get released as soon as I have time to document the new features, and test some changes that were made to a couple of ports.  In the mean time, you can obtain a copy of the timers code from the FreeRTOS SourceForge SVN repository.  The timers code has completed testing now so should not change much if at all between now and release.

The file to add to a project in order to use software timers is FreeRTOS/Source/Timers.c

The demo application tasks (which are actually quite complex because they are more of a test task than a demo task) is in FreeRTOS/Demo/Common/Minimal/TimerDemo.c

The MSVC Win32 simulator demo has been updated to use the timer module, this is in FreeRTOS\Demo\WIN32-MSVC and uses the free MSVC Express edition to compile.

Note the MSVC project has the following additions to its FreeRTOSConfig.h:

#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY 2
#define configTIMER_QUEUE_LENGTH 20

/* Nothing to do with timers, but to do with the new assertion points added in the core code. */
extern void vAssertCalled( void );
#define configASSERT( x ) if( ( x ) == 0 ) vAssertCalled()

The API for the timers module is in FreeRTOS\Source\include\timers.h *but* this is not yet commented.