Microchip Technology SW006022-1N Data Sheet
MPLAB
®
XC16 C Compiler User’s Guide
DS52071B-page 128
2012 Microchip Technology Inc.
7.4.2.3
ISR CONSIDERATIONS
A data access using managed PSV pointers is definitely not atomic, meaning it can
take several instructions to complete the access. Care should be taken if an access
should not be interrupted.
take several instructions to complete the access. Care should be taken if an access
should not be interrupted.
Furthermore an Interrupt Service Routine (ISR) never really knows what the current
state of the PSVPAG register will be. Unfortunately the compiler is not really in any posi-
tion to determine whether or not this is important in all cases.
state of the PSVPAG register will be. Unfortunately the compiler is not really in any posi-
tion to determine whether or not this is important in all cases.
The compiler will make the simplifying assumption that the writer of the interrupt service
routine will know whether or not the automatic, compiler managed PSVPAG is required
by the ISR. This is required to access any constant data in the auto_psv space or any
string literals or constants when the default -mconst-in-code option is selected.
When defining an interrupt service routine, it is best to specify whether or not it is nec-
essary to assert the default setting of the PSVPAG SFR.
routine will know whether or not the automatic, compiler managed PSVPAG is required
by the ISR. This is required to access any constant data in the auto_psv space or any
string literals or constants when the default -mconst-in-code option is selected.
When defining an interrupt service routine, it is best to specify whether or not it is nec-
essary to assert the default setting of the PSVPAG SFR.
This is achieved by adding a further attribute to the interrupt function definition:
• auto_psv - the compiler will set the PSVPAG register to the correct value for
accessing the auto_psv space, ensuring that it is restored when exiting the ISR
• no_auto_psv - the compiler will not set the PSVPAG register
For example:
void
_ _
attribute
_ _
((interrupt, no_auto_psv)) _T1Interrupt(void) {
IFS0bits.T1IF = 0;
}
The choice is provided so that, if you are especially conscious of interrupt latency, you
may select the best option. Saving and setting the PSVPAG will consume approximately
3 cycles at the entry to the function and one further cycle to restore the setting upon
exit from the function.
may select the best option. Saving and setting the PSVPAG will consume approximately
3 cycles at the entry to the function and one further cycle to restore the setting upon
exit from the function.
Note that boot or secure interrupt service routines will use a different setting of the
PSVPAG
PSVPAG
register for their constant data.
7.4.3
Size Limitations of Program Memory Variables
Arrays of any type (including arrays of aggregate types) can be qualified const and
placed in the program memory. So too can structure and union aggregate types, see
Section 6.5 “Structures and Unions”. These objects can often become large in size
and may affect memory allocation.
placed in the program memory. So too can structure and union aggregate types, see
Section 6.5 “Structures and Unions”. These objects can often become large in size
and may affect memory allocation.
For objects allocated in a compiler-managed PSV window (auto_psv space) the total
memory available for allocation is limited by the size of the PSV window itself. Thus no
single object can be larger than the size of the PSV window, and all such objects must
not total larger than this window.
memory available for allocation is limited by the size of the PSV window itself. Thus no
single object can be larger than the size of the PSV window, and all such objects must
not total larger than this window.
The variables allocated to program memory are subject to similar constraints as data
space objects in terms of maximum size, but they are allocated to the larger program
space rather than data space memory. Section 7.3.1.3 “Non-Auto Variable Size Lim-
its” which describes defining and using large arrays is also applicable to objects in pro-
gram space memory.
space objects in terms of maximum size, but they are allocated to the larger program
space rather than data space memory. Section 7.3.1.3 “Non-Auto Variable Size Lim-
its” which describes defining and using large arrays is also applicable to objects in pro-
gram space memory.