370 likes | 614 Views
ARM interrupts and the VIC. Interrupt. Interrupt. Interrupt return. Interrupt code. Main program code. ARM interrupts. ARM runs in 1 of 6 modes each mode has (some) unique registers mode is available to outside world (fi: for a memory managment unit – not in LPC2106)
E N D
ARM interrupts and the VIC Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
Interrupt Interrupt Interrupt return Interrupt code Main program code Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
ARM interrupts • ARM runs in 1 of 6 modes • each mode has (some) unique registers • mode is available to outside world (fi: for a memory managment unit – not in LPC2106) • current mode is in the CPSR register • 2 ‘normal’ interrupts: IRQ, FIQ Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
N Z C V ARM User Programming model mode 0 31 31 0 31 0 r0 r8 CPSR r1 r9 Status register r2 r10 r3 r11 r4 r12 r13: stack pointer r14: link register r5 r13 r6 r14 r7 r15 (PC) Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
All ARM registers Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
interrupt start • switch to the interrupt mode (IRQ or FIQ) (this switches to the new set of registers!) • copy PC to LR • copy CPSR to SPSR • set PC to start of interrupt code (fixed) notes: • Almost the same as a procedure call (BL) • no use of the stack • No (automatic) saving of registers Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
IRQ • ‘normal’ interrupts • Private LR (of course) • Private SP • no other private registers (must save users registers) Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
FIQ • typically used for ‘simple & fast’ processing • Private LR (of course) • Private SP • Private R6 .. R12 • Low latency: • no need to save user’s registers • no need to initialise FIQ registers! Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
VIC • Vectored Interrupt Controller • between interrupt sources and the ARM core • handles: priorities and vectoring http://www.arm.com/pdfs/DDI0181E_vic_pl190_r1p2_trm.pdf Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
interrupt priorities • FIQs • Vectored IRQs • Non-vectored IRQs While the code for an interrupt is running lower interrupts are blocked The interrupt code must inform the VIC when its done! Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
vectors Each • FIQ • vectored IRQ has a unique vector. In most cases this will be the start address of the code that handles the interrupt. All non-vectored IRQs share one vector, the interrupt code must inquire which interrupt has occured. Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
interrupt sources • 32 sources possible • 16 hardware sources implemented on an LPC 2106 Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
forcing, masking, assigning Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
forcing I Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
masking I Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
IRQ /FIQ assigning I Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
FIQ Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
FIQ I Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
non-vectored IRQ Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
non-vectored IRQ I Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
vectors Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
vectors • 16 vector slots • 0 has highest priority, 15 lowest • each slot contains • enable bit • the interrupt source (0..31) • the vector address (32 bits) Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
vectors I Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
IRQ arbitration Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
IRQ arbitration I Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
interrupt end This is not mentioned in the Philips manuals Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
interrupt configuration • probably: reserve and set the interrupt stack • make sure the hardware vector points to your code • configure the peripheral to generate interrupts • enable the interrupt source • select FIQ or IRQ • (vectored) set source, enable, vector • (non-vectored IRQ) set default vector • enable interrupts Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
set interrupt stack ldr r2, = … mrs r0, cpsr @ Original PSR value bic r0, r0, #0x1F @ Clear the mode bits orr r0, r0, #0x12 @ Set IRQ mode bits msr cpsr_c, r0 @ Change the mode mov sp, r2 bic r0, r0, #0x1F @ Clear the mode bits orr r0, r0, #0x13 @ Set Supervisor bits msr cpsr_c, r0 @ Change the mode Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
interrupt vectors ldr pc, =ResetHandler @ reset vector ldr pc, =ResetHandler @ undefined instruction ldr pc, =ResetHandler @ software interrupt ldr pc, =ResetHandler @ prefetch abort ldr pc, =ResetHandler @ data abort ldr pc, =ResetHandler @ reserved ldr pc, [pc, #-0xFF0] @ IRQ. load vector @ from VICVectAddr ldr pc, =ResetHandler @ FIQ Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
interrupt code • (probably) save registers • do what you have to do • clear the interrupt source • write to VicVectAddr • return: subs pc, lr, #4 Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
enable / disable interrupts Why? • protect data that is used by both main and interrupts • protect code that must execute with a fixed timing Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
enable / disable interrupts __disable_interrupts: mrs r0, CPSR orr r0, r0, #0x80 @ disable IRQ interrupts msr CPSR_fsxc, r0 mov pc, lr __enable_interrupts: mrs r0, CPSR bic r0, r0, #0x80 @ enable IRQ interrupts msr CPSR_fsxc, r0 mov pc, lr Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology