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.

MSP430FR5969: Stack Memory Modification in Interrupt Service Routine.

Part Number: MSP430FR5969

I wants to write a code in ISR. But Large code in ISR is not preferable. So i am going to use the inline assembly function to read the address of next instruction that stores before the interrupt occur.  and store this address into local variable . and replace the address of next instruction in the stack memory with my call back function where i am going to execute all required task as done in ISR before . In call back function, after the execution of all task i simply jump to the next instruction address store in local variable. In simple, after the execution of ISR the control should return back to the next instruction address in normal way, but in my case i redirect the flow control from ISR to my call back function and from call back function return to the next instruction address. 

So Question is this way of programming is preferable or not?

  • You forgot to save the values in all CPU registers.

    If you do save the registers (and switch the stack while you're at it), you essentially have task switching. It might be a better idea to use an RTOS to begin with.

    Anyway, the reason for avoiding too much code in an ISR is to prevent the main code from being interrupted for too long. Your callback function mechanism does not change that.

  • hello Clemens Ladisch,

    I already saved all CPU register. and did the stack modification and my code is working fine without any memory violation. I have to write a large code in ISR so that's why i am using this technique, so i release the ISR as soon as possible. so it's not block the others interrupt.

    Is it the right way to changing the stack or redirection of flow control of program.
  • With the context saving and stack switching, you have implemented a task switching mechanism. How do you call it, AnilOS? :-)

    And yes, this is the right way if you want to execute some task in reaction to an interrupt, and do not want to check for events in a main loop.

**Attention** This is a public forum