MODULE 2: Input / Output Organization: Courtesy: Text Book: Carl Hamacher 5 Edition
MODULE 2: Input / Output Organization: Courtesy: Text Book: Carl Hamacher 5 Edition
Subject
Accessing I/O devices
•Multiple I/O devices may be connected to the processor and
the memory via a bus.
•Bus consists of three sets of lines to carry address, data and
control signals.
•Each I/O device is assigned an unique address.
•To access an I/O device, the processor places the address on
the address lines.
•The device recognizes the address, and responds to the control
signals.
The processor requests either a read or a write operation, and
the requested data are transferred over the data lines, when I/O
devices and the memory share the same address space, the
arrangement is called memory-mapped I/O.
Accessing I/O devices
Processor Memory
Bus
Control lines
Input device
Accessing I/O devices (contd..)
•I/O device is connected to the bus using an I/O interface
circuit which has:
- Address decoder, control circuit, and data and
status registers.
•Address decoder decodes the address placed on the address
lines thus enabling the device to recognize its address.
•Data register holds the data being transferred to or from the
processor.
•Status register holds information necessary for the operation
of the I/O device.
-Data and status registers are connected to the data lines, and
have unique addresses.
•I/O interface circuit coordinates I/O transfers.
Interrupts
• In Program-controlled I/O, where the processor repeatedly
checks a status flag to achieve the required synchronization
between the
• processor and an input or output device. We say that the
processor polls the device. There are two other commonly
used mechanisms for implementing I/O operations: Interrupts
and Direct Memory Access(DMA).
• In the case of interrupts, synchronization is achieved by
having the I/O device send a special signal over the bus
whenever it is ready for a data transfer operation. Direct
memory access is a technique used for high-speed I/O
devices.
• It involves having the device interface transfer data directly to
or from the memory, without continuous involvement by the
processor.
Interrupts
• The routine executed in response to an interrupt
request is called the interrupt- service routine, which
is the PRINT routine in our example. Interrupts bear
considerable resemblance to subroutine calls. Assume
that an interrupt request arrives during execution of
instruction i in figure
Interrupt
occurs i
here
i+1
M
Interrupts (contd..)
•Processor is executing the instruction located at address i when
an interrupt occurs. Routine executed in response to an interrupt
request is called the interrupt-service routine.
IN T R 1 INTR p
INTA1 INTA p
Priority arbitration
Controlling Multiple Devices:- Priority method
•Each device has a separate interrupt-request and
interrupt-acknowledge line.
Processor
Device Device
INTA1
Processor
IN T R p
Device Device
INTA p
Priority arbitration
circuit
• Trace mode:
– Exception occurs after the execution of every instruction.
– Debugging program is used as the exception-service routine.
• Breakpoints:
– Exception occurs only at specific points selected by the user.
– Debugging program is used as the exception-service routine.
Exceptions (contd..)
• Certain instructions can be executed only when the processor is in the
supervisor mode. These are called privileged instructions.
Two registers are used for storing the Starting address and the word count. The
third register contains status and control flags.
The R/W bit determines the direction of the transfer. When this bit is set to 1 by
a program instruction, the controller performs a read operation, that is, it
transfers data from the memory to the I/O device. Otherwise, it performs a write
operation.
When the controller has completed transferring a block of data and is ready to
receive another command, it sets the Done flag to 1. Bit 30 is the Interrupt-
enable flag, IE.
When this flag is set to 1, it causes the controller to raise an interrupt after it has
completed transferring a block of data. Finally, the controller sets the IRQ bit to 1
when it has requested an interrupt.
Direct Memory Access (contd..)
DMA controller can transfer a block of data from an external device to the
processor, without any intervention from the processor.
However, the operation of the DMA controller
must be under the control of a program executed
by the processor. That is, the processor must
initiate the DMA transfer.
To initiate the DMA transfer, the processor informs the DMA controller of:
Starting address,
Number of words in the block.
Direction of transfer (I/O device to the memory,
or memory to the I/O device).
Once the DMA controller completes the DMA transfer, it informs the
processor by raising an interrupt signal.
Direct Memory Access
Main
Processor
memory
System bus
B BS Y
BR
Processor
DMA DMA
controller controller
BG1 1 BG2 2
Centralized Bus Arbitration(cont.,)
• Bus arbiter may be the processor or a separate unit
connected to the bus.
• Normally, the processor is the bus master, unless it grants
bus membership to one of the DMA controllers.
• DMA controller requests the control of the bus by asserting
the Bus Request (BR) line.
• In response, the processor activates the Bus-Grant1 (BG1)
line, indicating that the controller may use the bus when it
is free.
• BG1 signal is connected to all DMA controllers in a daisy
chain fashion.
• BBSY signal is 0, it indicates that the bus is busy. When
BBSY becomes 1, the DMA controller which asserted BR
can acquire control of the bus.
Distributed arbitration
All devices waiting to use the bus share the responsibility of carrying
out the arbitration process.
Arbitration process does not depend on a central arbiter and hence
distributed arbitration has higher reliability.
Each device is assigned a 4-bit ID number.
All the devices are connected using 5 lines, 4 arbitration lines to
transmit the ID, and one line for the Start-Arbitration signal.
To request the bus a device:
Asserts the Start-Arbitration signal.
Places its 4-bit ID number on the arbitration lines.
The pattern that appears on the arbitration lines is the logical-OR of
all the 4-bit device IDs placed on the arbitration lines.
Distributed arbitration
Distributed arbitration(Contd.,)
• Arbitration process:
– Each device compares the pattern that appears on the
arbitration lines to its own ID, starting with MSB.
– If it detects a difference, it transmits 0s on the arbitration
lines for that and all lower bit positions.
– The pattern that appears on the arbitration lines is the
logical-OR of all the 4-bit device IDs placed on the
arbitration lines.
Distributed arbitration (contd..)
•Device A has the ID 5 and wants to request the bus:
- Transmits the pattern 0101 on the arbitration lines.
•Device B has the ID 6 and wants to request the bus:
- Transmits the pattern 0110 on the arbitration lines.
•Pattern that appears on the arbitration lines is the logical OR of the patterns:
- Pattern 0111 appears on the arbitration lines.
Arbitration process:
•Each device compares the pattern that appears on the arbitration lines to its own
ID, starting with MSB.
•If it detects a difference, it transmits 0s on the arbitration lines for that and all lower
bit positions.
•Device A compares its ID 5 with a pattern 0101 to pattern 0111.
•It detects a difference at bit position 0, as a result, it transmits a pattern 0100 on the
arbitration lines.
•The pattern that appears on the arbitration lines is the logical-OR of 0100 and 0110,
which is 0110.
•This pattern is the same as the device ID of B, and hence B has won the arbitration.
Buses
• Processor, main memory, and I/O devices are
interconnected by means of a bus.
Address and
command
Data
t0 t1 t2
Bus cycle
Master places the
device address and Addressed slave places
command on the bus, data on the data lines Master “strobes” the data
and indicates that on the data lines into its
it is a Read operation. input buffer, for a Read
operation.
•In case of a Write operation, the master places the data on the bus along with the
address and commands at time t0.
•The slave strobes the data into its input buffer at time t2.
Synchronous bus (contd..)
• Once the master places the device address and
command on the bus, it takes time for this
information to propagate to the devices:
– This time depends on the physical and electric characteristics of
the bus.
• Also, all the devices have to be given enough time
to decode the address and control signals, so that
the addressed slave can place data on the bus.
• Width of the pulse t1 - t0 depends on:
– Maximum propagation delay between two devices
connected to the bus.
– Time taken by all the devices to decode the address
and control signals, so that the addressed slave can
respond at time t1.
Synchronous bus (contd..)
T ime
Address & Bus clock
command Data reaches
Seen by
appear on the master tAM the master.
bus. Address and
command
Data
Address & tDM
command reach
Seen by slave
the slave. tAS
Address and Data appears
command on the bus.
Data
tDS
t0 t1 t
2
•Signals do not appear on the bus as soon as they are placed on the bus, due to the
propagation delay in the interface circuits.
•Signals reach the devices after a propagation delay which depends on the
characteristics of the bus.
•Data must remain on the bus for some time after t2 equal to the hold time of the buffer.
Asynchronous bus
Data transfers on the bus is controlled by a handshake
protocol between the master and the slave.
Common clock in the synchronous bus case is replaced by
two timing control lines:
Master-ready,
Slave-ready.
Master-ready signal is asserted by the master to indicate to
the slave that it is ready to participate in a data transfer.
Slave-ready signal is asserted by the slave in response to the
master-ready from the master, and it indicates to the
master that the slave is ready to participate in a data
transfer.
Asynchronous bus (contd..)
• Data transfer using the handshake protocol:
– Master places the address and command information on the bus.
– Asserts the Master-ready signal to indicate to the slaves that the
address and command information has been placed on the bus.
– All devices on the bus decode the address.
– Address slave performs the required operation, and informs the
processor it has done so by asserting the Slave-ready signal.
– Master removes all the signals from the bus, once Slave-ready is
asserted.
– If the operation is a Read operation, Master also strobes the data
into its input buffer.
Asynchronous bus (contd..)
T ime
Address
and command
Master-ready
Slave-ready
Data
t0 t1 t2 t3 t4 t5
Bus cycle
t0 - Master places the address and command information on the bus.
t1 - Master asserts the Master-ready signal. Master-ready signal is asserted at t1 instead of t0
t2 - Addressed slave places the data on the bus and asserts the Slave-ready signal.
t3 - Slave-ready signal arrives at the master.
t4 - Master removes the address and command information.
t5 - Slave receives the transition of the Master-ready signal from 1 to 0. It removes the data
and the Slave-ready signal from the bus.
Interface circuits
I/O interface consists of the circuitry required to
connect an I/O device to a computer bus.
Side of the interface which connects to the
computer has bus signals for:
Address,
Data
Control
Side of the interface which connects to the I/O
device has:
Datapath and associated controls to transfer data between the interface and the I/O
device.
This side is called as a “port”.
Ports can be classified into two:
Parallel port,
Serial port.
Interface circuits (contd..)
• Parallel port transfers data in the form of a
number of bits, normally 8 or 16 to or from
the device.
• Serial port transfers and receives data one bit
at a time.
• Processor communicates with the bus in the
same way, whether it is a parallel port or a
serial port.
– Conversion from the parallel to serial and vice versa takes place inside the
interface circuit.
Parallel port
Data
Address
DATAIN Data
Encoder
R /W and K eyboard
Processor SIN
debouncing switches
Master-ready circuit
Valid
Input
Slav e-ready
interface
Address
DATAIN Data
Encoder
R /W and K eyboard
Processor SIN
debouncing switches
Master-ready circuit
Valid
Input
Slav e-ready
interface
Processor
CPU R /W SOUT Printer
Valid
Master-ready
Output Idle
Sla ve-ready interface
Processor
CPU R /W SOUT Printer
Valid
Master-ready
Output Idle
Sla ve-ready interface
DATAIN
D1
D0 PA0
SIN
•Combined I/O interface circuit.
Input
status CA •Address bits A2 through A31, that is
30 bits are used to select the overall
PB7
interface.
DATAOUT •Address bits A1 through A0, that is, 2
PB0 bits select one of the three registers,
SOUT
CB1
namely, DATAIN, DATAOUT, and
Handshake
control CB2 the status register.
Sla ve-
Ready 1
•Status register contains the flags SIN and
SOUT in bits 0 and 1.
•Data lines PA0 through PA7 connect the
Master- input device to the DATAIN register.
Ready
R /W
•DATAOUT register connects the data
A31 lines on the processor bus to lines PB0
Address
decoder
My-address
through PB7 which connect to the output
A2 device.
A1
RS1 •Separate input and output data lines for
connection to an I/O device.
RS0
A0
D7 P7
•Data lines to I/O device are bidirectional.
DATAIN •Data lines P7 through P0 can be used for
D0 P0
both input, and output.
•In fact, some lines can be used for input &
some for output depending on the pattern
in the Data Direction Register (DDR).
D ATAOUT •Processor places an 8-bit pattern into a DDR
•If a given bit position in the DDR is 1, the
corresponding data line acts as an output
line, otherwise it acts as an input line.
Data
•C1 and C2 control the interaction between
Direction the interface circuit and the I/O devices.
Register
•Ready and Accept lines are the handshake
control lines on the processor bus side, and
My-address
are connected to Master-ready & Slave-ready
RS2 •Input signal My-address is connected to the
C1
RS1
Register Status output of an address decoder.
RS0 and
R /W
select control •Three register select lines that allow up to 8
Ready C2 registers to be selected.
Accept
INTR
Serial port
• Serial port is used to connect the processor to
I/O devices that require transmission of data
one bit at a time.
• Serial port communicates in a bit-serial
fashion on the device side and bit parallel
fashion on the bus side.
– Transformation between the parallel and serial formats is achieved with shift
registers that have parallel access capability.
Input shift register Serial
input
•Input shift register accepts input one bit
at a time from the I/O device.
DATAIN •Once all the 8 bits are received, the
contents of the input shift register are
loaded in parallel into DATAIN register.
•Output data in the DATAOUT register
are loaded into the output shift register.
D7 •Bits are shifted out of the output shift
register and sent out to the I/O device on
D0 bit at a time.
•As soon as data from the input shift reg.
My-address DA TA OUT are loaded into DATAIN, it can start
RS1 accepting another 8 bits of data.
RS0 •Input shift register and DATAIN register
Chip and Serial are both used at input so that the input
R /W register Output shift register
Ready select shift register can start receiving another
Accept set of 8 bits from the input device after
loading the contents to DATAIN, before
Recei ving clock
Status
the processor reads the contents of
INTR
and
control ransmission clock DATAIN. This is called as double-
T
buffering.
Serial port (contd..)
Serial interfaces require fewer wires, and hence serial
transmission is convenient for connecting devices that
are physically distant from the computer.
Speed of transmission of the data over a serial interface
is known as the “bit rate”.
Bit rate depends on the nature of the devices connected.
In order to accommodate devices with a range of
speeds, a serial interface must be able to use a range of
clock speeds.
Several standard serial interfaces have been developed:
Universal Asynchronous Receiver Transmitter (UART) for low-speed
serial devices.
RS-232-C for connection to communication links.
Standard I/O interfaces
I/O device is connected to a computer using an
interface circuit.
Do we have to design a different interface for every
combination of an I/O device and a computer?
A practical approach is to develop standard interfaces
and protocols.
A personal computer has:
A motherboard which houses the processor chip, main memory and
some I/O interfaces.
A few connectors into which additional interfaces can be plugged.
Processor bus is defined by the signals on the processor
chip.
Devices which require high-speed connection to the processor
are connected directly to this bus.
Standard I/O interfaces (contd..)
Because of electrical reasons only a few devices can be
connected directly to the processor bus.
Motherboard usually provides another bus that can
support more devices.
Processor bus and the other bus (called as expansion bus) are
interconnected by a circuit called “bridge”.
Devices connected to the expansion bus experience a small delay in data
transfers.
Design of a processor bus is closely tied to the
architecture of the processor.
No uniform standard can be defined.
Expansion bus however can have uniform standard
defined.
Standard I/O interfaces (contd..)
• A number of standards have been developed
for the expansion bus.
– Some have evolved by default.
– For example, IBM’s Industry Standard Architecture.
Processor
Main
memory
Bridge circuit translates
signals and protocols from
processor bus to PCI bus.
Processor bus
Bridge
PCI bus
Expansion bus on
the motherboard
Additional SCSI Ethernet USB ISA
memory controller Interface controller Interface
SCSI b us
IDE
disk
V ideo
Disk CD-R OM
controller controller
CD-
Disk 1 Disk 2 R OM K eyboard Game
PCI Bus
Peripheral Component Interconnect
Introduced in 1992
Low-cost bus
Processor independent
Plug-and-play capability
In today’s computers, most memory transfers involve a burst of data rather
than just one word. The PCI is designed primarily to support this mode of
operation.
The bus supports three independent address spaces: memory, I/O, and
configuration.
we assumed that the master maintains the address information on the bus
until data transfer is completed. But, the address is needed only long
enough for the slave to be selected. Thus, the address is needed on the bus
for one clock cycle only, freeing the address lines to be used for sending
data in subsequent clock cycles. The result is a significant cost reduction.
A master is called an initiator in PCI terminology. The addressed device that
responds to read and write commands is called a target.
Data transfer signals on the PCI bus.
Name F unction
CLK
Frame#
AD Adress #1 #2 #3 #4
IRD Y#
TRD Y#
DEVSEL#
DB 2
DB 5
DB 6
BS Y
SEL
Host computer
Root
hub
Hub Hub
I/O I/O
device device
Universal Serial Bus tree structure
Bits 8 7 4 5
Control packets used for
PID ADDR ENDP CRC16 controlling data transfer
operations are called token
packets.
(b) Token packet, IN or OUT
Bits 8 0 to 8192 16
Token
Data0
ACK
Time
Token
Data0
ACK
Token
Data1
Figure: An output
transfer
ACK
Token
Data1
ACK
Isochronous Traffic on USB
One of the key objectives of the USB is to support the transfer of
isochronous data.
Devices that generates or receives isochronous data require a time
reference to control the sampling process.
To provide this reference. Transmission over the USB is divided into
frames of equal length.
A frame is 1ms long for low-and full-speed data.
The root hub generates a Start of Frame control packet (SOF) precisely
once every 1 ms to mark the beginning of a new frame.
The arrival of an SOF packet at any device constitutes a regular clock
signal that the device can use for its own purposes.
To assist devices that may need longer periods of time, the SOF packet
carries an 11-bit frame number.
Following each SOF packet, the host carries out input and output
transfers for isochronous devices. This means that each device will have
an opportunity for an input or output transfer once every 1 ms.
Electrical Characteristics
The cables used for USB connections consist of four
wires.
Two are used to carry power, +5V and Ground.
Thus, a hub or an I/O device may be powered directly from
the bus, or it may have its own external power connection.
The other two wires are used to carry data.
Different signaling schemes are used for different
speeds of transmission.
At low speed, 1s and 0s are transmitted by sending a high
voltage state (5V) on one or the other o the two signal
wires. For high-speed links, differential transmission is used.