You are on page 1of 28

ELEC 3300

Introduction to Embedded Systems

Topic 4
Interrupt Organization
Prof. Tim Woo

ELEC 3300 : Spring 17/18 Tim Woo 1


Course Overview
Assembler

Instruction Set Architecture

Memory I/O System

Datapath & Control


Introduction to Basic Computer
Embedded Systems Structure
MCU Main Board

Digital and Analog


Interfacing USART, IEEE1394,
USB, I2C and SPI

Microcontroller Structure
A/D Port
Buffering and
Serial Port Direct Memory Access
CPU
(DMA)
External Memory Port
Memory,
Interfacing to Memory,
External Interrupt Port
Memory Timing
Interrupt and applications
External Timer Port Interfacing LCD
Organization Timer and
Counter Simple I/O Port
Motor Interfacing

In this course, STM32 is used as a driving vehicle for delivering the concepts.
To be covered In progress Done

ELEC 3300 : Spring 17/18 Tim Woo 2


Expected Outcomes
• On successful completion of this topic, you will be able to
– Compare polling I/O with interrupt-driven I/O
– Understand the timing diagram of interrupt service routine
– Evaluate several issues deal with
• Identification of which device caused the interrupt
• Nested and simultaneous interrupts
– Understand the interrupt organization in ARM micro-controller

ELEC 3300 : Spring 17/18 Tim Woo 3


A switch is connected to MCU board
Description
Abstract idea of project
(Define the functionality of the system)
Data format / representation
Programming Language
ARM
Communication Protocol
Physical connection (Pins assignment)

PA0 Hardware devices


(Microcontroller, Peripherals)

Physical Pin Signal Type Initialization Signals at


Devices Assignment (Configuration) Physical
connection
Micro Switch General Input / Output General On/Off
Purpose Input Purpose IO
& Output setting

ELEC 3300 : Spring 17/18 Tim Woo 4


Polling
• Polled I/O requires the CPU to ask a device if the device requires servicing
– For example, if the devices have changed status
– Software polls the devices to know when a device will be serviced

• Polling requires code to loop until ARM


the device is ready
– Consumes a lot of CPU cycles PA0
– Have a guaranteed delay but some
applications do not have a

Program code
predictable delay (e.g. In loading a Description

printer buffer with text, the buffer can Ask the device Abstract idea of project
(Define the functionality of the
run out before the printer is polled system)
again and thus printing stops) Data format / representation
Programming Language
Communication Protocol
Physical connection (Pins
assignment)
Hardware devices
(Microcontroller, Peripherals)

ELEC 3300 : Spring 17/18 Tim Woo 5


Writing a polling algorithm
• Initialization

Program code
• Configure a GPIO as an appropriate function
(says, input or output port) Ask the device
• Implementation
• Write a while-loop / if-then-else loop for checking
the status of the GPIO
Initialization main()
Description
{
Abstract idea of project
Configure PA0 as input port (Define the functionality of the
while() system)
Data format / representation
{
Programming Language
Check if PA0 is pressed,
Communication Protocol
if yes, …. ; break
Physical connection (Pins
if not, …. ; back to while loop assignment)
implementation } Hardware devices
(Microcontroller, Peripherals)
}

ELEC 3300 : Spring 17/18 Tim Woo 6


Polling in multiple devices
• Polled I/O requires the CPU to ask devices if the devices require servicing

Ask the devices one by one


CPU

Description
D1 D6 D7
Abstract idea of project Loop Back
(Define the functionality of the
system)
Data format / representation
Programming Language
D2 D5 D8
Communication Protocol
Physical connection (Pins
assignment)

D9
Hardware devices
(Microcontroller, Peripherals) D3 D4 Next Instruction

ELEC 3300 : Spring 17/18 Tim Woo 7


Writing a polling algorithm
• Initialization

Program code
• Configure a GPIO as an appropriate function
(says, input or output port) Ask the devices

• Implementation
• Write a while-loop / if-then-else loop for checking
the status of the GPIO
Initialization main() * remark
{ Description
Configure PA0, PA1, …., as input ports * Abstract idea of project
while() (Define the functionality of the
system)
{
Check if PA0 is pressed, Data format / representation

if yes, …. ; break Programming Language

Else Check if PA1 is pressed, Communication Protocol

if yes, …..; break Physical connection (Pins


assignment)
implementation Otherwise, …… ; back to while loop
Hardware devices
} (Microcontroller, Peripherals)
}

ELEC 3300 : Spring 17/18 Tim Woo 8


Interrupts
• Interrupt I/O allows the device to interrupt the CPU
announcing that the device requires attention
– This allows CPU to ignore devices unless they request
servicing via interrupt
– Software does not know when an interrupt will occur, ARM

and this makes it more difficult to write code


• Interrupts do not require code to loop until the device EXTI0
is ready (PA0)

– Device interrupts CPU when it needs attention


– Code can go off to do other things
Description
Abstract idea of project
(Define the functionality of the
system)
Data format / representation
Programming Language
Communication Protocol
Physical connection (Pins
assignment) Clear the interrupt flag if you have already handled it.
Hardware devices
(Microcontroller, Peripherals)

ELEC 3300 : Spring 17/18 Tim Woo 9


Interrupts
Interrupt I/O allows the device to interrupt the CPU announcing that the
device requires attention
Description
Send request to CPU Abstract idea of project
(Define the functionality of the
CPU system)
Data format / representation
Provide Interrupt Service
Programming Language
Communication Protocol

D1 D6 D7 Physical connection (Pins


assignment)
Hardware devices
(Microcontroller, Peripherals)

D2 D5 D8

D3 D4 D9
ELEC 3300 : Spring 17/18 Tim Woo 10
Timing diagram of Interrupts
• Before an Interrupt Service Routine (ISR) can do anything, it must save
away the current program’s registers (if it touches those registers)
•Pushing the PC, registers etc onto the stack
•Disable subsequent interrupts of the same
Description type from occurring. However, interrupts of a
higher priority can still occur.
Abstract idea of project
(Define the functionality of the
system)

Data format / representation


Programming Language
Communication Protocol
Physical connection (Pins
assignment)

Hardware devices
(Microcontroller, Peripherals)

•Popping the PC, registers etc onto the stack


•Enable subsequent interrupts of the same
type from occurring.

ELEC 3300 : Spring 17/18 Tim Woo 11


Writing an interrupt algorithm
• Initialization
• Select an appropriate pin for handling interrupt signal
• Write an ISR for handling this interrupt signal
• Activate ISR by setting the corresponding Interrupt Request (IRQ)
channel
Initialization main() ISR_INT0() implementation
{ {
Configure PA0 as input port. (INT0 Program code for ISR

Program code
ISR
as interrupt signal) ………
Enable the IRQ channel
Clear the interrupt pending bit
while()
}
{
Program code
………
implementation }
}

ELEC 3300 : Spring 17/18 Tim Woo 12


Interrupts: Issues to be dealt with
• Enabling/disabling interrupt (all or some)
– Can be enabled / disabled by hardware or software
– Those interrupts that can be enabled / disabled by software are called
maskable.
• E.g. Masking with logical operators such as AND, OR, etc

• Identification of which device caused the interrupt

• Handling simultaneous interrupts

• Handling nested interrupts

ELEC 3300 : Spring 17/18 Tim Woo 13


Identification of Interrupting Device
• The problem is: CPU has received an interrupt
request, but which device caused the interrupt?

• Solution: One approach is simple polling of the


status flags in each device’s interface. In
programming terms, there is a ‘skip chain’ at the
start of the ISR

• Problem with this approach is time wasted in ‘skip-


chain’ processing, especially when there are many
possible interrupting devices

ELEC 3300 : Spring 17/18 Tim Woo 14


Identification of Interrupting Device
• Instead of programmed device identification, the device supplies the CPU
with interrupt vector using an “Interrupt Acknowledge” bus cycle

• The interrupting device sends a self-identifying code back to the CPU


during the “Interrupt ACK” cycle

ELEC 3300 : Spring 17/18 Tim Woo 15


Nested and Simultaneous Interrupts
• When there is the possibility of several devices interrupting
– What should happen if a second interrupt request occurs while a previous
interrupt is being serviced?
– What should happen if two devices make interrupt requests during the same
machine cycle?
• It is often the case that one device have priority over another (e.g. real-
time clock VS printer)
• Device A should be allowed to interrupt the serving of Device B if only if
A’s priority is higher than B’s
• Similarly, if A and B interrupt simultaneously, A should be serviced first
• On the interrupt priority, there are two main approaches
– Daisy-chaining of the acknowledge line (simplest)
– Use of a specialized Priority Interrupt Controller

ELEC 3300 : Spring 17/18 Tim Woo 16


Daisy-Chaining
• When several devices are interrupting, the ACK connects only to the
highest-priority device, which itself provides a secondary ACK1 signal foe
the next device and so on

ELEC 3300 : Spring 17/18 Tim Woo 17


Priority Interrupt Controller
• In many embedded systems, there are more external sources for
interrupts than interrupt pins on the microprocessor, and therefore, it is
necessary to use an interrupt controller to provide a large number of
prioritized interrupt signals

ELEC 3300 : Spring 17/18 Tim Woo 18


Nested Interrupts
• Interrupts can occur within interrupts

ELEC 3300 : Spring 17/18 Tim Woo 19


STM32 Interrupts
• Nested vectored interrupt controller (NVIC)
• Features:
– 68 interrupt lines
– 16 programmable priority levels
– Low-latency expectation and interrupt
handling
– Power management control
– Implementation of System Control Registers
• Reference:
– Table 61 Vector table for connectivity line
devices
– Table 62 Vector table for XL-density devices

ELEC 3300 : Spring 17/18 Tim Woo 20


STM32: Interrupt Priority
• Example:
– From the Table 61 and 62, indicate the interrupt priority.
Source Type of Priority Priority
priority (Table 61) (Table 62)
EXTI Line0 interrupt (EXTI0) Settable 13 13
Flash global interrupt (FLASH) Settable 11 11
I2C1 error interrupt (I2C1_ER) Settable 39 39
UART4 global interrupt (UART4) Settable 59 59
CAN1 TX interrupts (CAN1_TX) Settable 26 -
USB high priority or CAN TX interrupts (USB_HP_CAN_TX) Settable - 26
CAN RX1 interrupt (CAN_RX1) Settable - 28
CAN1 RX1 interrupt (CAN1_RX1) Settable 28 -
USB wakeup from suspend through EXTI line interrupt (USBWakeup) Settable - 49
Timer 2 global interrupt (TIM2) Settable 35 35

* CAN1_RX and CAN1_TX in connectivity line devices; CAN_RX and CAN_TX in other devices with a single CAN interface.

ELEC 3300 : Spring 17/18 Tim Woo 21


STM32 External interrupt / event controller (EXTI)

• Features:
– Up to 20 edge detectors in connectively line devices
– Up to 19 edge detectors in other devices for general event / interrupt
requests
– Independent trigger and mask on each interrupt / event line
– Dedicated status bit for each interrupt line
– Generation of up to 20 software event / interrupt requests
– Detection of external signal with pulse width lower than APB2 clock
period.

ELEC 3300 : Spring 17/18 Tim Woo 22


STM32 External interrupt / event controller (EXTI)

ELEC 3300 : Spring 17/18 Tim Woo 23


STM32 Interrupts

• The priority of external interrupts can


According to Table 61
be done by the hardware configuration.
• Example 1: Highest Priority

– Device 1 is connected to PA1


– Device 2 is connected to PB0
Which one has a highest priority?

Lowest Priority

ELEC 3300 : Spring 17/18 Tim Woo 24


Course Overview
Assembler

Instruction Set Architecture

Memory I/O System

Datapath & Control


Introduction to Basic Computer
Embedded Systems Structure
MCU Main Board

Digital and Analog


Interfacing USART, IEEE1394,
USB, I2C and SPI

Microcontroller Structure
A/D Port
Buffering and
Serial Port Direct Memory Access
CPU
(DMA)
External Memory Port
Memory,
Interfacing to Memory,
External Interrupt Port
Memory Timing
Interrupt and applications
External Timer Port Interfacing LCD
Organization Timer and
Counter Simple I/O Port
Motor Interfacing

In this course, STM32 is used as a driving vehicle for delivering the concepts.
To be covered In progress Done

ELEC 3300 : Spring 17/18 Tim Woo 25


Reflection (Self-evaluation)
• Do you
– Describe two I/O interfacing techniques: polling I/O and interrupt-driven
I/O ?
– Distinguish the concepts and signaling in polling and interrupt-driven
I/O ?
– List the timing diagram of interrupt service routines?
– Handle several issues deal with interrupts ?
– Configure the interrupt settings in ARM micro-controller ?

ELEC 3300 : Spring 17/18 Tim Woo 26


Reflection (Self-evaluation)
• Challenges:
– Do you know which pins of STM 32 are already configured for
conducting the laboratory experiment 2?

Hints:
– The hardware devices: I/O ports, on-board switches, LEDs
– Communication protocols: polling, interrupt

ELEC 3300 : Spring 17/18 Tim Woo 27


Class activity
• Comment the input detection algorithm (polling or interrupt) of
following projects:
– Star Trek-style Smart Glasses
– Connect 4 with laser input
– Electronic Guitar
– Spider bot
– Robotic Arm

ELEC 3300 : Spring 17/18 Tim Woo 28

You might also like