In some very rare situations one can have to violate the interruptibility rule.
In this case, interruptions must be masked. In order to keep the code consistent with interruptions usage
you must use the following macro to manage interrupts (ie: never change the INTCON
enabling bits (GIE/GIEH/GIEL
) directly).
MASK_HI_PRI_IT
: disable high priority interrupts.
MASK_LO_PRI_IT
: disable low priority interrupts.
UNMASK_HI_PRI_IT
: enable high priority interrupts.
UNMASK_LO_PRI_IT
: enable low priority interrupts.
Before entering a critical (ie: non-interruptible) section, just use the DISABLE_IT
macro : it will atomically
disable all interrupts.
When you leave the critical section, use the ENABLE_IT
macro : interrupts will be restored to the previous state, no matter they were enabled or not.
Of course, never change the interrupt status in a critical section, and never enter a critical section from a critical section.
Caution: never use one of these macros in an Interrupt Service Routine because it is likely to cause an infinite recursive call of the ISR. This limitation is caused by a flaw in the design of the PIC18 architecture. All these macros are defined in <interrupt.h> header. |
Alain Gibaud 2015-07-09