5.10 __get_interrupt_state Intrinsic Function
The IAR __get_interrupt_state
intrinsic function returns the global interrupt
state, which can be saved and used later by the __set_interrupt_state
intrinsic function to restore the global interrupt state.
Suggested Replacement
There is no MPLAB XC8 equivalent built-in function; however, a similar code sequence can be inserted explicitly using in-line assembly code.
Use in-line assembly to directly fetch the state of the register, storing it in an appropriate C object.
Caveats
None
Examples
Consider migrating IAR code such
as:
extern int mode;
void clearMode_safe()
{
__istate_t s = __get_interrupt_state();
__disable_interrupt();
mode = 0x0;
__set_interrupt_state(s);
}
to
MPLAB XC8 code similar
to:#include <xc.h>
unsigned char get_interrupt_state(void) {
unsigned char s;
__asm__ ("in %0, __SREG__"
:"=d" (s));
return s;
}
void set_interrupt_state(unsigned char s) {
__asm__ ("sbrs %0, 7 \n\t"
"rjmp .+4 \n\t"
"sei \n\t"
"rjmp .+2 \n\t"
"cli \n\t"
: : "r" (s));
}
extern int mode;
void clearMode_safe()
{
unsigned char s = get_interrupt_state();
di();
mode = 0x0;
set_interrupt_state(s);
}
Further Information
See the In-line Assembly section in the MPLAB XC8 C Compiler User's Guide for AVR MCUs for more information on adding in-line assembly.