The Clock Tick

In order to provide time services, such as time delays, timeouts, and timers, µC/OS-III-based systems rely the presence of a time source called the clock tick or system tick. µC/OS-III’s clock tick handling is encapsulated in the file os_tick.c.

There are three possible configurations of µC/OS-III which determine how, or if, it provides time services.

Tickless Mode

A common misconception is that a system tick is always needed with µC/OS-III. In fact, many low-power applications may not implement the system tick because of the power required to maintain the tick list. In other words, it may not be reasonable to continuously power down and power up the product just to maintain the system tick. Since µC/OS-III is a preemptive kernel, an event other than the tick interrupt can wake up a system placed in low power mode by either a keystroke from a keypad or other means. However, not having a system tick means that the user is not allowed to use time delays or timeouts on system calls. This is a decision required to be made by the designer of the low-power product.

Periodic Tick Mode

This is the simplest method for enabling the kernel's time services. µC/OS-III requires (as do most kernels) that the user provide a periodic interrupt to keep track of time delays and timeouts. This periodic time source is called a clock tick and should occur between 10 and 1000 times per second (see OS_CFG_TICK_RATE_HZ in os_cfg_app.h). The actual frequency of the clock tick depends on the desired tick resolution of the application. However, the higher the frequency of the ticker, the higher the overhead. The consequence of this approach is that the system needs to service the tick interrupt frequently, even when there are no tasks ready to run. Periodic Tick Mode is often unsuitable for low-power applications as a result. However, this is the only mode to properly support round-robin scheduling.

Dynamic Tick Mode

A more advanced method of enabling time services is to use a hardware timer which can be reconfigured to interrupt when the next delay or timeout occurs. It is a compromise between the other two modes in the sense that it provides the time services but it does so without waking the system at each tick. This approach, called Dynamic Tick Mode, requires additional BSP code to function. The tick rate, OS_CFG_TICK_RATE_HZ, still defines the basic unit of time, but it now carries additional implications. The details are covered in the section dedicated to this mode. Unlike Periodic Tick Mode, round-robin scheduling is not supported in Dynamic Tick Mode.

Choosing the Tick Mode

Selecting the tick mode is done by configuring two compile-time parameters in os_cfg.hOS_CFG_TICK_EN and OS_CFG_DYN_TICK_EN. There are 4 possible configurations of these booleans, three of which are valid.

Table - µC/OS-III Tick Modes
OS_CFG_DYN_TICK_ENOS_CFG_TICK_ENModeDescription
DEF_DISABLEDDEF_DISABLEDTickless ModeTiming services are completely disabled.
DEF_DISABLEDDEF_ENABLEDPeriodic Tick ModeTiming services are enabled: Periodic tick is used

DEF_ENABLED

DEF_DISABLED

INVALID

Invalid combination which generates a build error.
DEF_ENABLEDDEF_ENABLEDDynamic Tick ModeTiming services are enabled: Dynamic Tick is used