HomeAbout UsContact Us

Timer Management and Tickless Mode in RTOS

By embeddedSoft
Published in Embedded OS
June 03, 2026
3 min read
Timer Management and Tickless Mode in RTOS

Table Of Contents

01
Introduction
02
Software Timers and the Daemon Task
03
Tickless Idle Mode
04
Zephyr: A Tickless-First Design
05
Summary
06
References

Introduction

Every real-time operating system needs a heartbeat — a periodic interrupt that drives the scheduler, tracks timeouts, and advances task delays. In most RTOS implementations, this comes from a hardware timer like ARM’s SysTick. While effective for scheduling, this periodic tick becomes a liability in battery-powered embedded systems: every tick wakes the CPU, even when no work needs to be done.

This article explores how RTOS-based systems manage timing internally — through software timers and daemon tasks — and how tickless idle mode dramatically reduces power consumption by eliminating unnecessary wakeups.

Software Timers and the Daemon Task

Software timers let you schedule callback functions at a future time or periodically without dedicating a task to each timer. FreeRTOS implements them through a central daemon task created automatically when the scheduler starts.

When you call xTimerStart(), a command is sent through the timer command queue to the daemon task. When the timer expires, the daemon executes the callback. Two timer types exist: one-shot (fires once) and auto-reload (restarts automatically). Callbacks run in the daemon task context, so they must never call blocking RTOS functions — doing so would delay all other timer callbacks.

Configure the daemon task via configTIMER_TASK_PRIORITY and configTIMER_TASK_STACK_DEPTH in FreeRTOSConfig.h. Set priority just below your most critical tasks to balance responsiveness with real-time constraints.

A typical timeout pattern uses a one-shot timer:

void comm_timeout_callback(TimerHandle_t xTimer) {
report_comm_failure();
}
void on_packet_sent(void) {
xTimerStart(xCommTimeout, 0); // Start 2-second countdown
}
void on_packet_received(void) {
xTimerStop(xCommTimeout, 0); // Cancel — response received
}

For periodic work, auto-reload timers eliminate the need for a dedicated task:

void heartbeat_callback(TimerHandle_t xTimer) {
toggle_status_led();
}

Use hardware timers for sub-millisecond resolution or precise periodic interrupts. Use software timers for timeouts, heartbeats, and status checks where plus or minus 1 ms jitter is acceptable.

Tickless Idle Mode

In a traditional ticked system, the periodic tick fires even when the CPU is idle. At 1 ms tick rate, that is 1,000 wakeups per second — each preventing the MCU from entering deep sleep. Tickless idle solves this by stopping the tick during idle periods and compensating the tick count on wakeup.

How It Works

When only the Idle task can run and no tasks will become ready for a known duration, the kernel programs a wake-up source (RTC or adjusted SysTick), stops the periodic tick, and enters a low-power state. On wakeup, it compensates the kernel’s tick count using the elapsed time from the secondary timer.

FreeRTOS supports two levels: configUSE_TICKLESS_IDLE = 1 uses the built-in WFI-based implementation suitable for light sleep modes. Setting it to 2 allows a custom implementation for deeper sleep modes like stop or standby.

Custom Implementation for Deep Sleep

When SysTick loses context in deep sleep, a secondary timer (RTC, LPTIM) must track elapsed time:

void vApplicationSleep(TickType_t xExpectedIdleTime)
{
uint32_t sleep_ms = xExpectedIdleTime * portTICK_PERIOD_MS;
if (sleep_ms > 10) {
configure_rtc_wakeup(sleep_ms);
uint32_t rtc_before = read_rtc_counter();
enter_stop_mode();
uint32_t elapsed_ms = (read_rtc_counter() - rtc_before);
vTaskStepTick(elapsed_ms / portTICK_PERIOD_MS);
} else {
__WFI();
}
}

The secondary timer must stay initialized and running continuously. Common choices include the RTC (32.768 kHz, ~30 microsecond resolution) or a low-power timer peripheral.

ARM Cortex-M offers multiple sleep levels: Sleep (WFI) preserves full context with near-instant wake-up, Stop Mode consumes ~50–100 µA with microsecond wake-up, and Standby drops to ~1–5 µA but may lose CPU context. NXP measured a 2.34 mA current reduction with tickless mode on the LPC5500 series.

Pre/Post Sleep Hooks

FreeRTOS provides hook macros to optimize power around sleep transitions. configPRE_SLEEP_PROCESSING can gate peripheral clocks and lower core voltage. configPOST_SLEEP_PROCESSING restores the system to full operation after wakeup.

Zephyr: A Tickless-First Design

Zephyr RTOS takes a different approach from FreeRTOS. Its kernel is inherently tickless — when all threads are blocked, the timer switches to one-shot mode, firing only at the earliest thread timeout. No periodic tick is generated during idle. Combined with Zephyr’s power management subsystem, this enables automatic selection of the deepest allowable sleep state without explicit tickless configuration.

Summary

Timer management is foundational to every RTOS system. Software timers enable event-driven callback patterns without dedicated tasks. Tickless idle mode eliminates the wasted energy of periodic ticks during inactivity. By understanding these mechanisms — daemon task configuration, secondary timers for deep sleep, and sleep-level trade-offs — you can design firmware that meets both real-time deadlines and aggressive power budgets. For battery-powered products, tickless idle is the difference between hours and years of battery life.

References


Tags

rtostimer-managementtickless-modelow-powerfreertos

Share


Previous Article
Watchdog Timer Design for Reliable Embedded Systems
embeddedSoft

embeddedSoft

Embedded Systems Articles by Jithin Tom & Hermes (AI Agent)

Related Posts

Deadlock Prevention and Avoidance Strategies in RTOS
Deadlock Prevention and Avoidance Strategies in RTOS
May 29, 2026
3 min
© 2026, All Rights Reserved.
Powered By Netlyft

Quick Links

Advertise with usAbout UsContact Us

Social Media