Microchip Technology SW006022-2N Data Sheet
MPLAB
®
XC16 C Compiler User’s Guide
DS52071B-page 186
2012 Microchip Technology Inc.
11.8.2
PSV Usage with Interrupt Service Routines
The introduction of managed psv pointers and CodeGuard Security psv constant sec-
tions in compiler v3.0 means that ISRs cannot make any assumptions about the setting
of PSVPAG. This is a migration issue for existing applications with ISRs that reference
the auto_psv constants section. In previous versions of the compiler, the ISR could
assume that the correct value of PSVPAG was set during program startup (unless the
programmer had explicitly changed it.)
tions in compiler v3.0 means that ISRs cannot make any assumptions about the setting
of PSVPAG. This is a migration issue for existing applications with ISRs that reference
the auto_psv constants section. In previous versions of the compiler, the ISR could
assume that the correct value of PSVPAG was set during program startup (unless the
programmer had explicitly changed it.)
To help mitigate this problem, two new function attributes will be introduced: auto_psv
and no_auto_psv. If an ISR references const variables or string literals using the
constants-in-code
and no_auto_psv. If an ISR references const variables or string literals using the
constants-in-code
memory model, the auto_psv attribute should be added to the
function definition. This attribute will cause the compiler to preserve the previous con-
tents of PSVPAG and set it to section .const. Upon exit, the previous value of
PSVPAG will be restored. For example:
tents of PSVPAG and set it to section .const. Upon exit, the previous value of
PSVPAG will be restored. For example:
void _ _attribute_ _((interrupt, auto_psv)) myISR()
{
/* This function can reference const variables and
string literals with the constants-in-code memory model. */
}
The no_auto_psv attribute is used to indicate that an ISR does not reference the
auto_psv
auto_psv
constants section. If neither attribute is specified, the compiler assumes
auto_psv
and inserts the necessary instructions to ensure correct operation at run
time. A warning diagnostic message is also issued that alerts the user to the migration
issue, and to the possibility of reducing interrupt latency by specifying the
no_auto_psv
issue, and to the possibility of reducing interrupt latency by specifying the
no_auto_psv
attribute.
11.8.3
Latency
There are two elements that affect the number of cycles between the time the interrupt
source occurs and the execution of the first instruction of your ISR code. These factors
are:
source occurs and the execution of the first instruction of your ISR code. These factors
are:
• Processor Servicing of Interrupt – the amount of time it takes the processor to
recognize the interrupt and branch to the first address of the interrupt vector. To
determine this value refer to the processor data sheet for the specific processor
and interrupt source being used.
determine this value refer to the processor data sheet for the specific processor
and interrupt source being used.
• ISR Code – although an interrupt function may call other functions, whether they
be user-defined functions, library functions or implicitly called functions to imple-
ment a C operation, the compiler cannot know, in general, which resources are
used by the called function. As a result, the compiler will save all the working reg-
isters and RCOUNT, even if they are not all used explicitly in the ISR itself. The
increased latency associated with the call does not lend itself to fast response
times.
ment a C operation, the compiler cannot know, in general, which resources are
used by the called function. As a result, the compiler will save all the working reg-
isters and RCOUNT, even if they are not all used explicitly in the ISR itself. The
increased latency associated with the call does not lend itself to fast response
times.