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.

msp430fw423: How to enter LPM3 (low power mode) and enable interrupts in atomic way?

Part Number: MSP430FW423

Hi,

I need to do in atomic way two things:
1. enter LPM3 low power mode and
2. enable interrupts.

I undertand that I can do this by correct setting SR register. My question is: can I do these in one intruction, and it will be truly atomic?

Method A. Direct SR register setting: 

C:    __bis_SR_register( LPM3_bits | GIE );

That is compiled to spu intruction:

          bis  #216, SR

Method B. Indirect SR setting by RETI 

          push #Label_1
          push #216
          reti

Label_1:   

I need to be sure, that the method is correct way of doing this in atomic way.
I am affraid that there might be some hardware hazard (even if I set SR in one instruction) that would result:
a) not entering low power mode, or
b) not enabling interrupts,
c) (only for Method B) there are some side effects of using RETI outside ISR.

Regards,
Piotr

  • For the CPU, there is not really any difference between "inside ISR" and "outside ISR"; that RETI will work just fine.

    But the __bis_SR_register functions is guaranteed to map to a single, atomic instruction. (If the BIS were not atomic, the RETI wouldn't be either.)

**Attention** This is a public forum