Source: https://mokxi.com/teachers/plans/build-a-kernel
Updated: 2026-11-19

Lesson plan

# Build a tiny kernel lesson plan

Your 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.

4 chapters, 7 lessons, about 7 hours, on the Arduino Uno R3. Every lesson runs in the browser, with nothing to install.

Start a class from this course

The unit

## Objectives and materials

### By the end, students can

- What a task is, and how the processor moves from one to another.
- A tick of the kernel’s own, and a scheduler that takes the processor back.
- Tasks that block on semaphores, and one doorway into the kernel.
- Three tasks on one Uno, on the kernel you built.

### Materials for the whole unit

- Arduino Uno R3
- Character LCD with I2C backpack
- Full-size breadboard
- LED x 3
- Logic analyzer, four channels
- Potentiometer
- Pushbutton
- Resistor x 3

Every part is already on the simulator’s bench, so there is nothing to buy or hand out. The counts are the most any one lesson uses, if you build it on real breadboards too.

Chapter 1. About 2 h 10 min

## Tasks and switching

What a task is, and how the processor moves from one to another.

Lesson | Time | What students do

Tasks and stacks 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. | 65 min

- Run it: under FreeRTOS
- The task control block
- A frame that was never saved
- Launch
- Running on its own stack
- Launch the other one
- Why a stack each

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. | 65 min

- Run it: three tasks take turns
- Save
- Swap
- Restore
- What a switch costs
- A task that will not share
- Read your switch

### Materials

- Arduino Uno R3
- Character LCD with I2C backpack
- Full-size breadboard
- LED x 3
- Potentiometer
- Pushbutton
- Resistor x 3

### Check for understanding

Each student finishes "Context switch in assembly" on their own, without opening the hints. The simulator checks 7 of its 7 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Read your switch".

Chapter 2. About 1 h 50 min

## Time and preemption

A tick of the kernel’s own, and a scheduler that takes the processor back.

Lesson | Time | What students do

A timer tick 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. | 55 min

- Run it: Timer1 ticks
- Leave Timer0 alone
- Two clocks agree
- Wait in ticks
- Double the tick rate
- Choosing a tick rate

Preemption 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. | 55 min

- Run it: tasks that never yield
- A naked interrupt
- See the slices
- Fair shares
- Longer slices
- Every stack pays

### Materials

- Arduino Uno R3
- Character LCD with I2C backpack
- Full-size breadboard
- LED x 3
- Logic analyzer, four channels
- Potentiometer
- Pushbutton
- Resistor x 3

### Check for understanding

Each student finishes "Preemption" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Every stack pays".

Chapter 3. About 2 h

## Waiting and asking

Tasks that block on semaphores, and one doorway into the kernel.

Lesson | Time | What students do

Semaphores 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. | 55 min

- Run it: a dock with two bays
- Blocked
- Handed over
- Counting
- One bay
- A semaphore is not a mutex

Syscalls 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. | 65 min

- Run it: tasks that ask
- Sleep, in milliseconds
- Why a doorway
- Return means exit
- The idle load
- Speed up red
- Design a syscall

### Materials

- Arduino Uno R3
- Character LCD with I2C backpack
- Full-size breadboard
- LED x 3
- Potentiometer
- Pushbutton
- Resistor x 3

### Check for understanding

Each student finishes "Syscalls" on their own, without opening the hints. The simulator checks 7 of its 7 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Design a syscall".

Chapter 4. About 1 h 5 min

## Boss project

Three tasks on one Uno, on the kernel you built.

Lesson | Time | What students do

Boss: three tasks on one Uno 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. | 65 min

- Run it: your kernel
- The beacon
- Sensor to reporter
- Turn the knob
- How much stack is left
- Overflow it
- From here to FreeRTOS

### Materials

- Arduino Uno R3
- Full-size breadboard
- LED x 2
- Potentiometer
- Resistor x 2

### Check for understanding

Each student finishes "Boss: three tasks on one Uno" on their own, without opening the hints. The simulator checks 7 of its 7 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "From here to FreeRTOS".

Your class

## Teach this unit as a class

Start a class from this course and its 7 lessons are assigned in one go, in order. Students join with a six-character code or printed login cards, and each one’s work comes back to you.

The class tools are free for 30 days for one class of up to 20 students, with no card. The lessons themselves are free either way.

Start a class from this course See the demo class

More units

## Other lesson plans

Electronics basics 20 lessons, about 10 h. Embedded on the Arduino Uno 16 lessons, about 12 h. Embedded on the ESP32-C3 13 lessons, about 11 h. Embedded on the Raspberry Pi Pico 7 lessons, about 6 h. Build your own fight stick 5 lessons, about 4 h. Embedded on the STM32F411 6 lessons, about 6 h. C++ on a board 13 lessons, about 10 h. Digital logic and memory 4 lessons, about 4 h. Interactive devices on the Uno 9 lessons, about 8 h. From gates to a computer 23 lessons, about 16 h. Build a claw machine 8 lessons, about 6 h. Every unit All the courses as ready-made units, on the teachers page.
