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.

MSP430FR6047: __bic_SR_register_on_exit assembly code needed

Part Number: MSP430FR6047

HI,

I have to abstract the call to 

__bic_SR_register_on_exit 
My Problem: I call this routine from an interrupt routine but in a subroutine. The compiler does not recognize this unfortunately, so I get a compiler error. 
Is it possible to get the assembly code for this routine?

Kind regards

  • Maybe a bit code to see what I want to achieve:

    template <typename Derived>
    class ITest
    {
    
      public:
      static constexpr inline void wakeup()
      {
        Derived::wakeupImpl();
      }
    };
    
    class Test : public ITest<Test>
    {
      protected:
    
      friend class ITest<Test>;
      static constexpr inline void wakeupImpl()
      {
        __bic_SR_register_on_exit(LPM3_bits);
      }
    
    };
    
    void __attribute__((interrupt(USCI_A0_VECTOR))) USCI_A0_ISR(void)
    {
      WakeState wakeState;
      MyUart::intByteReceived(wakeState);
    
      if(wakeState == WakeState::Wakeup)
      {
        Test::wakeup();
      }
    }

    leads to this error: 

    error: MSP430 builtin functions only work inside interrupt handlers
    [build]    84 |     __bic_SR_register_on_exit(LPM3_bits);
  • This must be used within the ISR because the compiler must know exactly where on the stack the SR register was saved. It knows that in the ISR but not within a function called from the ISR.

    Given that it says "on_exit" I would assume that this would usually, but not always, be deferred until just before the rti instruction.

    The instruction used is "bic #LMP3_bits,offset(SP)". You could of course use an asm() statement to insert that using an offset you determined to work. Today. It could of course break tomorrow when you update the compiler. Or change optimization level.

  • static __attribute__((always_inline)) inline void wakeUp()

    Thanks for the answer. My solution, to keep the abstraction, is now to force inlining. This works.

**Attention** This is a public forum