The Timer Task
µC/OS-III provides timer services to the application programmer and this code is found in os_tmr.c
.
The timer task is optional in a µC/OS-III application and its presence is controlled by the compile-time configuration constant OS_CFG_TMR_EN
defined in os_cfg.h
. Specifically, the code is included in the build when OS_CFG_TMR_EN
is set to DEF_ENABLED
.
Timers are countdown counters that perform an action when the counter reaches zero. The action is provided by the user through a callback function. A callback function is a function that the user declares and that will be called when the timer expires. The callback can thus be used to turn on or off a light, a motor, or perform whatever action needed. It is important to note that the callback function is called from the context of the timer task. The application programmer may create an unlimited number of timers (limited only by the amount of available RAM). Timer management is fully described in Timer Management and the timer services available to the application programmer are described in the µC-OS-III API Reference.
OS_TmrTask()
is a task created by µC/OS-III (this assumes setting OS_CFG_TMR_EN
to DEF_ENABLED
in os_cfg.h
) and its priority is configurable by the user through µC/OS-III’s configuration constant OS_CFG_TMR_TASK_PRIO
found in os_cfg_app.h
. OS_TmrTask()
is typically set to a low to medium priority.
OS_TmrTask()
is a periodic task using the same interrupt source that was used to generate clock ticks. However, timers are generally updated at a slower rate (i.e., typically 10 Hz). This is accomplished by dividing down the timer tick rate in software. In other words, if the tick rate is 1000 Hz and the desired timer rate is 10 Hz, the timer task will be signaled every 100th tick interrupt as shown in the figure below.