LD and CO Module 4
LD and CO Module 4
21IST34
Module 4
Prepared by
MOHAN D N
Assistant Professor
Department of ISE ,NCET
Bengaluru
Accessing I/O Devices
Accessing I/O devices
Processor Memory
Bu
s
Input device
•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
Accessing I/O devices (contd..)
Recall that the rate of transfer to and from
I/O devices is slower than the speed of the
processor. This creates the need for
mechanisms to synchronize data transfers
between them.
Program-controlled I/O:
⚫ Processor repeatedly monitors a status flag to achieve the necessary
synchronization.
⚫ Processor polls the I/O device.
Interru
pt i
occur
s i+
here 1
ways:
Some processors have an explicit interrupt-
acknowledge control signal
for this purpose.
In other cases, the data transfer that takes place
Enabling and disabling
Interrupts
• Interrupt-requests interrupt the execution of
a program, and may alter the intended
sequence of events:
⚫ Sometimes such alterations may be undesirable, and must not be
allowed.
⚫ For example, the processor may not want to be interrupted by the same
device
while executing its interrupt-service routine.
• Processors generally provide the ability to
enable and disable such interruptions as
desired.
• One simple way is to provide machine
instructions such as Interrupt-enable and
Interrupt- disable for this purpose.
• To avoid interruption by the same device
during the execution of an interrupt
service routine:
Interrupts (contd..)
Multiple I/O devices may be connected
to the processor and the memory via a
bus. Some or all of these devices may
be capable of generating interrupt
requests.
⚫ Each device operates independently, and hence no definite
order can
be imposed on how the devices generate interrupt requests?
Processo
NTRp
Device Device Device
1 2 p
r
INTA INTA p
1
Priority arbitration
I NTR1
INTR
r
p
Device Device
INTA
Priority p
arbitration
circuit
•Devices are
organized into
groups.
•Each group is
assigned a different
Interrupts (contd..)
Only those devices that are being used in
a program should be allowed to generate
interrupt requests.
To control which devices are allowed to
generate interrupt requests, the interface
circuit of each I/O device has an interrupt-
enable bit.
⚫ If the interrupt-enable bit in the device interface is set to 1, then
the device is
allowed to generate an interrupt-request.
Interrupt-enable bit in the device’s
interface circuit determines whether the
device is allowed to generate an
interrupt request.
Interrupt-enable bit in the processor
Exceptions
Interrupts caused by interrupt-requests
sent by I/O devices.
Interrupts could be used in many other
situations where the execution of one
program needs to be suspended and
execution of another program needs to be
started.
In general, the term exception is used to
refer to any event that causes an
interruption.
⚫ Interrupt-requests from I/O devices is one type of an exception.
System
bus
Disk/DMA DMA
Printer Keyboard
controller controller
B BS Y
BR
Processo
r
DMA DMA
controll controll
BG er BG er
1 1 2 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.
Centralized arbitration (contd..)
DMA controller 2
asserts the BR Tim
signal. Processor
e
BR
asserts
the BG1 signal
BG1 BG1 signal
propagates
BG2 to DMA#2.
B BSY
Bus
mast
er Processo DMA controller Processo
r 2 r
Processor relinquishes
control
of the bus by setting BBSY
to 1.
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.
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 0’s 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
Buses
Buses
Processor, main memory, and I/O
devices are interconnected by
means of a bus.
Bus provides a communication path
Bus clock
Bus cycle
Synchronous bus (contd..)
Tim
e
Bus
clock
Address
and
comman
d
Dat
a
t0 t1 t2
Bus
Master places the cycle
device address Addressed slave
and command on places Master “strobes” the
the bus, and data on the data data on the data lines
indicates that lines into its input buffer,
it is a Read for a Read operation.
• 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 electrical
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.
Synchronous bus (contd..)
At the end of the clock cycle, at time t2,
the master strobes the data on the
data lines into its input buffer if it’s a
Read operation.
“Strobe” means to capture the values of the data and store
them into a
buffer.
When data are to be loaded into a
storage buffer register, the data
should be available for a period longer
than the setup time of the device.
Synchronous bus (contd..)
Time
Address & Bus
command clock Data reaches
appear on Seen the master.
tAM
the bus. by
master
Address
and
Dat
comman
Address & d a tDM
command
Seen by
reach the tAS
slave
slave. Address Data
and appears
on the bus.
command
Dat
a
tDS
t t 2
•Signals do not appear on
0
the bus as soon as they are placed on the bus,
1
t
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 t equal to the hold
Synchronous bus (contd..)
Data transfer has to be completed
within one clock cycle.
Clock period t2 - t0 must be such that the longest propagation
delay on
the bus and the slowest device interface must be
accommodated.
Forces all the devices to operate at the speed of the slowest
device.
Processor just assumes that the data
are available at t2 in case of a Read
operation, or are read by the device in
case of a Write operation.
What if the device is actually failed, and never really
Synchronous bus (contd..)
Most buses have control signals to
represent a response from the slave.
Control signals serve two purposes:
Inform the master that the slave has recognized the address,
and is
ready to participate in a data transfer operation.
Enable to adjust the duration of the data transfer operation
based on the
speed of the participating slaves.
High-frequency bus clock is used:
Data transfer spans several clock cycles instead of just one
clock cycle
as in the earlier case.
Synchronous bus (contd..)
Address & Tim
command e
requesting a Read 1 2 3 4
operation appear
on the bus.
Cloc
k
Addres
s
Comman
d Master strobes data
into the input buffer.
Dat
a
Slave-
ready
Slave places the data on the Clock changes are seen by all the
bus,
and asserts Slave-ready signal. devices
at the same time.
Asynchronous bus
Data transfers on the bus is controlled
by a handshake 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
Slave-
ready
Dat
a
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.
Asynchronous vs. Synchronous bus
Address Dat
DATAOUT
a
Processor R/W
CPU SOUT Vali Printer
Master- d
ready Output Idl
e
Slave-
ready interfa
ce
•Printer is connected to a processor using a parallel port.
•Processor is 32 bits, uses memory-mapped I/O and asynchronous
bus protocol.
•On the processor side:
- Data lines.
- Address lines
- Control or R/W line.
- Master-ready signal and
- Slave-ready signal.
Parallel port (contd..)
Dat
a
Addres DATAOUT Dat
s a
CPU R/
Processor SOUT Vali Printer
W
d
Master-
ready Output Idl
Slave- e
ready interfa
ce
•On the printer side:
- Idle signal line which the printer asserts when it is ready to
accept a character.
This causes the SOUT flag to be set to 1.
- Processor places a new character into a DATAOUT register.
- Valid signal, asserted by the interface circuit when it places a
new character
on the data lines.
Circuit
•Data lines of the
processor bus are
connected to the
DATAOUT register of the
interface.
•The status flag SOUT is
connected to the data line D1
using a three-state driver.
•The three-state driver is
turned on, when the control
Read-status line is 1.
•Address decoder selects the
output interface using
address lines A1 through
A31.
•Address line A0 determines
whether the data is to be
loaded into the DATAOUT
register or status flag is to
be read.
•If the Load-data line is 1,
Bus
D PA
7 7
DATAI
D N
1 PA
D
0 SIN
0 •Combined I/O interface
Input
statu CA circuit.
s
30
• bits arebits
Address used
A2to select the
through A31,
PB7
overall
that is
DATAOU
T interface.
•Address
PB0 bits selectbits
oneA1
of through
the threeA0,
SOUT
Handsha
that is, 2
CB1 namely,
registers, DATAIN, DATAOUT,
ekcontrol CB2 the status register.
and
Slave-
Read
y
1
•Status register contains the flags
SIN and
SOUT in bits 0 and 1.
Master- •Data lines PA0 through PA7
Read
y connect the
R/ W
A3 input device to the DATAIN
1 Addres
s
My-
address register.
decode
A2
r •DATAOUT register connects the
A1
RS1
data lines on the processor bus
RS0
to lines PB0 through PB7 which
A0 connect to the output device.
•Separate input and output data
lines for
D P7
7 •Data lines to I/O device are
DATAIN bidirectional.
D P0
•both
Datainput, andthrough P0 can be
lines P7
0 •used forsome lines can be used for
In fact,
output.
input & some for output
depending on the pattern in the
DATAOUT •Data Direction
Processor Register
places (DDR).
an 8-bit pattern
•into
If a agiven
DDRbit position in the DDR
is 1, the corresponding data line
acts as an output line, otherwise
Data
it acts as an input line.
Directio •C1 and C2 control the interaction
n
Register between the interface circuit and
the I/O devices.
•are
Ready
connected
and Accept
to Master-ready
lines are &the
My-
address • Input
Slave-ready
handshake
signal My-address is
C1
RS2
Registe Statu control lines
connected on the
to the processor
output of an bus
r s and
RS1 side, and
address decoder.
select contr •Three register select lines that
RS0 ol
R/W allow up to 8
INTR C2 registers to be selected.
Ready
Accep
t
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-