Skip to content

Instantly share code, notes, and snippets.

@pamaury
Created January 30, 2014 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pamaury/8720923 to your computer and use it in GitHub Desktop.
Save pamaury/8720923 to your computer and use it in GitHub Desktop.
nested interrupt handling
void irq_handler(void)
{
/* read vector and notify as a read side-effect */
uint32_t vec = HW_ICOLL_VECTOR;
/* Save registers on IRQ stack, switch to SVC and renable interrupts */
asm volatile(
"mrs lr, spsr \n" /* Save SPSR_irq */
"stmfd sp!, { lr } \n" /* Push it on the IRQ stack */
"msr cpsr_c, #0x13 \n" /* Switch to SVC mode, enable IRQ */
"stmfd sp!, { lr } \n" /* Save lr_SVC */
);
int ack_lvl = _irq_handler(vec);
asm volatile(
"ldmfd sp!, { lr } \n" /* Restore lr_SVC */
"msr cpsr_c, #0x92 \n" /* Mask IRQ, return to IRQ mode */
"ldmfd sp!, { lr } \n" /* Pop back SPSR */
"msr spsr_cxsf, lr \n" /* Restore SPSR_irq */
);
HW_ICOLL_LEVELACK = 1 << ack_lvl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment