ECE391 - Ch3 - Interrupts and Handlers - ARM
ECE391 - Ch3 - Interrupts and Handlers - ARM
2
10/24/202
• Switching Processor
Mode at Interrupt
4
10/24/202
• Control[1] = 1: Thread Level Uses Process Stack and Handler Uses Main Stack
6
10/24/202
8
10/24/202
10
10/24/202
3. Interrupt - NVIC
Nested Vectored Interrupt Controller (NVIC)
• Handles exceptions and interrupts
• 8 programmable priority levels, priority grouping
• 7 exceptions and 65 Interrupts
• Automatic state saving and restoring
• Automatic reading of the vector table entry
• Pre-emptive/Nested Interrupts
• Tail-chaining
• Deterministic: always 12 cycles or 6 with tail-chaining
Tail Chaining...
IRQ2
PUS PO PUS
Typical processor ISR 1 ISR 2 POP
H P H
Tail-chaining
PUS PO
Cortex-M4 ISR 1 ISR 2
Interrupt handling in HW H P
12 6 12
Cycles Cycles Cycles
Pre-emption …
10/24/202
IRQ2
P
PO
Cortex-M4 ISR 1 O ISR 2
P
P
1- 6 12
12 Cycles
Cycles Cycles
Late arrival...
Highest IRQ1
Priority
IRQ2
PUS PO
Cortex-M4 ISR 1 ISR 2
H P
6 12
Cycles Cycles
Interrupt handling...
10/24/202
Entry
Automatically pushes registers R0–R3, R12, LR, PSR, and PC onto the stack
In parallel, ISR is pre-fetched on the instruction bus. ISR ready to start
executing as soon as stack PUSH complete
Exit
Processor state is automatically restored from the stack
In parallel, interrupted instruction is pre-fetched ready for execution upon
completion of stack POP
Exception types...
Vector Table...
10/24/202
GPTM...
Interrupt Configuration
• Interrupt Enable
– void IntDisable (unsigned long ulInterrupt)
– void IntEnable(unsigned long ulInterrupt)
– tBoolean IntMasterDisable (void)
– tBoolean IntMasterEnable (void)
– void TimerIntEnable (unsigned long ulBase, unsigned long
ulIntFlags)
• Example
– IntEnable(INT_TIMER0A);
– TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
– IntMasterEnable();
18
10/24/202
Interrupt Handler
Interrupt handler sample: toggle a LED at GPIO_PIN2
void Timer0IntHandler(void)
{
// Clear the timer interrupt
TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
// Read the current state of the GPIO pin and
// write back the opposite state
if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_2))
{
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0);
}
else
{
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 4);
}
}
19
Class Assignment
• Write a program to toggle the LED on the LM4F120
kit with the frequency 20Hz using Timer1 and
interrupt
20