5.5.7 · D1Embedded Systems & Real-Time Software

Foundations — Interrupts — ISR design, NVIC priority, interrupt latency

2,135 words10 min readBack to topic

This page assumes nothing. Before you read the parent topic, you must be fluent in every word and symbol it throws at you. We build each one from a picture.


1. What a CPU is actually doing (the moving finger)

Figure — Interrupts — ISR design, NVIC priority, interrupt latency

Normally the finger just steps forward: address, address+1, address+2. A jump means the finger suddenly lands on a different address. An interrupt is a jump the hardware forces, not one you wrote.


2. Registers — the CPU's tiny scratchpad

Figure — Interrupts — ISR design, NVIC priority, interrupt latency

3. The stack — where saved context is parked

Figure — Interrupts — ISR design, NVIC priority, interrupt latency
Recall Why LIFO and not a queue?

Interrupts can nest (an interrupt inside an interrupt). The most recently interrupted context must resume first — that is exactly LIFO. Which end of the stack is touched on both push and pop? ::: The top, tracked by .


4. Functions and the "jump and come back" pattern


5. Peripherals, flags, and the interrupt line


6. The NVIC and the vector table — the traffic controller

Figure — Interrupts — ISR design, NVIC priority, interrupt latency

7. Numbers you must be able to read: powers of two and cycles


8. Masking — the mute button


Prerequisite map

Program Counter - the moving finger

Jump and come back

Registers R0 to R12 LR xPSR

Saved context = 8 words

Stack and SP - LIFO parking

ISR - forced function call

Peripherals flags IRQ lines

NVIC controller

Vector table - address phone book

Powers of two 2 to the n

NVIC priority levels

Cycles and clock frequency

Interrupt latency

Masking and volatile

Safe shared variables

Interrupts topic


Equipment checklist

Test yourself — if any answer is fuzzy, re-read that section before the parent note.

What does hold, and what happens to it during an interrupt?
The address of the current instruction; hardware saves it and loads the ISR's address so the finger jumps.
Name the 8 registers the Cortex-M auto-stacks.
, , , , .
Why LIFO (a stack) and not a queue for saved context?
Nested interrupts must resume most-recently-interrupted first — Last In, First Out.
What is a "flag" and why must an ISR clear it early?
A peripheral status bit recording the event; if not cleared it keeps re-asserting the IRQ → the ISR re-enters forever.
What does the vector table map?
IRQ number → the memory address of that interrupt's ISR.
How many levels do implemented priority bits give?
total, split preempt × sub.
Convert 12 cycles to time at 100 MHz.
.
What does volatile force the compiler to do?
Re-read the variable from memory every access instead of caching it in a register.
What does masking (disabling) interrupts buy you, and what does it cost?
Buys atomic access to shared data; costs added interrupt latency ().

Next: with every symbol earned, read the parent topic. Related foundations you may want alongside: Polling vs Interrupt-driven I/O, Concurrency & Race Conditions, Ring Buffers / FIFO Queues, ARM Cortex-M Architecture, Real-Time Scheduling & Deadlines, Power Management & Sleep Modes.