ARM Technical Support Knowledge Articles

WHAT'S THE BEST WAY TO DISABLE/REENABLE INTERRUPTS

Applies to: C51 C Compiler

Answer


Information in this article applies to:


QUESTION

What's the best way to disable interrupts (for ISR configuration) and reenable them when I'm done?

I know that the 8051 has an EA (enable all) flag for interrupts, but is it guaranteed that the interrupt does not occur after the instruction EA=0?

ANSWER

There are 2 good ways to accomplish this.

  1. Use a #define to create definitions for ENABLE_INTERRUPTS and DISABLE_INTERRUPTS. For example:
    #define ENABLE_INTERRUPTS { EA = 1; }
    #define DISABLE_INTERRUPTS { EA = 0; }
    

    Then, in your program:

    void ISR_setup (void)
    {
    DISABLE_INTERRUPTS
    // Set timer reload
    // Set timer mode
    // EtCetera
    ENABLE_INTERRUPTS
    }
    
    
  2. Use the #pragma disable directive to disable interrupts for an entire function. Then, you can create a function that sets up the ISR or whatever and not even DEAL with the EA=0 bit. For example:
    #pragma disable
    void ISR_setup (void)
    {
    // Set timer reload
    // Set timer mode
    // EtCetera
    }
    

    The benefit of this method is that #pragma disable restores the previous state of the EA bit. So, if interrupts were disabled when you entered this function, they will still be disabled on exit.

The hardware of the 8051 guarantees that interrupts are disabled after execution of EA = 0. So you need not to worry about any pipeline effects.

MORE INFORMATION

SEE ALSO

Article last edited on: 2005-07-15 14:07:38

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential