Microchip Technology SW006023-1N Data Sheet

Page of 238
Interrupts
 2012 Microchip Technology Inc.
DS51686E-page 139
void __ISR(_TIMER_1_VECTOR, IPL7AUTO) Timer1Handler(void)
{
  // clear the interrupt flag
  mT1ClearIntFlag();
  // .. things to do
  // .. in this case, toggle the LED
  mPORTDToggleBits(BIT_0);
}
#ifdef __cplusplus
 }
#endif
11.4
ASSOCIATING A HANDLER FUNCTION WITH AN EXCEPTION VECTOR
For PIC32MX devices, there are 64 exception vectors, numbered 0..63 inclusive. Each 
interrupt source is mapped to an exception vector as specified in the device data sheet. 
By default, four words of space are reserved at each vector address for a dispatch to 
the handler function for that exception source.
An interrupt handler function can be associated with an interrupt vector either as the 
target of a dispatch function located at the exception vector address, or as being 
located directly at the exception vector address. A single handler function can be the 
target of multiple dispatch functions.
The association of a handler function to one or more exception vector addresses is 
specified via a vector attribute on the function declaration. For compatibility purposes, 
you may also associate a handler function to a vector address using a clause of the 
interrupt pragma, a separate vector pragma, or a vector attribute on the function 
declaration.
11.4.1
Vector Attribute
A handler function can be associated with one or more exception vector addresses via 
an attribute. The at_vector attribute indicates that the handler function should itself 
be placed at the exception vector address. The vector attribute indicates that a dis-
patch function should be created at the exception vector address(es) which will transfer 
control to the handler function.
For example, the following declaration specifies that function foo will be created as an 
interrupt handler function of priority four. foo will be located at the address of exception 
vector 54.
void __attribute__ ((interrupt(IPL4SOFT))) __attribute__ 
((at_vector(54))) foo (void)
The following declaration specifies that function foo will be created as an interrupt 
handler function of priority four. Define dispatch functions targeting foo at exception 
vector addresses 52 and 53.
void __attribute__ ((interrupt(IPL4SOFT))) __attribute__ 
((vector(53, 52))) foo (void)
Handler functions that are linked directly to the vector will be executed faster. Although 
the vector spacing can be adjusted, there is limited space between vectors and linking 
a substantial handler function directly at a vector may cause it to overlap the higher vec-
tor locations, preventing their use. In such situations, using a dispatch function is a 
safer option.