Professional Documents
Culture Documents
1.6 Cpus: Programming Input and Output
1.6 Cpus: Programming Input and Output
no
char
start
bit 0
bit 1
...
The parameters for the serial port are familiar from the parameters for a serial communications program:
7/12/2016
8251 USART
7/12/2016
7/12/2016
We can use the EQU pseudo-op to define a symbolic name for the
memoryy location of our I/O device:
Given that name, we can use the following standard code to read and
write the device register:
7/12/2016
7/12/2016
Interruptsandsubroutines
Because the CPU checks for interrupts at every instruction, it can respond quickly to
service requests from devices. However, the interrupt handler must return to the
foreground program without disturbing the foreground programs operation. Because
subroutines perform a similar function, it is natural to build the CPUs interrupt mechanism
to resemble its subroutine function. Most CPUs use the same basic mechanism for
remembering the foreground programs PC as is used for subroutines. The subroutine call
mechanism in modern microprocessors is typically a stack, so the interrupt mechanism
puts the return address on a stack; some CPUs use the same stack as for subroutines while
others define a special stack.
7/12/2016
Prioritiesandvectors
Providingapracticalinterruptsystemrequireshavingmorethanasimpleinterruptrequest
line.MostsystemshavemorethanoneI/Odevice,sotheremustbesomemechanismfor
allowingmultipledevicestointerrupt.Wealsowanttohaveflexibilityinthelocationsof
theinterrupthandlingroutines,theaddressesfordevices,andsoon.
Therearetwowaysinwhichinterruptscanbegeneralizedtohandlemultipledevicesand
toprovidemoreflexibledefinitionsfortheassociatedhardwareandsoftware:
interruptprioritiesallowtheCPUtorecognizesomeinterruptsasmoreimportant
thanothers,and
interruptvectorsallowtheinterruptingdevicetospecifyitshandler.
Vectors provide flexibility in a different dimension, namely, the ability to define the interrupt
handler that should service a request from a device. In addition to the interrupt request and
acknowledge lines, additional interrupt vector lines run from the devices to the CPU. After a
devices request is acknowledged, it sends its interrupt vector over those lines to the CPU.
7/12/2016
Interruptoverhead
Onceadevicerequestsaninterrupt,somestepsareperformedbytheCPU,some
bythedevice,andothersbysoftware:
CPU:TheCPUchecksforpendinginterruptsatthebeginningofan
instruction It answers the highest priority interrupt which has a higher
instruction.Itanswersthehighestpriorityinterrupt,whichhasahigher
prioritythanthatgivenintheinterruptpriorityregister.
Device:ThedevicereceivestheacknowledgmentandsendstheCPUits
interruptvector.
CPU:TheCPUlooksupthedevicehandleraddressintheinterruptvector
tableusingthevectorasanindex.Asubroutinelikemechanismisused
tosavethecurrentvalueofthePCandpossiblyotherinternalCPUstate,
suchasgeneral purposeregisters.
Software:ThedevicedrivermaysaveadditionalCPUstate.Itthen
performstherequiredoperationsonthedevice.Itthenrestoresany
savedstateandexecutestheinterruptreturninstruction.
CPU:TheinterruptreturninstructionrestoresthePCandother
automaticallysavedstatestoreturnexecutiontothecodethatwas
interrupted.
Interrupts in ARM
ARM7 supports two types of interrupts: fast interrupt requests (FIQs) and interrupt
requests (IRQs). An FIQ takes priority over an IRQ. The interrupt table is always kept in
the bottom memory addresses, starting at location 0. The entries in the table typically
contain subroutine calls to the appropriate handler.
The ARM7 performs the following steps when responding to an interrupt: