5.5.7 · D3Embedded Systems & Real-Time Software

Worked examples — Interrupts — ISR design, NVIC priority, interrupt latency

2,066 words9 min readBack to topic

The scenario matrix

Before any numbers, let us list every kind of situation these formulas must survive. Each row is one case class; the worked examples below are tagged with the row they hit.

# Case class The question it answers Degenerate / edge form
A Priority split (, ) How many preempt vs sub levels? (no preemption) and (no sub-levels)
B Preemption decision Does IRQ-X interrupt running IRQ-Y? Equal preempt → no preemption
C Sub-priority tiebreak Two pending at once, equal preempt — who runs first? Equal sub too → lower IRQ number wins
D Latency, normal Time to first ISR instruction Event fires while IRQs masked (worst case)
E Latency, tail-chaining Back-to-back IRQs, cost saved Limiting case: many queued IRQs
F Deadline / real-world Do we drop a UART byte? Zero slack (exactly meets)
G Exam twist Combine grouping + latency + a trap "higher number = more urgent" trap

The formulas we lean on, restated so no symbol is unearned:


Case A — the priority split, including both degenerate ends


Case B & C — preemption vs tiebreak, all sign/order combinations

Remember the golden trap: lower numeric priority = more urgent. We test every ordering.


Case D — latency, normal and worst-case (masked)


Case E — tail-chaining and its limiting behaviour


Case F — real-world word problem (deadline / dropped byte)


Case G — the exam twist (grouping + latency + the trap)


Recall Self-test — reveal after answering

With , , how many things can preempt a running ISR? ::: Preempt levels , so none — fully non-nested. Two IRQs equal preempt, equal sub, numbers 12 and 30 — who runs first? ::: IRQ 12 (lower IRQ number is the final tiebreak). Worst-case latency at 100 MHz with 12 fixed + 50 masked cycles? ::: . Tail-chaining saving for one B→C transition (24 naive vs 6)? ::: cycles (). One byte time at 115200 baud, 8N1? ::: .


See also