next up previous contents index
Next: 3.10.3 Semaphore locking (mcs51/ds390) Up: 3.10 Enabling and Disabling Previous: 3.10.1 Critical Functions and   Contents   Index

3.10.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 seperate 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;

...
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 reenable 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 reenabling interrupts within the interrupt routine. Check there is sufficient space on the stack and don't add complexity unless you have to.


next up previous contents index
Next: 3.10.3 Semaphore locking (mcs51/ds390) Up: 3.10 Enabling and Disabling Previous: 3.10.1 Critical Functions and   Contents   Index
2008-12-05