Peripheral interrupt exceptions and
system exceptions temporarily pause the processor's normal execution flow so that
the processor can be used to handle an event.
The following can cause interruption
of normal execution flow:
- A CPURST
- A
Non-Maskable Interrupt (NMI, software trigger or hardware error signal from
SYSCTL)
- A Secure
Fault
- A fault exception in the system
(HardFault)
- Execution of a supervisor call
instruction (SVCall)
- Setting of a pending supervisor
service request (PendSV)
- A SysTick
exception
- An enabled peripheral interrupt
(IRQ)
- A breakpoint instruction (for
debug)
Exception States
Each
exception source to the processor will be in one of the below states at any given point
in time:
- Inactive (not active, not
pending)
- Pending (waiting to be
serviced by the processor)
- Active (actively being
serviced by the processor but has not completed)
- Active and pending
(actively being serviced by the processor and there is a pending exception from
the same source)
Exception Prioritization, Entry, and Exit
Exceptions are prioritized by the
processor together with the Nested Vectored Interrupt Controller (NVIC).
Each exception has either a fixed priority (Reset, NMI,
HardFault) or a configurable priority (SVCall, PendSV, SysTick,
peripheral IRQs). Exceptions with configurable priority can be disabled by
application software running in privileged mode. Exceptions with fixed priority
cannot be disabled.
The processor exception model supports preemption, tail-chaining, and late-arrival features to boost exception handling performance:
- In the preemption case, if an exception of higher priority is pending when an exception of lower priority is executing, the higher priority exception will preempt the ongoing handler
servicing the lower priority exception.
- In the tail-chaining case, if a valid-for-entry exception is pending at the time of completion of an exception handler, then the application context is not restored from the stack
and control is given immediately to the pending exception.
- In the late-arriving case, if a higher priority exception occurs during entry to a lower priority exception, the higher priority exception will be serviced first after the processor
state is saved to the stack. Once the higher priority exception handling is complete, the lower priority exception (which is still pending) is serviced based on the tail-chaining procedure.
An exception entry is issued if and when all of the following are true:
- An exception is in a pending state
- The priority of the pending exception is higher than the limit set by the exception mask register (PRIMASK)
- The processor is currently in either thread mode (not servicing an exception) or the newly pending exception is higher priority than the exception which is currently being serviced
(resulting in a preemption)
Processor exceptions are vectored. When an exception occurs, the current processor state is pushed onto the stack which was active at the time of the event, and execution is vectored to the
entry point address in the vector table corresponding to the exception which is to be processed.
If the exception is tail-chained to a previous handler which has completed, then there is no need to push any state to the stack and the interrupt service routine can be vectored to immediately.
Likewise, if the exception is higher priority than a previous exception which started entry but did not complete entry, then there is no need to save the context again (late arrival).
Upon completion of an exception handler, if there is no exception pending which needs to be handled then the processor will pop the state from the stack and restore the processor to the previous
state which it was in when the exception occurred.