3.21 __raw Keyword
The IAR __raw
keyword prevents saving call-used registers in interrupt
functions.
Suggested Replacement
There is no MPLAB XC8 feature that performs the same function as this keyword; however, there is an attribute which performs a similar task.
The naked
attribute can be used to prevent generation of the entire
prologue and epilogue context switching associated with an interrupt function.
Caveats
The naked
attribute prevents the call-used registers from being
saved, but it also omits code that performs other operations typically required by
interrupt functions, such as generation of the reti
instruction,
and saving and clearing r1 (__zero_reg__
) on entry, and the reverse
process on exit.
Examples
volatile int x;
#pragma vector=2
__raw __interrupt void incIsr(void) {
x++;
}
to
MPLAB XC8 code similar
to:#include <xc.h>
volatile int x;
void __attribute__((naked)) __interrupt(2) incIsr(void) {
// insert hand-written context switch code here
x++;
// insert hand-written context switch and return-from-interrupt code here
}
Further Information
See the Interrupts section in the MPLAB XC8 C Compiler User's Guide for AVR MCUs for more information on writing interrupt functions.