Structuring device software.
WHAT THE LAYERS TYPICALLY ARE
Hardware abstraction, wrapping peripherals Drivers for sensors and radios Application logic Communication and protocol handling Configuration and persistence
WHY ABSTRACTION MATTERS HERE
Hardware changes during a product's life, and logic should not change with it.
WHAT IT ENABLES
Testing logic on a development machine, without hardware.
WHAT THE MAIN LOOP SHOULD DO
Wake, check what is due, act, and return to sleep.
WHAT TO AVOID
Blocking waits Long operations without yielding Logic scattered through interrupt handlers
WHAT A STATE MACHINE PROVIDES
Explicit representation of what the device is doing.
WHY THAT MATTERS ON UNATTENDED DEVICES
Recovery requires knowing where you were.
WHAT TO PERSIST
Enough state to resume after an unexpected restart.
WHAT AN EVENT-DRIVEN STRUCTURE PROVIDES
Reacting to sensor, timer and radio events without polling.
WHAT A REAL-TIME OPERATING SYSTEM ADDS
Tasks, scheduling and synchronisation.
WHEN IT IS WARRANTED
Several concurrent activities with timing requirements.
WHEN IT IS NOT
A simple sense-and-send device, where a loop suffices.
WHAT TO PREFER
The simplest structure meeting the requirement.