A real-time operating system schedules tasks so that the right one runs within a known time. "Real time" means predictable, not fast: a late answer counts as a wrong one. On a microcontroller an RTOS gives you tasks, priorities, queues and timers in a few kilobytes.
Key concepts
- Preemptive scheduling: the highest-priority ready task runs, and an event can take the CPU away at once.
- Synchronisation: mutexes, semaphores, queues and event flags pass data and wake tasks safely.
- Priority inversion: a low task holding a lock blocks a high one; priority inheritance bounds it.
- Determinism: worst-case execution time and interrupt latency matter more than averages.
- Memory: static allocation, stacks sized per task, and stack overflow checks.
Vocabulary
- Tick: the periodic interrupt that drives time slicing and timeouts; tickless modes skip it to save power.
- ISR: interrupt service routine; it defers work to a task instead of doing it all.
- Hard and soft real time: missing a deadline is a failure, or only a degradation.
- FreeRTOS, Zephyr, NuttX: common open RTOSes, from a small kernel to a full platform.
What to study, in order
- Bare-metal interrupts and a super-loop, to feel what an RTOS replaces.
- Two tasks and a queue in FreeRTOS; then a mutex and a priority inversion you cause on purpose.
- Measure latency with a GPIO toggle and an oscilloscope or logic analyser.
- Zephyr's device model and build system, for a larger platform.
- Rate-monotonic analysis, to prove a set of tasks meets its deadlines.