The INTERRUPT Pragma

The INTERRUPT pragma enables you to handle interrupts directly with C code. The pragma specifies that the function is an interrupt. The type of interrupt is specified by the pragma; the IRQ (interrupt request) interrupt type is assumed if none is given.

The syntax of the pragma in C is:

#pragma INTERRUPT (func[,interrupt_type])

The syntax of the pragma in C++ is:

#pragma INTERRUPT[( interrupt_type)]
void func( void )

The GCC interrupt attribute syntax, which has the same effects as the INTERRUPT pragma, is as follows. Note that the interrupt attribute can precede either the function's definition or its declaration.

__attribute__((interrupt[( "interrupt_type" )] )) void func( void )

In C, the argument func is the name of a function. In C++, the pragma applies to the next function declared. The optional argument interrupt_type specifies an interrupt type. The registers that are saved and the return sequence depend upon the interrupt type. If the interrupt type is omitted from the interrupt pragma, the interrupt type IRQ is assumed. These are the valid interrupt types:

Interrupt Type Description
DABT Data abort
FIQ Fast interrupt request
IRQ Interrupt request
PABT Prefetch abort
RESET System reset
SWI Software interrupt
UDEF Undefined instruction

Except for _c_int00, which is the name reserved for the system reset interrupt for C programs, the name of the interrupt (the func argument) does not need to conform to a naming convention.

For the Cortex-M architectures, the interrupt_type can be nothing (default) or SWI. The hardware performs the necessary saving and restoring of context for interrupts. Therefore, the compiler does not distinguish between the different interrupt types. The only exception is for software interrupts (SWIs) which are allowed to have arguments (for Cortex-M architectures, C SWI handlers cannot return values).

NOTE

Hwi Objects and the INTERRUPT Pragma

The INTERRUPT pragma must not be used when SYS/BIOS Hwi objects are used in conjunction with C functions. The Hwi_enter/Hwi_exit macros and the Hwi dispatcher contain this functionality, and the use of the C modifier can cause negative results.