liveBook · Manning

Interrupt handler

As explained in Embedded Software with Rust

An interrupt handler is a routine invoked asynchronously in response to a hardware or software interrupt.

An interrupt handler is a routine that runs when a hardware or software interrupt occurs. The event is delivered through a vector table; the processor saves a small register context, transfers control to the handler, then restores the context so interrupted code can resume. section 1.2.4 section 1.4.4

Handlers can interrupt the main program at unpredictable times. When both contexts access the same data or peripheral, race conditions and data corruption can result. Rust makes sharing explicit and can restrict access to an appropriate synchronization mechanism. section 1.4.4 section 4.6

Embedded Rust uses several approaches to control shared access:

  • For simple cases, a short critical section disables interrupts around an access; its permission to access shared state lasts only while the section is active. section 1.4.4
  • RTIC assigns task priorities and derives permitted references for compiler checking. Embassy coordinates async tasks and shared devices through nonblocking drivers with exclusive-access APIs. section 1.4.4
Figure 4.9 Race condition with shared variables
CH04 F09 Cabanis

The figure illustrates how a race condition can arise when an interrupt handler and other code share variables. section 4.6

How Embedded Software with Rust covers it

How deep it goes
Traces vector-table dispatch and context restoration, then outlines sharing safeguards while deferring concrete APIs.
Examples
Uses hardware events, timers, faults, shared state, critical sections, and embedded task frameworks as examples.
What you can do after
Apply ownership-based sharing and short critical sections to control access between handlers and application code.
How it connects
Connects interrupt handlers to vector tables, concurrency, ownership, critical sections, RTIC, and Embassy.

Also explained in

Compare how 2 books explain interrupt handler →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Embedded Software with Rust. The section links point to the parts of the book it draws on.