|
Enabling and Disabling Global Interrupts |
Top Previous Next |
|
There are times whern you may wish to disable interrupts. This is usually needed when you have to ensure that a short sequence of code cannot be interrupted. The emphasis must be on short; it is a mistake to disable interrupts for anything except the briefest possible period.
Controlling interrupts globally on the C6000 is surprisingly difficult for several reasons, not the least of which is that you have to prevent the compiler from optimising your code and moving sequences you want to protect out of the interrupt-free zone.
The following functions can be used to control the processors global interrupt enable:
The standard way to use these functions is:
unsigned int old; . . . old = c6xint_off(); // interrupts off // // do something with interrupts disabled // c6xint_restore(old); // restore old CSR/GIE state
Do not be tempted to disable and enable interrupts by simply clearing and setting GIE directly in the CSR. Doing so can lead to unexpected behaviour because of code reordering by the compiler and unhelpful processor behaviour involving PGIE.
Note that indiscriminate global disabling of interrupts is likely to have a bad effect on performance. | ||||||||||