Avoiding Possible Hitches with Enabled Pragma Interrupt

If a routine that has pragma interrupt enabled (caller) calls another C function/routine (callee), it is possible that the callee can change some registers that are not saved by the caller. For example, use of volatile registers by callee.

//Example of a hitch

#pragma interrupt 
ISR_caller()
{
      // Register B not used
      Subroutine_Callee();
}

Subroutine_Callee()
{
     // Register B used and won't be saved/restored as this is volatile register
}

To avoid this, use either of the following options:

// Solution for the hitch using called mode

#pragma interrupt 
ISR_caller()
{
     // Register B not used
     Subroutine_Callee();
}

#pragma interrupt called
Subroutine_Callee()
{
     // Register B used and will be saved and restored due to use of interrupt called mode
}

The first option may be more efficient because only the registers that are used are preserved. The second option is easier to implement, but is likely to have a large overhead.

The situation described above also holds true for library functions because library functions do not have pragma interrupt enabled. These calls include: C Standard Library calls and Runtime Library calls (such as multiplication, division and floating point math).