Outline: EE-379 Embedded Systems and Applications
Outline: EE-379 Embedded Systems and Applications
Interrupts (1)
Cristinel Ababei
Department of Electrical Engineering, University at Buffalo
Spring 2013
Note: This course is offered as EE 459/500 in Spring 2013
Outline
Introduction
NVIC and Interrupt Control
Interrupt Pending
Examples
Interrupt Service Routines
Some questions
How do you figure out where to branch/jump to?
If you know number the possible interrupt cases, and an
interrupt comes in, you can just branch to a location, using that
number as an offset
How to you ensure that you can get back to where you
started?
Store return address to stack or dedicated register?
Interrupts
An interrupt is the automatic transfer of software
execution in response to a hardware event that is
asynchronous with the current software
execution
This hardware event is called a trigger and it
breaks the execution flow of the main thread of
the program
The event causes the CPU to stop executing the
current program and begin executing a special
piece of code called an interrupt handler or
interrupt service routine (ISR)
Typically, the ISR does some work and then
resumes the interrupted program
Interrupts
The hardware event can either be:
1) A busy-to-ready transition in an external I/O device.
Caused by the external world
Peripheral/device, e.g., UART input/output device
Reset button, Timer expires, Power failure, System error
Names: exception, interrupt, external interrupt
2) An internal event
Cortex-M3 Interrupts
Exceptions:
System exceptions: numbered 1 to 15
External interrupt inputs: numbered from 16 up
Interrupt Programming
To arm (disarm) a device/peripheral means to
enable (shut off) the source of interrupts. Each
potential interrupting trigger has a separate
arm bit. One arms (disarms) a trigger if one is
(is not) interested in interrupts from this source.
To enable (disable) means to allow interrupts at
this time (postponing interrupts until a later
time). On the ARM Coretx-M3 processor, there is
one interrupt enable bit for the entire interrupt
system. In particular, to disable interrupts we set
the interrupt mask bit, I, in PRIMASK register.
Interrupt Programming
Interrupts on the Cortex-M3 are controlled by the
Nested Vectored Interrupt Controller (NVIC)
To activate an interrupt source we need to set
its priority and enable that source in the NVIC:
Activate = Set priority + Enable source in NVIC
Outline
Introduction
NVIC and Interrupt Control
Interrupt Pending
Examples
Interrupt Service Routines
Memory
Map
See page 77-80 of LPC17xx user manual for description of ISER0,ISER1 and ICER0,ICER1!
See page 81-84 of LPC17xx user manual for description of ISPR0,ISPR1 and ICPR0,ICPR1!
Active Status
Each external interrupt has an active status bit.
When the processor starts the interrupt handler, the bit
is set to 1 and cleared when the interrupt return is
executed.
Interrupt Active Bit Status registers
0xE000E300-0xE000E31C
10
Priority Levels
Each external interrupt has an associated prioritylevel register, which has a maximum width of 8
bits and a minimum width of 3 bits
Interrupt Priority Level registers
0xE000E400-0xE000E4EF
Interrupt Priority
An exception can be carried out can be
affected by the priority of the exception
A higher-priority (smaller number in priority
level) exception can preempt a lower-priority
(larger number in priority level) exception
Cortex-M3 supports three fixed highestpriority levels and up to 256 levels of
programmable priority (a maximum of 128
levels of preemption
Most Cortex-M3 chips have fewer supported
levels - for example, 8, 16, 32, ...
11
Levels of priority
Reduction of levels is implemented by cutting out
the LSB part of the priority configuration
registers. Example of 3-bit implemented:
Interrupt priority
Priority can be sub-divided into priority groups
Splits priority register into two halves:
Preempt priority indicates if an interrupts can
preempt another
Sub priority used if 2 interrupts of the same
group arrive at the same time
12
Vector Tables
When an exception takes place and is being
handled by the Cortex-M3, the processor will
need to locate the starting address of the
exception handler
This information is stored in the vector table
Each exception has an associated 32-bit vector
that points to the memory location where the
ISR that handles the exception is located
Vectors are stored in ROM at the beginning of
the memory
Vector Table
Exception vector table after power-up is located at address
0x00000000:
13
Vector Table
Example of a few vectors as defined inside
startup_LPC17xx.s:
__Vectors
DCD
__initial_sp
DCD
Reset_Handler
DCD
NMI_Handler
DCD
HardFault_Handler
...
; External Interrupts
DCD
WDT_IRQHandler
DCD
TIMER0_IRQHandler
...
DCD
UART0_IRQHandler
;
;
;
;
Top of Stack
Reset Handler
NMI Handler
Hard Fault Handler
14
Software interrupts
Software interrupts can be generated in two
ways:
Use the SETPEND register
Use the Software Trigger Interrupt Register (STIR)
15
16
Outline
Introduction
NVIC and Interrupt Control
Interrupt Pending
Examples
Interrupt Service Routines
Interrupt Pending
The normal case
Once Interrupt Request is seen, processor puts it in
pending state even if hardware drops the request
IPS is cleared by the hardware once we jump to the ISR
17
Interrupt pending
18
19
Outline
Introduction
NVIC and Interrupt Control
Interrupt Pending
Examples
Interrupt Service Routines
20
21
22
#include "LPC17xx.h"
23
24
25
Outline
Introduction
NVIC and Interrupt Control
Interrupt Pending
Examples
Interrupt Service Routines
26
Interrupt/Exception Exits
At the end of the exception handler, an exception exit
(a.k.a interrupt return in some processors) is required to
restore the system status so that the interrupted program
can resume normal execution
There are three ways to trigger the interrupt return
sequence; all of them use the special value stored in the
LR in the beginning of the handler:
27