15.5 Interrupt Service Routine Context Saving
Interrupts, by their very nature, can occur at unpredictable times. Therefore, the interrupted code must be able to resume with the same machine state that was present when the interrupt occurred.
To properly handle a return from interrupt, the setup (prologue) code for
an ISR function automatically saves the compiler-managed working and special function
registers on the stack for later restoration at the end of the ISR. You can use the
optional save parameter of the interrupt attribute to
specify additional variables and SFRs to be saved and restored.
To reduce the amount of context that must be preserved, which will improve interrupt
latency, use the 14.1.2.4 attribute with the ISR. context
void __attribute__((interrupt, context)) _INT1Interrupt()
- When the
contextattribute is added, the compiler will not generate instructions to save/restore the context. - When the
nocontextattribute is added, or when neithercontextnornocontextattributes are specified, the compiler will generate instructions to save/restore the context.
The context register set is automatically, chosen using the given interrupt’s priority level,.i.e., an interrupt with IPL = 5 will use Context set 5, and an interrupt with IPL = 6 will use context set 6.
