15.2 Interrupt Vector Table
The Interrupt Vector Table (IVT) resides in device program memory. (For a list of interrupt vectors, see Available Interrupt Vectors.)
Remapping and Collapsing the IVT
The IVT is remappable/relocatable using the IVTBASE register to set the base address. To simplify this operation, a builtin function has been provided:
/* switch to IVT '2' */
__builtin_setIVTBASE(&_ivt_2);
The IVT can be collapsed by configuring the IVTC bit of the IVTCREG register. The collapsed/compressed peripheral interrupt vector is placed in the reserved interrupt location (see device data sheet.) The TRAP interrupts are not collapsed and the peripheral interrupts are pointed to one location, which is placed after the TRAP’s interrupt location.
To specify the address of an IVT, use these linker command options:
- to move the default IVT, use
--ivt=ADDR
. - to create a collapsed IVT at the default location, use
--civt
- to create two IVTs, use two
--ivt
options. For example:--ivt --ivt=2:ADDR // creates ivt_0 at the default address, and ivt_2 at ADDR --ivt --ivt=2: // creates ivt_0 at the default address, and ivt_2 at an address selected by the linker
For a list of interrupt-related linker options, see MPLAB® XC32 Assembler, Linker and Utilities User’s Guide for PIC32A MCU DS-50003839, “Interrupt-Related Linker Options”.
The lowest-numbered IVT will be programmed into IVTBASE by the startup code. If the lowest numbered IVT is 'compressed' the corresponding control bit in IVTCREG will also be set.
Referencing the IVT
Interrupt vector tables (IVTs) are referenced in source code like this:
extern void (**name)(void);
If the IVT is located in Flash (which is typical) the large-data memory model is required. Alternatively, the far attribute could be specified like this:
extern void (**name)(void) __attribute__((far));
However, a reference is needed only if manipulation is done, such as changing the value of IVTBASE. If the application simply needs to create a compressed interrupt vector, or assign the vector table to a specific address, there is no need to reference the IVT in source code.
When statically allocating the vector table, either in flash or ram, the type needs to specify the size. The compiler constant __IVT_NUM can be used like this:
void (*name[__IVT_NUM])(void)