5.5.9 · D1Embedded Systems & Real-Time Software

Foundations — RTOS concepts — task, scheduler, preemption, context switch

2,073 words9 min readBack to topic

Before you can read the parent note RTOS Concepts fluently, you need every word and symbol it assumes you already own. This page builds them all, from the ground, in an order where each idea leans only on the ones before it.


0. The CPU: one worker, one desk

Figure — RTOS concepts — task, scheduler, preemption, context switch

Everything an RTOS does is a clever way of sharing this one worker between many manuals.


1. Registers — the worker's held slips of paper

The parent note names specific registers. Here is each, in plain words:


2. RAM and the stack — the private notepad

Figure — RTOS concepts — task, scheduler, preemption, context switch

Each RTOS task gets its own stack — its own private pile of plates — which is why the parent says a task "has its own stack." Read more in Stack memory and TCB.


3. The super-loop — life before the RTOS

This "one slow job freezes everyone" problem is the villain the whole RTOS topic defeats.


4. Interrupts and the tick — the tap on the shoulder


5. Frequency, period, and the symbols , , Hz, µs

The parent's formulas use these; here they are from zero.


6. Priority and states — the manager's board

Figure — RTOS concepts — task, scheduler, preemption, context switch

7. The TCB — one index card per task


How these foundations feed the topic

CPU one worker one stream

Registers PC SP r0-r12

Stack push and pop

TCB saved stack pointer

Super-loop the old way

Interrupts and ISR

Tick the heartbeat

Scheduler picks next task

Priority and states

Frequency and period f and T

Overhead formula

Context switch

Why an RTOS exists

Read the map top-down: registers and the stack build the TCB and the context switch; interrupts and the tick drive the scheduler; frequency feeds the overhead maths — and all of it lands on why an RTOS exists.


Equipment checklist

Recall Self-test: can you answer each before opening the parent note?

A CPU core runs how many instruction streams at once? ::: Exactly one. What is a register, in one phrase? ::: A tiny fast storage slot inside the CPU holding a value it's using right now. What does the PC (program counter) hold? ::: The address of the current instruction — "which line am I on". What does the SP (stack pointer) mark? ::: The top of the task's private stack (its pile of plates). How does a stack add and remove items? ::: Push on top, pop from top — last-in, first-out. What is an interrupt? ::: A hardware signal that makes the CPU pause and handle something now. What is a tick? ::: A regular timer interrupt — the RTOS heartbeat that wakes the scheduler. Convert to a period. ::: . How many microseconds are in one second? ::: One million (). Name the four task states. ::: Running, Ready, Blocked, Suspended. Why does "Blocked" help the system? ::: A Blocked task releases the CPU so other tasks can run. What single value in the TCB is the handle to a task's whole saved state? ::: Its saved stack pointer (SP). In a super-loop, what happens if one job waits 50 ms? ::: Every job behind it is stalled for those 50 ms.