Skip to content

Instantly share code, notes, and snippets.

@iori-yja
Created January 11, 2012 07:53
Show Gist options
  • Save iori-yja/1593618 to your computer and use it in GitHub Desktop.
Save iori-yja/1593618 to your computer and use it in GitHub Desktop.
IRQ handler for LPC23xx ARM microcontroller
.section .text, "ax"
.arm
IRQ_Handler:
SUB LR, LR, #4 @ Adjust LR_irq and push it
STMFD SP!, {LR}
MRS LR, SPSR @ Save SPSR need to be saved for nested interrupt
STMFD SP!, {R0-R3,IP,LR} @ Push scratch/used registers and SPSR
LDR R0, =LPC_BASE_VIC @ Get the ISR address pointed by VIC_VectAddr
LDR R0, [R0, #VIC_Address]
MSR CPSR_c, #M_SVC @ Enter SVC mode and enable Irq and Fiq
STMFD SP!, {LR} @ Call the ISR
MOV LR, PC
BX R0
LDMIA SP!, {LR}
MSR CPSR_c, #M_IRQ | B_Irq @ Enter IRQ mode and disable Irq
LDMIA SP!, {R0-R3,IP,LR} @ Restore scratch/used registers and SPSR
MSR SPSR_cxsf, LR @ Restore SPSR_irq
LDR LR, =LPC_BASE_VIC @ Issue EOI command to the VIC
STR LR, [LR, #VIC_Address]
LDMIA SP!, {PC}^ @ Reruen from the IRQ handler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment