Esp32 Interrupt Controller
An interrupt controller's job is deciding, within a few CPU cycles, which of potentially dozens of simultaneous hardware events actually gets the CPU's attention right now — and on a radio-integrated chip like this, getting that prioritization wrong doesn't just mean a sluggish user interface, it means a dropped Wi-Fi or Bluetooth connection. Dozens of peripherals (the radio baseband, DMA completion, UART, timers, GPIO edges) can all signal "something happened" at effectively the same moment, and a flat, unprioritized interrupt scheme would let a low-stakes timer interrupt block a radio event with a hard real-time deadline purely by accident of timing — the controller's entire reason for existing is preventing exactly that outcome through a defined priority scheme the hardware enforces automatically.
Nested, preemptive interrupt priority exists specifically so a lower-priority handler already running doesn't become an accidental blocking problem for a higher-priority event that shows up mid-handler. A non-preemptive scheme would force every interrupt to run to completion before any other interrupt — including a higher-priority one — can be serviced, which means a long-running but low-priority handler (say, servicing a slow UART transaction) could directly delay a time-critical radio interrupt simply by having started first; preemptive priority lets the controller interrupt that lower-priority handler mid-execution the instant a higher-priority event arrives, service the urgent one, and only then return to finish the one that was interrupted — a design that trades some added complexity in handler re-entrancy for a hard guarantee that priority actually means something under real, overlapping traffic.
Context-save overhead is a fixed cost every interrupt pays before any handler-specific code even starts running, which makes it a direct, unavoidable tax on the latency budget for the chip's most time-critical events. Entering an interrupt handler requires pushing enough CPU state — registers, program counter, status flags — onto the stack that the interrupted code can resume correctly once the handler returns, and that save/restore sequence takes a fixed number of CPU cycles regardless of how simple or complex the handler itself turns out to be; for a hard-deadline event like a BLE connection slot, that fixed overhead isn't a rounding error, it's a real chunk of an already-tight timing budget, which is why interrupt-latency-sensitive firmware keeps ISR code itself as short as physically possible — doing the minimum necessary and deferring any real work to a lower-priority task — rather than trying to economize on the context-save cost that hardware fixes and software can't reduce.
Interrupt priority assignment is a design decision made once at the architecture level, not something application firmware should casually override, because the priority scheme's entire value depends on every peripheral's assigned level accurately reflecting how time-critical that peripheral's events actually are. A firmware developer who bumps a convenient but non-critical peripheral's interrupt to the highest priority level — because it happens to make a specific feature feel more responsive during testing — can inadvertently create exactly the blocking scenario the priority scheme exists to prevent, delaying the radio's genuinely hard-deadline interrupts behind a change that looked harmless in isolation; priority levels for the radio and other real-time-critical sources are set at the hardware/SDK level specifically so individual application decisions can't accidentally undermine the one guarantee the whole radio stack depends on.
Interrupt controller and priority design is the mechanism that makes "many peripherals, one CPU, one hard real-time deadline on the radio" actually work: a priority scheme enforced in hardware with genuine preemption rather than a polite convention, a latency budget that treats fixed context-save overhead as a real cost against the radio's own timing margin, and a priority assignment discipline that keeps application-level convenience from ever outranking the one interrupt source whose timing the whole product's wireless reliability depends on.