SlideShare a Scribd company logo
1 of 34
1
Digital Systems and Microprocessor Design
(H7068)
Daniel Roggen
d.roggen@sussex.ac.uk
10.2. Interrupts
2
Content
• Summary: discontinuities in program flow
– Jumps
– Reset
• Interrupts: changing the program flow upon
hardware event
• External interrupts
• Internal interrupts
3
Program flow
PC Adr Inst
-> 00 mov ra,42
02 mov rb,3
04 add ra,rb
06 cmp ra,70
08 ja 0Ch
0A jmp 04
0C ...
0E ...
4
Program flow
PC Adr Inst
00 mov ra,42
-> 02 mov rb,3
04 add ra,rb
06 cmp ra,70
08 ja 0Ch
0A jmp 04
0C ...
0E ...
5
Program flow
PC Adr Inst
00 mov ra,42
02 mov rb,3
-> 04 add ra,rb
06 cmp ra,70
08 ja 0Ch
0A jmp 04
0C ...
0E ...
6
Program flow
PC Adr Inst
00 mov ra,42
02 mov rb,3
04 add ra,rb
-> 06 cmp ra,70
08 ja 0Ch
0A jmp 04
0C ...
0E ...
Under “normal”
circumstances PC is
incremented to point to the
next instruction (after each
instruction / clock cycle,
depending on the
implementation)
In the Educational
Processor PC is
incremented by 1 in the
fetchh and fetchl cycles
7
Program flow
PC Adr Inst
00 mov ra,42
02 mov rb,3
04 add ra,rb
06 cmp ra,70
-> 08 ja 0Ch
0A jmp 04
0C ...
0E ...
PC is not always
incremented to point to
the next instruction:
• Conditional jumps
• Unconditional jumps
Here the conditional
jump is not taken
8
Program flow
PC Adr Inst
00 mov ra,42
02 mov rb,3
04 add ra,rb
06 cmp ra,70
08 ja 0Ch
-> 0A jmp 04
0C ...
0E ...
This unconditional jump
is taken
PC is not always
incremented to point to
the next instruction:
• Conditional jumps
• Unconditional jumps
9
Program flow
PC Adr Inst
00 mov ra,42
02 mov rb,3
-> 04 add ra,rb
06 cmp ra,70
08 ja 0Ch
0A jmp 04
0C ...
0E ...
Habitual program flow
continues
jm
p
10
Program flow
PC Adr Inst
00 mov ra,42
02 mov rb,3
04 add ra,rb
-> 06 cmp ra,70
08 ja 0Ch
0A jmp 04
0C ...
0E ...
11
Program flow
PC Adr Inst
00 mov ra,42
02 mov rb,3
04 add ra,rb
06 cmp ra,70
-> 08 ja 0Ch
0A jmp 04
0C ...
0E ...
clk rst
Reset creates a discontinuity
in the program flow: PC set
to 0
Really: more than a
discontinuity as all registers
are cleared – but
fundamentally it is a
discontinuity
12
Program flow
PC Adr Inst
00 mov ra,42
02 mov rb,3
04 add ra,rb
06 cmp ra,70
08 ja 0Ch
-> 0A jmp 04
0C ...
0E ...
clk rst
Let’s reset the processor!
13
Program flow
PC Adr Inst
-> 00 mov ra,42
02 mov rb,3
04 add ra,rb
06 cmp ra,70
08 ja 0Ch
0A jmp 04
0C ...
0E ...
clk rst
Processor after reset:
PC=0
rst
14
From reset to interrupts
• Reset is a an external signal that changes the flow of
execution
• Interrupts are another mechanism by which an external
signal can change the execution flow
• Interrupts exist on all commercial processors and
microcontrollers!
• Note: there are no interrupts in the educational
processor...
clk rst
15
Motivation for interrupts
• Let’s say a program must wait until a pin goes high on
the external interface….
– for example to count how often a pin is toggled
– Or to implement a communication protocol in software (e.g. I2C,
SPI, etc)
• How to implement this in a program?
clk rst
Ext interface
16
Polling
• Implementation by polling: continuously reading the pin
to detect changes
mov ra,0 // number of toggles
testbit:
in rb // read ext input
and rb,1 // check bit 0
cmp rb,1 // bit 0 set?
jne testbit //
add ra,1 // increment counter
// instead of increment we
// could do more complex stuff
waitclr: // now wait until clear
in rb
and rb,1
cmp rb,0 // bit clear?
jne waitclr // no, loop until clear
jmp testbit // yes, go back to test bit set
17
Polling
• Latency?
– 7 instructions to react to rising edge (worst case)
– 8 instructions to react to falling edge (worst case)
mov ra,0 // number of toggles
testbit:
in rb // read ext input
and rb,1 // check bit 0
cmp rb,1 // bit 0 set?
jne testbit //
add ra,1 // increment counter
// instead of increment we
// could do more complex stuff
waitclr: // now wait until clear
in rb
and rb,1
cmp rb,0 // bit clear?
jne waitclr // no, loop until clear
jmp testbit // yes, go back to test bit set
18
Polling
• Latency?
– 7 instructions to react to rising edge
– 8 instructions to react to falling edge
• Total: 15*3=45 processor clock cycles to detect one
cycle on the external input!
• If the external signal toggles with a period smaller than
45 clock cycles then the processor cannot count the
number of toggles!
45clk
Ext input:
19
Polling
• Polling is usually a very slow solution (compared to a
hardware approach) to the problem of detecting changes
on input pins
– 1/45th
speed of processor in this example! (100MHz->2MHz)
– (although some specific use cases are suitable for polling!)
• During polling the processor cannot do anything else!
• Not suitable for multitasking
20
Solution 1: hardware
• Hardware counter (outside of processor)
• Hardware interface: see previous lectures
– There are hardware interfaces dedicated to "count" events in
many microcontrollers!
• (however that's not the point of this lecture)
21
Solution 2: external interrupt
• An external interrupt is a condition on a external pin that
triggers an interruption of the normal program flow
• Several conditions can trigger ints (usually configurable):
– Rising edge
– Falling edge
– Any edge
– Level-triggered
Ext interface
clk rst
pin that generates an interrupt
22
External interrupts
• External condition interrupts program flow
• PC set to jump to an interrupt vector
• Interrupt vector: piece of code that will handle
the interrupt (do something in reaction to it)
• There can be multiple interrupts!
– E.g. one per pin
FLASH
RAM
Int vect 1
Int vect 2
23
External interrupts
• The following happens during an interrupt:
• The processor keeps a return address:
– Address of PC before the interrupt
• PC set to the interrupt vector (i.e. jump to IV)
• The processor executes the instructions in the
interrupt vector
• Interrupt return instruction (RETI)
– Indicates the end of the interrupt routine
– The processor returns to the PC value before the
interrupt (return address)
FLASH
RAM
Int vect 1
Int vect 2
24
Interrupt vector table
• Processor jumps to a fixed location! (interrupt vector)
– Typically at the start or end of memory
• Interrupt vector table (IVT): with multiple interrupts, all
interrupt vectors follow each other
• Each entry is one instruction wide
• Reset can sometimes be seen as an entry in the IVT
Adr What
----- ------
00-01 First instruction on reset
02-03 Int0 (First instruction of Int0)
04-05 Int1 (First instruction of Int1)
...
0A-0B First "normal" program instruction
25
Interrupt vector table
• The IVT holds only one instruction per interrupt!
– How to have an interrupt routine of more than one instruction??
• A jump (one instruction) is stored in the IVT
• This allows to program the location of interrupt routine
– The programmer can decide where to place the interrupt routine!
• The program continues until the RETI instruction
Adr What
----- ------
00-01 First instruction on reset
02-03 Int0 (First instruction of Int0)
04-05 Int1 (First instruction of Int1)
...
0A-0B First "normal" program instruction
26
IVT example
Adr What
----- ------
00-01 jmp 20
02-03 jmp 80
04-05 jmp A0
20-21 First program instruction
.....
78-79 Last possible program instruction
80-81 First instruction for Int0
.....
A0-A1 First instruction for Int1
.....
27
Using interrupt to count toggles
• Assumption: int0 is called on rising edge of a pin
Adr
00 jmp 10h
02 jmp 20h
10 mov ra,0h // number of toggles
12 ... // do
14 ... // something
16 ... // continuously
18 jmp 12h // here
20 add ra,1h // increment counter
22 reti // interrupt return
28
Using interrupt to count toggles
• Latency?
– 1 instruction to go to interrupt vector
– 1 instruction to return from interrupt vector
Adr
00 jmp 10h
02 jmp 20h
10 mov ra,0h // number of toggles
12 ... // do
14 ... // something
16 ... // continuously
18 jmp 12h // here
20 add ra,1h // increment counter
22 reti // interrupt return
29
External interrupts
• External interrupts are a very fast approach to react to
external events!
– 2 instruction latency instead of 15 -> 7.5x speedup!
• Interrupts permit the processor to execute a main task
and occasionally process "urgent" events
• Processors have an "interrupt pin" that can be used by
peripherals (I/O interfaces) to trigger interrupts
– Often used in microcontrollers
– E.g. Interrupt once byte is sent over I2C
• Commonly used for:
– communication
– storage devices
– user interaction
– sensor sampling
• Foundation of multitasking
30
comp_ip: entity work.dffre generic map(N=>N) port
map(clk=>clk,rst=>rst,en=>'1',d=>ipnext,q=>ip);
ipnext <= ip+1 when fetch='1' else
ip when jump='0' else
jumpip;
• Educational processor has no interrupts!
– ip incremented in the fetchh and fetchl cycles
– In exec cycle ip is unchanged if there is no jump,
– or ip is set to the jump address if there is jump
• unconditional jump
• conditional jump with a valid jump condition
Possible Implementation
31
comp_ip: entity work.dffre generic map(N=>N) port
map(clk=>clk,rst=>rst,en=>'1',d=>ipnext,q=>ip);
ipnext <= ip+1 when fetch='1' else
ip when jump='0' and int ='0' else
iv when int='1' else
jumpip;
• Adding an interrupt:
– Implemented in the same way as a jump
– int indicates an interrupt: e.g. can be level of a signal of
the external input interface
– iv is the address of the interrupt vector (e.g. "02" in the
previous example)
Possible Implementation
32
• Additionally (not shown here):
– Keep the return address (PC before modification stored
in a register or memory
– Implement the RETI instruction (e.g. using a spare
opcode)
Possible Implementation
33
Internal interrupts
• External interrupts react to external events (on pins)
• Internal interrupts react to processor events
• Common processor events:
– Division by zero / invalid math operation
– Invalid opcode
– Data alignment check
– etc
• For example, "invalid opcode" could be used to emulate
new opcodes on an older processor!
34
Summary
• Interrupts change the control flow until a RETI instruction
• Multiple interrupts can placed in programmer-defined
memory location using the interrupt vector table
• External interrupts allow very fast reaction to external
events while allowing multitasking!
• External interrupts include pin change interrupts and
peripheral interrupts
• Processors have internal interrupts to indicate issues

More Related Content

What's hot

Handling Interrupts in Microchip MCUs
Handling Interrupts in Microchip MCUsHandling Interrupts in Microchip MCUs
Handling Interrupts in Microchip MCUsCorrado Santoro
 
Handling Asynchronous Events in MCUs
Handling Asynchronous Events in MCUsHandling Asynchronous Events in MCUs
Handling Asynchronous Events in MCUsCorrado Santoro
 
Assembly programming II
Assembly programming IIAssembly programming II
Assembly programming IIOmar Sanchez
 
selected input/output - sensors and actuators
selected input/output - sensors and actuatorsselected input/output - sensors and actuators
selected input/output - sensors and actuatorsEueung Mulyana
 
Connectivity for Local Sensors and Actuators Using nRF24L01+
Connectivity for Local Sensors and Actuators Using nRF24L01+Connectivity for Local Sensors and Actuators Using nRF24L01+
Connectivity for Local Sensors and Actuators Using nRF24L01+Eueung Mulyana
 
Functions for Nano 5 Card
Functions for Nano 5 CardFunctions for Nano 5 Card
Functions for Nano 5 CardOmar Sanchez
 
[DCG 25] Александр Большев - Never Trust Your Inputs or How To Fool an ADC
[DCG 25] Александр Большев - Never Trust Your Inputs or How To Fool an ADC [DCG 25] Александр Большев - Never Trust Your Inputs or How To Fool an ADC
[DCG 25] Александр Большев - Never Trust Your Inputs or How To Fool an ADC DefconRussia
 
Tools for Practical Attacks on Analog-to-Digital Conversion
Tools for Practical Attacks on Analog-to-Digital ConversionTools for Practical Attacks on Analog-to-Digital Conversion
Tools for Practical Attacks on Analog-to-Digital ConversionAlexander Bolshev
 
Using Timer2 in Microchip MCUs
Using Timer2 in Microchip MCUsUsing Timer2 in Microchip MCUs
Using Timer2 in Microchip MCUsCorrado Santoro
 

What's hot (20)

Handling Interrupts in Microchip MCUs
Handling Interrupts in Microchip MCUsHandling Interrupts in Microchip MCUs
Handling Interrupts in Microchip MCUs
 
Using Timer1 and CCP
Using Timer1 and CCPUsing Timer1 and CCP
Using Timer1 and CCP
 
Handling Asynchronous Events in MCUs
Handling Asynchronous Events in MCUsHandling Asynchronous Events in MCUs
Handling Asynchronous Events in MCUs
 
Lecture7
Lecture7Lecture7
Lecture7
 
Class8
Class8Class8
Class8
 
Assembly programming II
Assembly programming IIAssembly programming II
Assembly programming II
 
Uart
UartUart
Uart
 
selected input/output - sensors and actuators
selected input/output - sensors and actuatorsselected input/output - sensors and actuators
selected input/output - sensors and actuators
 
microprocessors
microprocessorsmicroprocessors
microprocessors
 
Connectivity for Local Sensors and Actuators Using nRF24L01+
Connectivity for Local Sensors and Actuators Using nRF24L01+Connectivity for Local Sensors and Actuators Using nRF24L01+
Connectivity for Local Sensors and Actuators Using nRF24L01+
 
Functions for Nano 5 Card
Functions for Nano 5 CardFunctions for Nano 5 Card
Functions for Nano 5 Card
 
[DCG 25] Александр Большев - Never Trust Your Inputs or How To Fool an ADC
[DCG 25] Александр Большев - Never Trust Your Inputs or How To Fool an ADC [DCG 25] Александр Большев - Never Trust Your Inputs or How To Fool an ADC
[DCG 25] Александр Большев - Never Trust Your Inputs or How To Fool an ADC
 
Showcase
ShowcaseShowcase
Showcase
 
Tools for Practical Attacks on Analog-to-Digital Conversion
Tools for Practical Attacks on Analog-to-Digital ConversionTools for Practical Attacks on Analog-to-Digital Conversion
Tools for Practical Attacks on Analog-to-Digital Conversion
 
8051 Inturrpt
8051 Inturrpt8051 Inturrpt
8051 Inturrpt
 
Jp
Jp Jp
Jp
 
Interrupt
InterruptInterrupt
Interrupt
 
8051 interrupts
8051 interrupts8051 interrupts
8051 interrupts
 
Using Timer2 in Microchip MCUs
Using Timer2 in Microchip MCUsUsing Timer2 in Microchip MCUs
Using Timer2 in Microchip MCUs
 
8051 Timers
8051 Timers8051 Timers
8051 Timers
 

Similar to W10: Interrupts

Embedded system - Introduction To ARM Exception Handling and Software Interru...
Embedded system - Introduction To ARM Exception Handling andSoftware Interru...Embedded system - Introduction To ARM Exception Handling andSoftware Interru...
Embedded system - Introduction To ARM Exception Handling and Software Interru...Vibrant Technologies & Computers
 
Computer Organization
Computer OrganizationComputer Organization
Computer OrganizationHaripritha
 
ESD_05_ARM_Instructions set for preparation
ESD_05_ARM_Instructions set for preparationESD_05_ARM_Instructions set for preparation
ESD_05_ARM_Instructions set for preparationssuser026e94
 
Best-embedded-corporate-training-in-mumbai
Best-embedded-corporate-training-in-mumbaiBest-embedded-corporate-training-in-mumbai
Best-embedded-corporate-training-in-mumbaiUnmesh Baile
 
W8_2: Inside the UoS Educational Processor
W8_2: Inside the UoS Educational ProcessorW8_2: Inside the UoS Educational Processor
W8_2: Inside the UoS Educational ProcessorDaniel Roggen
 
Pipeline stalling in vhdl
Pipeline stalling in vhdlPipeline stalling in vhdl
Pipeline stalling in vhdlSai Malleswar
 
UNIT 3 - General Purpose Processors
UNIT 3 - General Purpose ProcessorsUNIT 3 - General Purpose Processors
UNIT 3 - General Purpose ProcessorsButtaRajasekhar2
 
W8_1: Intro to UoS Educational Processor
W8_1: Intro to UoS Educational ProcessorW8_1: Intro to UoS Educational Processor
W8_1: Intro to UoS Educational ProcessorDaniel Roggen
 
PROGRAMMABLE LOGIC CONTROLLERS
PROGRAMMABLELOGIC CONTROLLERSPROGRAMMABLELOGIC CONTROLLERS
PROGRAMMABLE LOGIC CONTROLLERSDnr Creatives
 
Microcontroller
MicrocontrollerMicrocontroller
MicrocontrollerSpitiq
 
Let's write a Debugger!
Let's write a Debugger!Let's write a Debugger!
Let's write a Debugger!Levente Kurusa
 
Using ARM Dev.Board in physical experimental instruments
Using ARM Dev.Board in physical experimental instrumentsUsing ARM Dev.Board in physical experimental instruments
Using ARM Dev.Board in physical experimental instrumentsa_n0v
 

Similar to W10: Interrupts (20)

lesson01.ppt
lesson01.pptlesson01.ppt
lesson01.ppt
 
Embedded system - Introduction To ARM Exception Handling and Software Interru...
Embedded system - Introduction To ARM Exception Handling andSoftware Interru...Embedded system - Introduction To ARM Exception Handling andSoftware Interru...
Embedded system - Introduction To ARM Exception Handling and Software Interru...
 
Interrupts.ppt
Interrupts.pptInterrupts.ppt
Interrupts.ppt
 
Computer Organization
Computer OrganizationComputer Organization
Computer Organization
 
ESD_05_ARM_Instructions set for preparation
ESD_05_ARM_Instructions set for preparationESD_05_ARM_Instructions set for preparation
ESD_05_ARM_Instructions set for preparation
 
chapter 4
chapter 4chapter 4
chapter 4
 
ARMInst.ppt
ARMInst.pptARMInst.ppt
ARMInst.ppt
 
ARMInst.ppt
ARMInst.pptARMInst.ppt
ARMInst.ppt
 
Best-embedded-corporate-training-in-mumbai
Best-embedded-corporate-training-in-mumbaiBest-embedded-corporate-training-in-mumbai
Best-embedded-corporate-training-in-mumbai
 
W8: Laboratory 1
W8: Laboratory 1W8: Laboratory 1
W8: Laboratory 1
 
Microcontroller part 2
Microcontroller part 2Microcontroller part 2
Microcontroller part 2
 
W8_2: Inside the UoS Educational Processor
W8_2: Inside the UoS Educational ProcessorW8_2: Inside the UoS Educational Processor
W8_2: Inside the UoS Educational Processor
 
Pipeline stalling in vhdl
Pipeline stalling in vhdlPipeline stalling in vhdl
Pipeline stalling in vhdl
 
UNIT 3 - General Purpose Processors
UNIT 3 - General Purpose ProcessorsUNIT 3 - General Purpose Processors
UNIT 3 - General Purpose Processors
 
W8_1: Intro to UoS Educational Processor
W8_1: Intro to UoS Educational ProcessorW8_1: Intro to UoS Educational Processor
W8_1: Intro to UoS Educational Processor
 
PROGRAMMABLE LOGIC CONTROLLERS
PROGRAMMABLELOGIC CONTROLLERSPROGRAMMABLELOGIC CONTROLLERS
PROGRAMMABLE LOGIC CONTROLLERS
 
Microcontroller
MicrocontrollerMicrocontroller
Microcontroller
 
Let's write a Debugger!
Let's write a Debugger!Let's write a Debugger!
Let's write a Debugger!
 
Instruction types
Instruction typesInstruction types
Instruction types
 
Using ARM Dev.Board in physical experimental instruments
Using ARM Dev.Board in physical experimental instrumentsUsing ARM Dev.Board in physical experimental instruments
Using ARM Dev.Board in physical experimental instruments
 

More from Daniel Roggen

Embedded Sensing and Computational Behaviour Science
Embedded Sensing and Computational Behaviour ScienceEmbedded Sensing and Computational Behaviour Science
Embedded Sensing and Computational Behaviour ScienceDaniel Roggen
 
W9_3: UoS Educational Processor: Assembler Memory Access
W9_3: UoS Educational Processor: Assembler Memory AccessW9_3: UoS Educational Processor: Assembler Memory Access
W9_3: UoS Educational Processor: Assembler Memory AccessDaniel Roggen
 
W9_2: Jumps and loops
W9_2: Jumps and loopsW9_2: Jumps and loops
W9_2: Jumps and loopsDaniel Roggen
 
Wearable technologies: what's brewing in the lab?
Wearable technologies: what's brewing in the lab?Wearable technologies: what's brewing in the lab?
Wearable technologies: what's brewing in the lab?Daniel Roggen
 
Wearable Computing - Part IV: Ensemble classifiers & Insight into ongoing res...
Wearable Computing - Part IV: Ensemble classifiers & Insight into ongoing res...Wearable Computing - Part IV: Ensemble classifiers & Insight into ongoing res...
Wearable Computing - Part IV: Ensemble classifiers & Insight into ongoing res...Daniel Roggen
 
Wearable Computing - Part III: The Activity Recognition Chain (ARC)
Wearable Computing - Part III: The Activity Recognition Chain (ARC)Wearable Computing - Part III: The Activity Recognition Chain (ARC)
Wearable Computing - Part III: The Activity Recognition Chain (ARC)Daniel Roggen
 
Wearable Computing - Part II: Sensors
Wearable Computing - Part II: SensorsWearable Computing - Part II: Sensors
Wearable Computing - Part II: SensorsDaniel Roggen
 
Wearable Computing - Part I: What is Wearable Computing?
Wearable Computing - Part I: What is Wearable Computing?Wearable Computing - Part I: What is Wearable Computing?
Wearable Computing - Part I: What is Wearable Computing?Daniel Roggen
 

More from Daniel Roggen (10)

Embedded Sensing and Computational Behaviour Science
Embedded Sensing and Computational Behaviour ScienceEmbedded Sensing and Computational Behaviour Science
Embedded Sensing and Computational Behaviour Science
 
W10: Laboratory
W10: LaboratoryW10: Laboratory
W10: Laboratory
 
W9: Laboratory 2
W9: Laboratory 2W9: Laboratory 2
W9: Laboratory 2
 
W9_3: UoS Educational Processor: Assembler Memory Access
W9_3: UoS Educational Processor: Assembler Memory AccessW9_3: UoS Educational Processor: Assembler Memory Access
W9_3: UoS Educational Processor: Assembler Memory Access
 
W9_2: Jumps and loops
W9_2: Jumps and loopsW9_2: Jumps and loops
W9_2: Jumps and loops
 
Wearable technologies: what's brewing in the lab?
Wearable technologies: what's brewing in the lab?Wearable technologies: what's brewing in the lab?
Wearable technologies: what's brewing in the lab?
 
Wearable Computing - Part IV: Ensemble classifiers & Insight into ongoing res...
Wearable Computing - Part IV: Ensemble classifiers & Insight into ongoing res...Wearable Computing - Part IV: Ensemble classifiers & Insight into ongoing res...
Wearable Computing - Part IV: Ensemble classifiers & Insight into ongoing res...
 
Wearable Computing - Part III: The Activity Recognition Chain (ARC)
Wearable Computing - Part III: The Activity Recognition Chain (ARC)Wearable Computing - Part III: The Activity Recognition Chain (ARC)
Wearable Computing - Part III: The Activity Recognition Chain (ARC)
 
Wearable Computing - Part II: Sensors
Wearable Computing - Part II: SensorsWearable Computing - Part II: Sensors
Wearable Computing - Part II: Sensors
 
Wearable Computing - Part I: What is Wearable Computing?
Wearable Computing - Part I: What is Wearable Computing?Wearable Computing - Part I: What is Wearable Computing?
Wearable Computing - Part I: What is Wearable Computing?
 

Recently uploaded

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 

Recently uploaded (20)

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 

W10: Interrupts

  • 1. 1 Digital Systems and Microprocessor Design (H7068) Daniel Roggen d.roggen@sussex.ac.uk 10.2. Interrupts
  • 2. 2 Content • Summary: discontinuities in program flow – Jumps – Reset • Interrupts: changing the program flow upon hardware event • External interrupts • Internal interrupts
  • 3. 3 Program flow PC Adr Inst -> 00 mov ra,42 02 mov rb,3 04 add ra,rb 06 cmp ra,70 08 ja 0Ch 0A jmp 04 0C ... 0E ...
  • 4. 4 Program flow PC Adr Inst 00 mov ra,42 -> 02 mov rb,3 04 add ra,rb 06 cmp ra,70 08 ja 0Ch 0A jmp 04 0C ... 0E ...
  • 5. 5 Program flow PC Adr Inst 00 mov ra,42 02 mov rb,3 -> 04 add ra,rb 06 cmp ra,70 08 ja 0Ch 0A jmp 04 0C ... 0E ...
  • 6. 6 Program flow PC Adr Inst 00 mov ra,42 02 mov rb,3 04 add ra,rb -> 06 cmp ra,70 08 ja 0Ch 0A jmp 04 0C ... 0E ... Under “normal” circumstances PC is incremented to point to the next instruction (after each instruction / clock cycle, depending on the implementation) In the Educational Processor PC is incremented by 1 in the fetchh and fetchl cycles
  • 7. 7 Program flow PC Adr Inst 00 mov ra,42 02 mov rb,3 04 add ra,rb 06 cmp ra,70 -> 08 ja 0Ch 0A jmp 04 0C ... 0E ... PC is not always incremented to point to the next instruction: • Conditional jumps • Unconditional jumps Here the conditional jump is not taken
  • 8. 8 Program flow PC Adr Inst 00 mov ra,42 02 mov rb,3 04 add ra,rb 06 cmp ra,70 08 ja 0Ch -> 0A jmp 04 0C ... 0E ... This unconditional jump is taken PC is not always incremented to point to the next instruction: • Conditional jumps • Unconditional jumps
  • 9. 9 Program flow PC Adr Inst 00 mov ra,42 02 mov rb,3 -> 04 add ra,rb 06 cmp ra,70 08 ja 0Ch 0A jmp 04 0C ... 0E ... Habitual program flow continues jm p
  • 10. 10 Program flow PC Adr Inst 00 mov ra,42 02 mov rb,3 04 add ra,rb -> 06 cmp ra,70 08 ja 0Ch 0A jmp 04 0C ... 0E ...
  • 11. 11 Program flow PC Adr Inst 00 mov ra,42 02 mov rb,3 04 add ra,rb 06 cmp ra,70 -> 08 ja 0Ch 0A jmp 04 0C ... 0E ... clk rst Reset creates a discontinuity in the program flow: PC set to 0 Really: more than a discontinuity as all registers are cleared – but fundamentally it is a discontinuity
  • 12. 12 Program flow PC Adr Inst 00 mov ra,42 02 mov rb,3 04 add ra,rb 06 cmp ra,70 08 ja 0Ch -> 0A jmp 04 0C ... 0E ... clk rst Let’s reset the processor!
  • 13. 13 Program flow PC Adr Inst -> 00 mov ra,42 02 mov rb,3 04 add ra,rb 06 cmp ra,70 08 ja 0Ch 0A jmp 04 0C ... 0E ... clk rst Processor after reset: PC=0 rst
  • 14. 14 From reset to interrupts • Reset is a an external signal that changes the flow of execution • Interrupts are another mechanism by which an external signal can change the execution flow • Interrupts exist on all commercial processors and microcontrollers! • Note: there are no interrupts in the educational processor... clk rst
  • 15. 15 Motivation for interrupts • Let’s say a program must wait until a pin goes high on the external interface…. – for example to count how often a pin is toggled – Or to implement a communication protocol in software (e.g. I2C, SPI, etc) • How to implement this in a program? clk rst Ext interface
  • 16. 16 Polling • Implementation by polling: continuously reading the pin to detect changes mov ra,0 // number of toggles testbit: in rb // read ext input and rb,1 // check bit 0 cmp rb,1 // bit 0 set? jne testbit // add ra,1 // increment counter // instead of increment we // could do more complex stuff waitclr: // now wait until clear in rb and rb,1 cmp rb,0 // bit clear? jne waitclr // no, loop until clear jmp testbit // yes, go back to test bit set
  • 17. 17 Polling • Latency? – 7 instructions to react to rising edge (worst case) – 8 instructions to react to falling edge (worst case) mov ra,0 // number of toggles testbit: in rb // read ext input and rb,1 // check bit 0 cmp rb,1 // bit 0 set? jne testbit // add ra,1 // increment counter // instead of increment we // could do more complex stuff waitclr: // now wait until clear in rb and rb,1 cmp rb,0 // bit clear? jne waitclr // no, loop until clear jmp testbit // yes, go back to test bit set
  • 18. 18 Polling • Latency? – 7 instructions to react to rising edge – 8 instructions to react to falling edge • Total: 15*3=45 processor clock cycles to detect one cycle on the external input! • If the external signal toggles with a period smaller than 45 clock cycles then the processor cannot count the number of toggles! 45clk Ext input:
  • 19. 19 Polling • Polling is usually a very slow solution (compared to a hardware approach) to the problem of detecting changes on input pins – 1/45th speed of processor in this example! (100MHz->2MHz) – (although some specific use cases are suitable for polling!) • During polling the processor cannot do anything else! • Not suitable for multitasking
  • 20. 20 Solution 1: hardware • Hardware counter (outside of processor) • Hardware interface: see previous lectures – There are hardware interfaces dedicated to "count" events in many microcontrollers! • (however that's not the point of this lecture)
  • 21. 21 Solution 2: external interrupt • An external interrupt is a condition on a external pin that triggers an interruption of the normal program flow • Several conditions can trigger ints (usually configurable): – Rising edge – Falling edge – Any edge – Level-triggered Ext interface clk rst pin that generates an interrupt
  • 22. 22 External interrupts • External condition interrupts program flow • PC set to jump to an interrupt vector • Interrupt vector: piece of code that will handle the interrupt (do something in reaction to it) • There can be multiple interrupts! – E.g. one per pin FLASH RAM Int vect 1 Int vect 2
  • 23. 23 External interrupts • The following happens during an interrupt: • The processor keeps a return address: – Address of PC before the interrupt • PC set to the interrupt vector (i.e. jump to IV) • The processor executes the instructions in the interrupt vector • Interrupt return instruction (RETI) – Indicates the end of the interrupt routine – The processor returns to the PC value before the interrupt (return address) FLASH RAM Int vect 1 Int vect 2
  • 24. 24 Interrupt vector table • Processor jumps to a fixed location! (interrupt vector) – Typically at the start or end of memory • Interrupt vector table (IVT): with multiple interrupts, all interrupt vectors follow each other • Each entry is one instruction wide • Reset can sometimes be seen as an entry in the IVT Adr What ----- ------ 00-01 First instruction on reset 02-03 Int0 (First instruction of Int0) 04-05 Int1 (First instruction of Int1) ... 0A-0B First "normal" program instruction
  • 25. 25 Interrupt vector table • The IVT holds only one instruction per interrupt! – How to have an interrupt routine of more than one instruction?? • A jump (one instruction) is stored in the IVT • This allows to program the location of interrupt routine – The programmer can decide where to place the interrupt routine! • The program continues until the RETI instruction Adr What ----- ------ 00-01 First instruction on reset 02-03 Int0 (First instruction of Int0) 04-05 Int1 (First instruction of Int1) ... 0A-0B First "normal" program instruction
  • 26. 26 IVT example Adr What ----- ------ 00-01 jmp 20 02-03 jmp 80 04-05 jmp A0 20-21 First program instruction ..... 78-79 Last possible program instruction 80-81 First instruction for Int0 ..... A0-A1 First instruction for Int1 .....
  • 27. 27 Using interrupt to count toggles • Assumption: int0 is called on rising edge of a pin Adr 00 jmp 10h 02 jmp 20h 10 mov ra,0h // number of toggles 12 ... // do 14 ... // something 16 ... // continuously 18 jmp 12h // here 20 add ra,1h // increment counter 22 reti // interrupt return
  • 28. 28 Using interrupt to count toggles • Latency? – 1 instruction to go to interrupt vector – 1 instruction to return from interrupt vector Adr 00 jmp 10h 02 jmp 20h 10 mov ra,0h // number of toggles 12 ... // do 14 ... // something 16 ... // continuously 18 jmp 12h // here 20 add ra,1h // increment counter 22 reti // interrupt return
  • 29. 29 External interrupts • External interrupts are a very fast approach to react to external events! – 2 instruction latency instead of 15 -> 7.5x speedup! • Interrupts permit the processor to execute a main task and occasionally process "urgent" events • Processors have an "interrupt pin" that can be used by peripherals (I/O interfaces) to trigger interrupts – Often used in microcontrollers – E.g. Interrupt once byte is sent over I2C • Commonly used for: – communication – storage devices – user interaction – sensor sampling • Foundation of multitasking
  • 30. 30 comp_ip: entity work.dffre generic map(N=>N) port map(clk=>clk,rst=>rst,en=>'1',d=>ipnext,q=>ip); ipnext <= ip+1 when fetch='1' else ip when jump='0' else jumpip; • Educational processor has no interrupts! – ip incremented in the fetchh and fetchl cycles – In exec cycle ip is unchanged if there is no jump, – or ip is set to the jump address if there is jump • unconditional jump • conditional jump with a valid jump condition Possible Implementation
  • 31. 31 comp_ip: entity work.dffre generic map(N=>N) port map(clk=>clk,rst=>rst,en=>'1',d=>ipnext,q=>ip); ipnext <= ip+1 when fetch='1' else ip when jump='0' and int ='0' else iv when int='1' else jumpip; • Adding an interrupt: – Implemented in the same way as a jump – int indicates an interrupt: e.g. can be level of a signal of the external input interface – iv is the address of the interrupt vector (e.g. "02" in the previous example) Possible Implementation
  • 32. 32 • Additionally (not shown here): – Keep the return address (PC before modification stored in a register or memory – Implement the RETI instruction (e.g. using a spare opcode) Possible Implementation
  • 33. 33 Internal interrupts • External interrupts react to external events (on pins) • Internal interrupts react to processor events • Common processor events: – Division by zero / invalid math operation – Invalid opcode – Data alignment check – etc • For example, "invalid opcode" could be used to emulate new opcodes on an older processor!
  • 34. 34 Summary • Interrupts change the control flow until a RETI instruction • Multiple interrupts can placed in programmer-defined memory location using the interrupt vector table • External interrupts allow very fast reaction to external events while allowing multitasking! • External interrupts include pin change interrupts and peripheral interrupts • Processors have internal interrupts to indicate issues