#include <htc.h>
-extern bit isr_gie;
-extern unsigned char isr_di;
+extern bit _isr_gie;
+extern unsigned char _isr_di;
-/* Nested disable interrupts inline function, for use outside ISR */
+/* Nested disable interrupts inline function. Should be OK even in ISR. */
#define ndi() \
do { \
- if (isr_di++ == 0) \
- isr_gie = GIE; \
- if (isr_gie) \
- di(); \
+ if (_isr_di++ == 0) { \
+ _isr_gie = GIE; \
+ di(); \
+ } \
} while (0)
-/* Nested enable interrupts inline function, for use outside ISR */
+/* Nested enable interrupts inline function. Should be OK even in ISR. */
#define nei() \
do { \
- if (--isr_di == 0) \
- if (isr_gie) { \
- isr_gie = 0; \
- ei(); \
- } \
+ if (--_isr_di == 0 && _isr_gie) \
+ ei(); \
} while (0)
void interrupt isr();