3.3.6.1 How Do I Use Interrupts in C?

First, be aware of what interrupt hardware is available on your target device. 32-bit devices implement several separate interrupt vector locations and use a priority scheme. For more information, see 17.1 Interrupt Operation.

In C source code, a function can be written to act as the interrupt service routine by using the interrupt attribute. Such functions save/restore program context before/after executing the function body code and a different return instruction is used. For more on writing interrupt functions, see 17.2 Writing an Interrupt Service Routine. To populate the interrupt vector table, use the vector or at_vector attribute. An __ISR() macro is provided in the sys/attribs.h header file that simplifies the usage of the interrupt and vector attributes.

Prior to any interrupt occurring, your program must ensure that peripherals are correctly configured and that interrupts are enabled. For details, see 17.8 Enabling/Disabling Interrupts.

For all other interrupt related tasks, including specifying the interrupt vector, context saving, nesting and other considerations, consult 17 Interrupts.