16.7.2 PSV Usage with Interrupt Service Routines
The introduction of managed psv pointers and CodeGuard Security psv
constant sections 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
memory model, the auto_psv
attribute should be added to the function definition. This attribute will cause the
compiler to preserve the previous contents 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)) _T1Interrupt()
{
/* 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
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
attribute.