This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Difference between __enable_interrupt() and __bis_SR_register(GIE)

Other Parts Discussed in Thread: MSP430F5419A

Hello,

Can anyone please specify what's the difference between  __enable_interrupt() and __bis_SR_register(GIE). Both are defined as intrinsic instruction according to  io430.h file.

Thanx and regards,

Sunil

  • They are the same.

    __enable_interrupt() : Enables interrupts by inserting the EINT instruction.

    EINT is an emulated instruction that is equivalent to BIS #8,SR

    __bis_SR_register(GIE) is an intrinsic that is also equivalent to BIS #8,SR

    The main difference between the two constructions is that __bis_SR_register() allows you to set more than just the GIE bit, while __enable_interrupt() only sets GIE bit.

    The same applies to the use of __disable_interrupt(); DINT; and bic_SR_register(GIE);

  • Also there is a small chance, that __enable_interrupt() is "portable" to another MCU, while __bis_SR_register(GIE) is not.

    H.

  • Actually, a good method to help with portability is to make your own definitions for interrupt state handling. For instance, for MSP430....

    // Define the interrupt control macros.
    #define MODIFIES_INT_FLAGS    istate_t gieSave
    #define SAVE_AND_DISABLE_INTS gieSave = __get_interrupt_state(); _DINT()
    #define RESTORE_INTS          __set_interrupt_state(gieSave)
    #define ENABLE_INTS _EINT();

    ....
    void main(void){
    MODIFIES_INT_FLAGS;
    .... code
    ENABLE_INTS; // enable interrupts
    ..... code
    // some code requiring mutex
    SAVE_AND_DISABLE_INTS;
    // code here
    RESTORE_INTS;
    // end mutex
    ....
    }

    Then when porting just modify the definitions for the new processor and the rest of the code works (generally speaking, of course).

  • All of you, Thanks for quick response..

    Brian Boorman said:
    The main difference between the two

    Ok.. then which one should i prefer in my code while disabling and enabling interrupts while doing Flash read-write? Or both are exactly same and doesn't make any difference? I am using MSP430F5419A and code composer studio v4.

  • If all you are doing is enabling/disabling interrupts, then either is ok. I would use __enable_interrupt() myself since it makes the code easier to read.

**Attention** This is a public forum