Beruflich Dokumente
Kultur Dokumente
-Swami Vivekananda
Chapter 3
Input / Output
Organization
Chapter objectives
• Program-controlled I/O using polling
• Interrupts
• DMA
• Data transfer over synchronous and
asynchronous buses
• Commercial bus standards, PCI, SCSI, USB
Input / Output
• Communication
• Exchange information
Accessing I/O devices
• Single-bus structure
• Memory-mapped I/O
Move DATAIN, R0
Move R0, DATAOUT
Processor Memory
Bus
I/O device 1 I/O device n
Figure. A singlebus structure
Hardware required to connect an
I/O device to the bus
Figure
• Address decoder
• Control circuits Interface
• Data and status registers circuit
Address lines
Bus Data lines
Control lines
Input device
Figure. I/O interface for an input device.
Illustration of program-controlled
I/O
DATAOUT
7 6 5 4 3 2 1 0
Figure. Registers in keyboard and display interfaces
Move #LINE, R0 Initialize memory pointer.
re. A program that reads one line from the keyboard stores it in memory buffer
and echoes it back to the display.
Program-controlled I/O
• Processor repeatedly checks a status flag to
achieve synchronization between the
processor and I/O device
• Processor polls the device
INTERRUPTS
• Hardware signal
• Sent by I/O device to alert the processor
when it becomes ready
• Processor can utilize waiting period to
perform other useful functions
Interrupts (cont.)
• Interrupt Service Routine
• Interrupt-request line
• Interrupt-acknowledge signal
• Interrupt vs. subroutine
• Interrupt latency
• Interrupt vs. Exception
Example to illustrate interrupts
Program 1 Program 2
COMPUTE routine PRINT routine
(ISR)
1
2
Interrupt
occurs i
here
i +1
Figure. Transfer of control through the use of interrupts.
Types of Exceptions
• I / O device request
• Invoking an operating system service from
a user program
• Tracing instruction execution
• Breakpoint(programmer-requested)
• Integer arithmetic overflow / underflow
• Power failure
Interrupt Hardware
V
dd
Processor
INTR
INTR
Figure. An equivalent circuit for an opendrain bus used
to implement a common interruptrequest line.
Open-drain bus to implement
interrupt-request line
• INTR1 to INTRn – Interrupt request signals
• INTR = INTR1 + … + INTRn
• Open collector(bipolar circuits) or open-
drain(MOS circuits)
• Pull-up resistor R
Enabling and Disabling
Interrupts
• Is it necessary?
• How?
• Interrupt-enable and Interrupt-disable
functions
Enabling and Disabling Interrupts(cont.)
• Option 1
– Have processor ignore interrupt-request line
until execution of first instruction of ISR
– Use interrupt-disable instruction as first
instruction in ISR
– Use interrupt-enable instruction as last
instruction in ISR before Return-from-interrupt
Enabling and Disabling Interrupts(cont.)
• Option 2
– Have the processor automatically disable
interrupts before starting execution of ISR
– PS register
• Option 3
– Processor has an edge-triggered interrupt-
request line
Handling multiple devices
• How can the processor recognize the device requesting an
interrupt?
• Vectored interrupts
– Code supplied by the device over the bus
– Interrupt Vector code
Handling multiple devices(cont.)
• Interrupt Nesting
– Device that sends interrupt requests to the
processor at regular intervals
– Priority structure for I/O devices
– Processor – user & supervisor modes
– Privileged instructions
INTR1 INTRp
Processor
INTA1 INTAp
Priority arbitration
circuit
Figure .
Implementation of interrupt priority using individual
interruptrequest and acknowledge lines.
Handling multiple devices(cont.)
• Simultaneous Requests
– How does the processor decide which request
to service first?
– Daisy chain
INTR
Processor
(a) Daisy chain
Figure. Interrupt priority schemes.
INTR 1
Device Device
INTA1
Processor
INTRp
Device Device
INTAp
Priority arbitration
circuit
(b) Arrangement of priority groups
Figure. Interrupt priority schemes.
Controlling device requests
• Idle devices must not be allowed to
generate interrupt requests
– Device end
– Processor end
Main Program
Status and control
IRQ Done
IE R/ W
Starting address
Word count
Figure. Registers in a DMA interface.
Main
Processor
memory
System bus
Disk/DMA DMA
controller controller Printer Keyboard
Centralized arbitration
Distributed arbitration
BBSY
BR
Processor
DMA DMA
controller controller
BG1 1 BG2 2
Figure. A simple arrangement for bus arbitration using a daisy chain.
Time
BR
BG1
BG2
B BS Y
Bus
master
Processor DMA controller 2 Processor
Figure. Sequence of signals during transfer of b
us mastership
for the de
vices in previous Figure.
V
cc
ARB 3
ARB 2
ARB 1
ARB 0
StartArbitration
O.C.
0 1 0 1 0 1 1 1
Interface circuit
for device A
Figure. A distributed arbitration scheme.
BUSES
• Data lines
• Address lines
• Control lines
–R/W
– Operand size
– Timing information
• Master(initiator) and slave(target)
Synchronous Bus
• All devices derive timing information from
a common clock line.
Time
Bus clock
Address and
command
Data
t0 t1 t2
Bus cycle
Figure 4.23. Timing of an input transfer on a synchronous bus.
Time
Bus clock
Seen by master t
AM
Address and
command
Data
t
DM
Seen by slave
t
AS
Address and
command
Data
t
DS
t t t
0 1 2
Figure. A detailed timing diagram for the input transfer of Figure 4.23.
Multiple-Cycle Transfers Time
1 2 3 4
Clock
Address
Command
Data
Slaveready
Figure. An input transfer using multiple clock cycles.
Asynchronous Bus
Address
and command
Masterready
Slaveready
Data
t t t t t t
0 1 2 3 4 5
Bus cycle
Figure. Handshake control of data transfer during an input operation.
Time
Address
and command
Data
Masterready
Slaveready
t0 t1 t2 t3 t4 t5
Bus cycle
Figure. Handshake control of data transfer during an output operation.
INTERFACE CIRCUITS
• Circuitry required to connect an I/O device
to a computer bus
• Ports
– Serial port
– Parallel port
Parallel Port
Next page …
Data
Address
DATAIN Data
Encoder
R /W and Keyboard
Processor SIN
debouncing switches
Masterready circuit
Valid
Input
Slaveready
interface
Figure. Keyboard to processor connection.
D AT AIN
D7 Q D
7 7
K e yboard
data
D0 Q0 D0
SIN
Status V alid
flag
Sla ve
ready 1
Read
status
Read
data
R/W
Master
ready
A31
Address
decoder
A1
Figure 4.29. Input interface circuit
A0
Data
Processor
CPU R /W SOUT Printer
Valid
Master
ready
Output Idle
Sla v eready interf ace
Figure . Printer to processor connection.
Figure. Output interface circuit
Bus
D7 P A7
D A TAIN
D1
D0 P A0
SIN
Input
status CA
PB7
D A TA OUT
PB0
SOUT
Handshak e CB1
control CB2
Sla ve
Ready 1
Master
Ready
R/W
A31
Myaddress
Address
decoder Figure. Combined input/output
interface circuit.
A2
RS1
A1
RS0
A0
D7 P7
DATAIN
D0 P0
D ATAOUT
Data
Direction
Register
Myaddress
Figure. A general 8bit parallel interface
RS2
RS1 Status C1
Register
RS0 and
select control
R /W C2
Ready
Accept
INTR
DATAOUT
D7 D7 Q7
Printer
data
D0 D1 Q1
D0 D0 Q0
SOUT
Handshake Idle
control Valid
Read Load
status data
R/W
Slave
ready
Go
A31
Address Myaddress Timing
decoder Logic Myaddress
A1
A0 Idle Respond
Go=1
Clock
Figure 35. A parallel point interface for the bus of Figure 25,
with a statediagram for the timing logic.
Time
1 2 3
Clock
Address
R/W
Data
Go
Slaveready
Figure 36. Timing for the output interface in Figure 35.
Serial Port
Next page…
Serial
Input shift register input
DATAIN
D7
Figure. A serial
D0
interface.
DATAOUT
Myaddress
RS1
RS0 Chip and
register Serial
R /W Output shift register output
select
Ready
Accept
Status Receiving clock
I NTR and
control
Transmission clock
Standard I/O interfaces
• Bridge
• ISA(Industry Standard Architecture) – PC AT
• IEEE
• ANSI
• ISO
Widely used bus standards
• PCI
• SCSI
• USB
Main
Processor
memory
Processor bus
Bridge
PCI bus
SCSI bus
IDE
disk
Video
Disk CDROM
controller controller
CD
Disk 1 Disk 2 ROM Keyboard Game
Figure . An example of a computer system using different interface standards.
PCI Bus
• Peripheral Component Interconnect
• Introduced in 1992
• Low-cost bus
• Processor independent
• Plug-and-play capability
Host
Main
PCI bridge
memory
PCI bus
Ethernet
Disk Printer
interface
Figure 39. Use of a PCI bus in a computer system.
Table 4.3. Data transfer signals on the PCI bus.
Name F
unction
C/BE# command/byte-enable
4 lines (8 for a 64-bit bus).
CLK
Frame#
Adress #1 #2 #3 #4
AD
IRDY#
TRD Y#
DEVSEL#
Figure 40. A read operation on the PCI bus.
1 2 3 4 5 6 7 8 9
CLK
Frame#
Adress #1 #2 #3 #4
AD
IRDY#
TRDY#
DEVSEL#
Figure 41. A read operation showing the role of IRDY# / TRDY#
PCI Bus …
• Data Transfer
• Device Configuration
• Electrical Characteristics
SCSI Bus
• Small Computer System Interface
• Defined by ANSI – X3.131
• 50, 68 or 80 pins
• Max. transfer rate – 160 MB/s, 320 MB/s.
Table 4. The SCSI bus signals.
Category Name u
Fnction
– SEL Selection:
Asserted
duringselection
and
reselection
– MSG Message:indicates
thatthe
information being
transferred
isamessage
Table 4. The SCSI bus signals.(cont.)
Category Name u
Fnction
– ACK Ackno
wledge:Assertedbytheinitiatorwhenit
hascompletedadatatransferop
eration
DB 2
DB 5
DB 6
BS Y
S EL
Figure 42. Arbitration and selection on the SCSI bus.
Device 6 wins arbitration and selects device 2.
USB
• Universal Serial Bus
• Speed
• Low-speed(1.5 Mb/s)
• Full-speed(12 Mb/s)
• High-speed(480 Mb/s)
• Port Limitation
• Device Characteristics
• Plug-and-play
Host computer
Root
hub
Hub Hub
I/O I/O
device device
Figure 43. Universal Serial Bus tree structure.
Host computer
Root
Hub
HS HS
Hub A Hub B
HS F/LS
HS High speed
F/LS Full/Low speed
De vice De vice
C D
Figure 44. Split bus operation
USB(cont.)
• Addressing
• USB Protocols
PID0 PID1 PID2 PID3 PID0 PID1 PID2 PID3
(a) Packet identifier field
Bits 8 7 4 5
(b) Token packet, IN or OUT
Bits 8 0 to 8192 16
(c) Data packet
Figure 45. USB packet format.
Host Hub I/O Device
Token
Data0
ACK
Time
Token
Data0
ACK
Token
Data1
Figure . An
output
ACK transfer
Token
Data1
ACK
USB(cont.)
(a) SOF Packet
1ms frame
S T3 D T7 D S T3 D
S Startofframe packet
Tn Token packet, address = n
D Data packet
A ACK packet
(b) Frame example
Figure 47. USB frames.
The only person who
never makes a mistake
is the person who never does
anything…!
- Theodore Roosevelt