Keywords: sdccman

## 3.9.2 Enabling and Disabling Interrupts directly

Interrupts can also be disabled and enabled directly (8051):

> EA = 0; or: EA_SAVE = EA;

> ... EA = 0;

> EA = 1; ...

> EA = EA_SAVE;

On other architectures which have separate opcodes for enabling and disabling interrupts you might want to make use of defines with inline assembly (HC08):

> #define CLI __asm cli __endasm;

> #define SEI __asm sei __endasm;

> or for SDCC version 3.2.0 or newer:

> #define CLI asm (”cli”);

> #define SEI asm (”sei”);

Note: it is sometimes sufficient to disable only a specific interrupt source like f.e. a timer or serial interrupt by manipulating an interrupt mask register.

Usually the time during which interrupts are disabled should be kept as short as possible. This minimizes both interrupt latency (the time between the occurrence of the interrupt and the execution of the first code in the interrupt routine) and interrupt jitter (the difference between the shortest and the longest interrupt latency). These really are something different, f.e. a serial interrupt has to be served before its buffer overruns so it cares for the maximum interrupt latency, whereas it does not care about jitter. On a loudspeaker driven via a digital to analog converter which is fed by an interrupt a latency of a few milliseconds might be tolerable, whereas a much smaller jitter will be very audible.

You can re-enable interrupts within an interrupt routine and on some architectures you can make use of two (or more) levels of interrupt priorities. On some architectures which don't support interrupt priorities these can be implemented by manipulating the interrupt mask and re-enabling interrupts within the interrupt routine. Check there is sufficient space on the stack and don't add complexity unless you have to.