Scheduling and RTOS lesson plan
From a scheduler written by hand to FreeRTOS on the Uno: tasks and priorities, time slicing on the logic analyzer, queues, mutexes and priority inversion, starvation and the watchdog, and a four-task device.
Objectives and materials
By the end, students can
- Many jobs in one loop, and where that stops working.
- Tasks, priorities, and a tick that takes the processor back.
- Queues, mutexes, priority inversion and starvation.
- A temperature alarm built from four tasks.
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.
Scheduling by hand
Many jobs in one loop, and where that stops working.
| Lesson | Time | What students do |
|---|---|---|
| A scheduler by handThree jobs at three rates in one loop with millis() and no delay(): a table of jobs, a loop that runs whichever is due, and the one rule that makes it work. | 55 min |
|
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 "A scheduler by hand" 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: "The rule, and where it breaks".
Tasks and the scheduler
Tasks, priorities, and a tick that takes the processor back.
| Lesson | Time | What students do |
|---|---|---|
| Tasks and prioritiesThe same lamps as FreeRTOS tasks: each one a loop of its own with a stack and a priority, vTaskDelay() counted in 16 ms ticks, and a report that outranks them. | 55 min |
|
| Time slicing and preemptionTwo tasks that never yield still share the processor a tick at a time, seen on the logic analyzer; a higher priority task cuts in on time; and one priority change starves a task completely. | 55 min |
|
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 "Time slicing and 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: "The rule for priorities".
Tasks that work together
Queues, mutexes, priority inversion and starvation.
| Lesson | Time | What students do |
|---|---|---|
| QueuesA sensor task hands readings to a logger task through a FreeRTOS queue: no shared variable, a receiver that sleeps until data arrives, and what happens when the queue fills up. | 45 min |
|
| Mutexes and priority inversionThree tasks and one shared bus: a mutex guards it, priority inversion makes the most important task wait for the least, and priority inheritance fixes it. Then break the fix and watch it happen. | 55 min |
|
| Starvation and the watchdogA busy worker starves a heartbeat task, a watchdog task at the top catches it in the act, and splitting the work into chunks lets every task check in on time. | 45 min |
|
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 "Starvation and the watchdog" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "The hardware watchdog".
Boss project
A temperature alarm built from four tasks.
| Lesson | Time | What students do |
|---|---|---|
| Boss: a multi-task deviceA temperature alarm built from four tasks: a sensor overwrites a one-slot queue, a display owns the LCD, a button notifies the alarm, and a mutex keeps every serial line whole. | 55 min |
|
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 "Boss: a multi-task device" 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: "Set your own limit".
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.