Context switch in assembly
The heart of every kernel: push all 32 registers and SREG, store SP in the TCB, pick the next task, load its SP, pop and return. Three tasks share the Uno by handing the processor on themselves.
Open it in the simulatorYour own preemptive kernel on the Uno: task control blocks and hand-built stacks, a context switch in inline assembly, a Timer1 tick, preemption, sleep and semaphores, syscalls, and stack canaries under three tasks at once.
0 of 7 done
7 lessons in 4 chapters, about 7 hours on a simulated Arduino Uno R3. Free, in your browser, every step checked by the simulator.
The heart of every kernel: push all 32 registers and SREG, store SP in the TCB, pick the next task, load its SP, pop and return. Three tasks share the Uno by handing the processor on themselves.
Open it in the simulatorMake the tick switch tasks: a naked Timer1 interrupt saves the interrupted task, counts the tick and restores the next one. Tasks that never yield still share, on the logic analyzer, a slice at a time.
Open it in the simulatorOne numbered doorway into the kernel: yield, sleep, ticks, write and exit through a table of functions. A task that returns is ended by SYS_EXIT, and the idle loop measures the load.
Open it in the simulatorEach lesson opens when the one before it is done, and each chapter ends in a project.
What a task is, and how the processor moves from one to another.
What a task really is: a function, a stack of its own and a task control block. Build two by hand, read the fake frame on each stack, and launch one by loading its stack pointer and returning into it.
0 of 7 steps
The heart of every kernel: push all 32 registers and SREG, store SP in the TCB, pick the next task, load its SP, pop and return. Three tasks share the Uno by handing the processor on themselves.
0 of 7 steps
A tick of the kernel’s own, and a scheduler that takes the processor back.
A clock of the kernel’s own: Timer1 in CTC mode interrupts at 100 Hz, leaving Timer0 to millis(). The register math, an atomic read of a two byte counter, and tasks that wait in ticks.
0 of 6 steps
Make the tick switch tasks: a naked Timer1 interrupt saves the interrupted task, counts the tick and restores the next one. Tasks that never yield still share, on the logic analyzer, a slice at a time.
0 of 6 steps
Tasks that block on semaphores, and one doorway into the kernel.
Waiting without spinning: tasks that sleep, tasks that block, and a counting semaphore that hands a unit straight to the next task in line. Three rovers share a charging dock with two bays.
0 of 6 steps
One numbered doorway into the kernel: yield, sleep, ticks, write and exit through a table of functions. A task that returns is ended by SYS_EXIT, and the idle loop measures the load.
0 of 7 steps
Three tasks on one Uno, on the kernel you built.
Your whole kernel at work: a beacon, a sensor and a reporter on a 100 Hz preemptive tick, with sleep, a semaphore between sensor and reporter, painted stacks and canaries. Then overflow a stack and watch the kernel catch it.
0 of 7 steps
All 7 lessons, in order, each with what it covers. Any of them opens in the editor right away.
Build a tiny kernel is part of the maker track, a ladder of courses from zero to expert.
A memo pen on an Uno: a microphone on A0, double buffers, an EEPROM that keeps up, real WAV files on microSD, PWM playback and debounced buttons.
Open the next courseFollow the starter kit you already own, then build a claw machine, a balance bot, a handheld console or an LED cube, each a short course checked by the simulator.
See every course on the trackEvery lesson runs in the simulator with nothing to buy. When you want the real thing, these kits have the parts.
Pick the starter kit you own and run every lesson in its manual with the same parts on the same pins.
See every kitYes. All 7 lessons of Build a tiny kernel are free and run in your browser, with nothing to install and no parts to buy before you start.
No. Every lesson runs on a simulated Arduino Uno R3 with its parts on the canvas, and the simulator checks each step as you go. When you want to build it for real, the same wiring and code work on a real board.
About 7 hours: 7 lessons in 4 chapters, each one a few short steps. Your progress is kept, so you can stop after any lesson and pick up where you left off.
Each chapter ends in a project that puts it together: Context switch in assembly, Preemption and Syscalls.
With "Tasks and stacks", and each lesson builds on the one before it. New to circuits? Electronics basics is the course that starts from zero.