17.3.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 dispatch 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 vector locations, preventing their use. In such situations, using a dispatch function is a safer option.
The newer devices family features variable offsets for vector spacing. The compiler and
linker work together to treat the OFF
nnn
SFRs
as initialized data so that they are initialized at startup. This means there is no need
for application code to initialize the OFF
nnn
SFRs. This also means that it is often more efficient to place the ISR within the vector
table rather than using a dispatch function.
Example Interrupt Service Routine
#include <xc.h>
#include <sys/attribs.h>
void
__ISR_AT_VECTOR(_CORE_TIMER_VECTOR, IPL7SRS)
CoreTimerHandler(void)
{
// ISR code here
}