- This topic has 0 replies, 1 voice, and was last updated 2 weeks, 2 days ago by
Logan Moon.
-
AuthorPosts
-
February 6, 2025 at 9:28 pm #16767
(This message was transferred over from our old forum)
Posted August 19, 2015
By Todd DeBoer
[hr]
On 11/17/2009 wella asked, “just looking on the interrupt(IRQ) scheme and please could someone explain me interrupt behaviour of uEZ? From code, it seems an irq_handler is called(defined in LPC2478_VIC_irq_handler.s).
The rutine at first saves registers
// store the APCS registers in the non-tasking case
stmfd sp!, {r0-r4, r12, lr}
and than calls address obtained from VIC.
At the end it writes to VIC and returns.
However every irq routine starts with #define IRQ_START() RTOS_SAVE_CONTEXT(). In the RTOS_SAVE_CONTEXT() that yields to FreeRTOS portSAVE_CONTEXT() are also saved registers on stack.
/* Push all the system mode registers onto the task stack. */
“STMDB LR,{R0-LR}^”….Is it a feature for interrupts routines that are not FreeRTOS related or a redundance?
There is also a double write to the VICAddress. One from IRQ_END and the second from irq_handler.”
[hr]
(Follow up post)Answered:
The goal of the interrupts is to push the register on once, never twice. Doing so would never allow context switching. Therefore, you are correct to be confused by the code, but I assure you the registers are only pushed once.
Part of the confusion is that we had to do two different methods for Rowley and IAR due to some differences in the compilers.
In Rowley, the root vector table is defined in LPC2478_Startup.s. In addition, the define VECTORED_IRQ_INTERRUPTS has been turned on in the project file. What this does is bypass calling a generic irq_handler (via irq_handler_address) for calling directly the IRQ_ROUTINEs directly (fetch from VIC will have this address). IRQ_ROUTINEs then need to call IRQ_START , do their business, and end with IRQ_END . As you already know, these do the context saving and restoring as well as feeding/writing the VICAddress. To keep the compiler from generating IRQ push/pop code, the IRQ routines are declared ‘naked’.
In IAR, there are no similar ‘naked’ option and the compiler kept trying to insert pushes on the stack before we could save context. So we opted for a doing the context save/restore in low level assembly with a stub routine, one per interrupt (see portasm.s79 and portasm_part2.s79 and calls to InterruptHandlerX). In this case, portSAVE_CONTEXT and portRESTORE_CONTEXT is called directly in the assembly before the stack is touched.
-
AuthorPosts
- You must be logged in to reply to this topic.