Skip to the content ForoHackers
Log inJoin

RTOS: start here

RTOS
#441 · Ophuscado · · Report

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

  1. Bare-metal interrupts and a super-loop, to feel what an RTOS replaces.
  2. Two tasks and a queue in FreeRTOS; then a mutex and a priority inversion you cause on purpose.
  3. Measure latency with a GPIO toggle and an oscilloscope or logic analyser.
  4. Zephyr's device model and build system, for a larger platform.
  5. Rate-monotonic analysis, to prove a set of tasks meets its deadlines.

Related tags

#microcontrollers #firmware #concurrency #functional-safety

Log in or join to reply.