Interrupt Basics Handout-1
Interrupt Basics Handout-1
Interrupt Basics
Todays Goals
An event that requires the CPU to stop the current program execution and
perform some service related to the event.
A simple analogy
Reading a book and the phone rings
Stop reading and get the phone
Talk..
Return to the book where one read and resume to read
The phone call is an interrupt and the talk is an interrupt service routine
(ISR) or an interrupt handler.
Interrupt Service Routine (ISR)
Interrupt handler
http://www.ece.unm.edu/~jimp/310/slides/8086_interrupts-9.gif
http://support.novell.com/techcenter/articles/img/ana1995050101.gif
Polling vs. Interrupt-driven
Polling ;***************************************************
; Purpose:
; 7 segment LEDs and SW test
Actively samples the status ; History:
; 2/21/2010: Prof. Kwon created
of an external devices. ;***************************************************
#INCLUDE d12plus.inc
;----------------------------------
Interrupt-driven programs ; init pattern
MOVB #%00000001, SEGPATTN
The main loop does not need BRSET PSHBUTTN, BUTT3, NOTPUSH
LSL PORTB
BNE PUSHED
to pay attention to the switch. MOVB #%00000001,PORTB
PUSHED: BRCLR PSHBUTTN, BUTT3, PUSHED
JSR DELAY1MS
BRCLR PSHBUTTN, BUTT3, NOTPUSH
BRA NOTPUSH
Why are interrupts used?
Coordinate I/O activities and prevent the CPU from being tied up during
data transfer process.
The CPU needs to know if the I/O is ready before it can proceed. Without the
interrupt capability, the CPU needs to check the status of the I/O device
continuously.
Cause:
An event which necessitates the interrupt.
Configuration:
Most devices have some options, such as time interval, effects on I/O, etc.
Interrupt Vector and Interrupt Vector Table
http://class.ee.iastate.edu/cpre211/lectures/interrupt_works_files/image025.gif
Interrupt Enable Bit
The enable bit is set to 0, if the microprocessor should ignore the devices
interrupt request.
Device 0
Device 1
Microprocessor
Device 2
Enable bits
Interrupt Flag Bit
The device will be set its flag to 1 when it believes that it needs to be
serviced.
Ex) A push button (remember Port H?) is being pressed. Then, the interrupt
flag bit of the push button will be set to 1.
The microprocessor can read the status of buttons using interrupts.
Flag bits
Device 0
Device 1
Microprocessor
Device 2
Basic Interrupt Sequence
1. The device that requires service sets its flag bit when an event takes
place.
4. The microprocessor looks up the interrupt vector (the address of the ISR)
for that device and puts the address into the PC.
There are several situations in which interrupts should not take control.
1. During the middle of an instruction
Since the microprocessor may take several clock cycles to load an instruction, an
interrupt could disrupt the fetching of an operation.
2. Interrupt another device
A device should never be able to interrupt another device. This could prevent
another ISR from finishing a reasonable amount of time.
Interrupt devices
Example programs