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.

replace an interrupt service routine(ISR) with a normal function?



hi,

can we replace an interrupt service routine(ISR) with a normal function.

will it work properly.

  • This can cause issues with your code since the ret will only pop the PC where as the reti will first pop the SR and then PC. Effectively your SR value will move into PC when you use ret to exit the ISR.

    Regards,

    Rakesh

  • ISRs are special in more than one way. The most obvious thing is the RETI instruction, as already noted. Since the hardware pushes PC and SR on the stack on an interrupt, both need to be restored. This could be done by doing a POP SR right before the RET.
    However, there are other, less obvious things going on. On an interrupt, the LPM bits are cleared, as well as GIE. On the POP SR, they are restored, before the RET is executed, which means the next interrupt will be handled before the RET is executed, which might lead to a stack overflow when multiple interrupts are happening during LPM.
    Next difference is that a normal function doesn't preserve the registers used for passing parameters and results. An ISR, however, has to do it.
    Finally, in case of a 430X CPU core, the upper 4 bits of the PC are pushed to stack together with the status register content, so you can't do a RETA to restore the original 20 bit PC.

    You can call a normal function from within an ISR, but it is somewhat ineffective. Not only the function call itself, but also the required register saving will add a significant overhead.

    The question is: why did you ask?

**Attention** This is a public forum