← Back to the chapter · Previous detail · Next detail →

Technical detail · Firmware Architecture Patterns

Runtime protection and deferred work

A protected process boundary keeps one program from freely reading or changing another program’s memory. An MPU region is an address range with access rules set by a memory protection unit. Embedded operating-system boundaries are part of that evidence. On a phone, laptop, or Linux gateway, the kernel usually protects itself from ordinary application code and mediates hardware access through drivers and services. Many MCU firmwares are flatter: application code, driver code, and runtime code may share one address space, and a bad pointer or runaway callback can stop the whole device. Cortex-M memory-protection units help when the runtime actually configures them, but the prototype record should not assume that protection exists. It should say whether the firmware has a protected process boundary, MPU regions, or a single trusted image, and which code is allowed to bypass the abstraction for direct peripheral control.

Interrupt handling is the sharpest version of that boundary. The direct handler should do the smallest urgent work: capture the event, clear or read the device status, copy a byte or timestamp, and enqueue a fact for normal code. Deferred execution moves work out of the urgent interrupt handler so normal code can do it later. A bottom-half callback is one such later handler; an event queue, work queue, or RTOS task can also carry the work. That deferred work still needs a contract: new interrupts may preempt it, queues may fill, and shared state can be touched from both handler and background paths unless ownership is explicit.

Event and thread designs have different costs. A callback can save RAM, but shared state needs a clear owner. The callback must not wait on a send, storage write, or long calculation. A thread has its own stack and can make waits easier to read. Record its priority, stack space, queue depth, and wake condition. In FreeRTOS, a higher priority task can preempt a lower one, and an interrupt can wake a task. Review vendor APIs and any direct register access as well.

← Back to the chapter · Previous detail · Next detail →