15.2.2 Syntax for Writing ISRs

To declare a C function as an interrupt handler, tag the function with the interrupt attribute (see the 14.1.2 Function Attributes section for a description of the __attribute__ keyword).

The syntax of the interrupt attribute is:

__attribute__((interrupt [(
                              [ save(symbol-list)]
                              [, irq(irqid)]
                              [, altirq(altirqid)]
                              [, preprologue(asm)]
                              )]
                  ))

The interrupt attribute name and the parameter names may be written with a pair of underscore characters before and after the name. Thus, interrupt and __interrupt__ are equivalent, as are save and __save__.

The optional save parameter names a list of one or more variables that are to be saved and restored on entry to and exit from the ISR. The list of names is written inside parentheses, with the names separated by commas.

You should arrange to save global variables that may be modified in an ISR if you do not want the value to be exported. Global variables accessed by an ISR should be qualified volatile.

The optional irq parameter allows you to place an interrupt vector at a specific interrupt, with the optional altirq parameter allowing you to place an interrupt vector at a specified alternate interrupt. Each parameter requires a parenthesized interrupt ID number (see the 15.3 Specifying the Interrupt Vector section for a list of interrupt IDs).

The optional preprologue parameter allows you to insert assembly-language statements into the generated code immediately before the compiler-generated function prologue.

When using the interrupt attribute, please specify either auto_psv or 
no_auto_psv. If none is specified a warning will be produced and auto_psv will be assumed.