Microchip Technology SW006022-1N Data Sheet
Interrupts
2012 Microchip Technology Inc.
DS52071B-page 169
11.4
SPECIFYING THE INTERRUPT VECTOR
Many 16-bit devices have two interrupt vector tables – a primary and an alternate table
– each containing several exception vectors.
– each containing several exception vectors.
The exception sources have associated with them a primary and alternate exception
vector, each occupying a program word, as shown in the tables below. The alternate
vector name is used when the ALTIVT bit is set in the INTCON2 register.
vector, each occupying a program word, as shown in the tables below. The alternate
vector name is used when the ALTIVT bit is set in the INTCON2 register.
To field an interrupt, a function’s address must be placed at the appropriate address in
one of the vector tables, and the function must preserve any system resources that it
uses. It must return to the foreground task using a RETFIE processor instruction.
Interrupt functions may be written in C. When a C function is designated as an interrupt
handler, the compiler arranges to preserve all the system resources that the compiler
uses, and to return from the function using the appropriate instruction. The compiler
can optionally arrange for the interrupt vector table to be populated with the interrupt
function’s address.
one of the vector tables, and the function must preserve any system resources that it
uses. It must return to the foreground task using a RETFIE processor instruction.
Interrupt functions may be written in C. When a C function is designated as an interrupt
handler, the compiler arranges to preserve all the system resources that the compiler
uses, and to return from the function using the appropriate instruction. The compiler
can optionally arrange for the interrupt vector table to be populated with the interrupt
function’s address.
To arrange for the compiler to fill in the interrupt vector to point to the interrupt function,
name the function as denoted in the preceding table. For example, the stack error
vector will automatically be filled if the following function is defined:
name the function as denoted in the preceding table. For example, the stack error
vector will automatically be filled if the following function is defined:
void
__
attribute
_ _
((
__
interrupt
_ _
,
_ _
auto_psv
_ _
)) _StackError(void);
Note the use of the leading underscore. Similarly, the alternate stack error vector will
automatically be filled if the following function is defined:
automatically be filled if the following function is defined:
void
__
attribute
_ _
((
__
interrupt
_ _
,
_ _
auto_psv
_ _
))
_AltStackError(void);
Again, note the use of the leading underscore.
For all interrupt vectors without specific handlers, a default interrupt handler will be
installed. The default interrupt handler is supplied by the linker and simply resets the
device. An application may also provide a default interrupt handler by declaring an
interrupt function with the name _DefaultInterrupt.
installed. The default interrupt handler is supplied by the linker and simply resets the
device. An application may also provide a default interrupt handler by declaring an
interrupt function with the name _DefaultInterrupt.
The last nine interrupt vectors in each table do not have predefined hardware functions.
The vectors for these interrupts may be filled by using the names indicated in the
preceding table, or, names more appropriate to the application may be used, while still
filling the appropriate vector entry by using the irq or altirq parameter of the
interrupt attribute. For example, to specify that a function should use primary interrupt
vector 52, use the following:
The vectors for these interrupts may be filled by using the names indicated in the
preceding table, or, names more appropriate to the application may be used, while still
filling the appropriate vector entry by using the irq or altirq parameter of the
interrupt attribute. For example, to specify that a function should use primary interrupt
vector 52, use the following:
void
__
attribute
_ _
((
__
interrupt
_ _
,
_ _
auto_psv
_ _
,
_ _
irq
__
(52)))
MyIRQ(void);
Similarly, to specify that a function should use alternate interrupt vector 52, use the fol-
lowing:
lowing:
void
__
attribute
_ _
((
__
interrupt
_ _
,
_ _
auto_psv
_ _
,
_ _
altirq
_ _
(52)))
MyAltIRQ(void);
Note:
A device Reset is not handled through the interrupt vector table. Instead,
on device Reset, the program counter is cleared. This causes the processor
to begin execution at address zero. By convention, the linker script
constructs a GOTO instruction at that location which transfers control to the
C run-time startup module.
on device Reset, the program counter is cleared. This causes the processor
to begin execution at address zero. By convention, the linker script
constructs a GOTO instruction at that location which transfers control to the
C run-time startup module.