12.3.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.

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 position 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 necessary 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.