Return from interrupt routine

[NetOS 5.1] I’m using timer 2 to generate an interrupt. In order to configure it I use the function netosSetupAuxClock() that comes in the BSP. When the timer expires the interrupt ocurrs and my Interrupt Software Routine (a C function) is called. The problem is that I don’t know how to return from the ISR. According to the documentation you must return with the assembly instruction: subs pc, r14, #4 At the end of my C ISR function I call an assembly function that performs ‘subs pc,r14,#4’ but it does not work. I think that, somehow, the returning point is not stored in R14. Has anybody some sample code that shows how to return form a FIRQ?

If you are using the GNU tools you can use: attribute((interrupt(“FIQ”))) appended to the function prototype… For example: void CPU_fiq_handler( void ) attribute((interrupt(“FIQ”))); Which wraps the “CPU_fiq_handler” function with suitable stack frame handling and returns with a “subs pc, r14, #4” instruction… Assuming you have GCC >= V3.3.1 or <= V2.95 that is :wink: don’t you just love compiler bugs… The Geenhills tools will have a similar directive, probably a #pragma or __FIRQ, that goes before the prototype… Hope this helps Dave

BTW the reason R14 doesn’t contain the correct return address is that “calling” your assembler for ‘subs pc,r14,#4’ has changed R14… then doing ‘subs pc,r14,#4’ returns to the instruction after the call in the ISR which then tries to exit the ISR standard way for a normal C function… This return -> corruption of the stack and the register contents prior to the ISR