Input Output Device
Input Output Device
ORGANIZATION
Dr Shreema Shetty
Dept CSE
SCEM
1
ACCESSING I/O-DEVICES
• A single bus-structure can be used for connecting I/O-devices to a computer
(Figure1).
• Each I/O device is assigned a unique set of address.
• Bus consists of 3 sets of lines to carry address, data & control signals.
• When processor places an address on address-lines, the intended-device
responds to the command.
• The processor requests either a read or write-operation.
• The requested-data are transferred over the data-lines.
2
3
• There are 2 ways to deal with I/O-devices:
1) Memory-mapped I/O & 2) I/O-mapped I/O.
1) Memory-Mapped I/O
Memory and I/O-devices share a common address-space.
Any data-transfer instruction (like Move, Load) can be used to exchange
information.
For example, Move DATAIN, R0; This instruction sends the contents of location
DATAIN to register R0. Here, DATAIN address of the input-buffer of the keyboard.
4
2) I/O-Mapped I/O
Dr Shreema Shetty
Dept CSE
SCEM
5
I/O Interface for an Input Device
1) Address Decoder: enables the device to recognize its address when this
address appears on the address-lines (Figure 2).
There are 2types:i) DATAIN Input-buffer associated with keyboard. ii) DATAOUT
Output data buffer of a display/printer.
6
7
8
MECHANISMS USED FOR INTERFACING I/O-DEVICES
• Main drawback: The processor wastes time in checking status of device before
actual data-transfer takes place.
9
2) Interrupt I/O
• Like this, required synchronization is done between processor & I/O device.
10
3) Direct Memory Access (DMA)
Dr Shreema Shetty
Dept CSE
11
SCEM
INTERRUPTS
• There are many situations where other tasks can be performed while waiting for
an I/O device to become ready.
• A hardware signal called an Interrupt will alert the processor when an I/O device
becomes ready.
12
• The processor can be performing its own task without the need to continuously
check the I/O-device.
• The processor must inform the device that its request has been recognized by
sending INTA signal.
13
INTERRUPTS
• There are many situations where other tasks can be performed while waiting for
an I/O device to become ready.
• A hardware signal called an Interrupt will alert the processor when an I/O device
becomes ready.
• Interrupt-signal is sent on the interrupt-request line.
• The processor can be performing its own task without the need to continuously
check the I/O-device.
• The routine executed in response to an interrupt-request is called ISR.
14
15
The processor first completes the execution of instruction i.
• Then, processor loads the PC with the address of the first instruction of the ISR.
• After the execution of ISR, the processor has to come back to instruction i+1.
• Therefore, when an interrupt occurs, the current content of PC is put in
temporary storage location.
• A return at the end of ISR reloads the PC from that temporary storage location.
• This causes the execution to resume at instruction i+1.
16
• When processor is handling interrupts, it must inform device that its request has
been recognized.
• This may be accomplished by INTA signal.
• The task of saving and restoring the information can be done automatically by
the processor.
• The processor saves only the contents of PC & Status register.
• Saving registers also increases the Interrupt Latency.
17
• Interrupt Latency is a delay between
Dr Shreema Shetty
Dept CSE
SCEM 18
19
INTERRUPT HARDWARE
• Most computers have several I/O devices that can request an interrupt.
• A single interrupt-request (IR) line may be used to serve n devices (Figure 4.6).
• All devices are connected to IR line via switches to ground.
• To request an interrupt, a device closes its associated switch.
• Thus, if all IR signals are inactive, the voltage on the IR line will be equal to Vdd.
• When a device requests an interrupt, the voltage on the line drops to 0.
• This causes the INTR received by the processor to go to 1.
20
• The value of INTR is the logical OR of the requests from individual devices.
INTR=INTR1+ INTR2+ . . . . . +INTRn
• A special gates known as open-collector or open-drain are used to drive the INTR line.
• The Output of the open collector control is equal to a switch to the ground that is
→ open when gates input is in ”0‟ state and
→ closed when the gates input is in “1‟ state.
• Resistor R is called a Pull-up Resistor because it pulls the line voltage up to the high-voltage
state when the switches are open.
21
22
ENABLING & DISABLING INTERRUPTS
• All computers fundamentally should be able to enable and disable interruptions as desired.
• The problem of infinite loop occurs due to successive interruptions of active INTR signals.
1) Processor should ignore the interrupts until execution of first instruction of the ISR.
2) Processor should automatically disable interrupts before starting the execution of the ISR.
3) Processor has a special INTR line for which the interrupt-handling circuit.
Interrupt-circuit responds only to leading edge of signal. Such line is called edge-triggered.
23
• Sequence of events involved in handling an interrupt-request:
1) The device raises an interrupt-request.
2) The processor interrupts the program currently being executed.
3) Interrupts are disabled by changing the control bits in the processor status register (PS).
4) The device is informed that its request has been recognized.
In response, the device deactivates the interrupt-request signal.
5) The action requested by the interrupt is performed by the interrupt-service routine.
6) Interrupts are enabled and execution of the interrupted program is resumed.
24
HANDLING MULTIPLE DEVICES
• While handling multiple devices, the issues concerned are:
2) How can the processor obtain the starting address of the appropriate ISR?
Dr Shreema Shetty
Dept CSE
25
SCEM
POLLING
• Information needed to determine whether device is requesting interrupt is available in
status-register
• Following condition-codes are used:
DIRQ Interrupt-request for display.
KIRQ Interrupt-request for keyboard.
KEN keyboard enable.
DEN Display Enable.
SIN, SOUT status flags.
26
• For an input device, SIN status flag in used.
• Simplest way to identify interrupting-device is to have ISR poll all devices connected to bus.
• The first device encountered with its IRQ bit set is serviced.
Dr Shreema Shetty
Dept CSE
27
SCEM
• Advantage: Simple & easy to implement.
28
29
VECTORED INTERRUPTS
30
• Processor
→ loads interrupt-vector into PC &
→ executes appropriate ISR.
• When processor is ready to receive interrupt-vector code, it activates INTA line.
• Then, I/O-device responds by sending its interrupt-vector code & turning off the
INTR signal.
• The interrupt vector also includes a new value for the Processor Status Register.
31
CONTROLLING DEVICE REQUESTS
• Following condition-codes are used:
32
1) At Device-end
→ Priority structure
33
34
INTERRUPT NESTING
• A multiple-priority scheme is implemented by using separate INTR & INTA lines for each
device
• Each INTR line is assigned a different priority-level (Figure 4.7).
• Priority-level of processor is the priority of program that is currently being executed.
• Processor accepts interrupts only from devices that have higher-priority than its own.
• At the time of execution of ISR for some device, priority of processor is raised to that of
the device.
• Thus, interrupts from devices at the same level of priority or lower are disabled.
35
Privileged Instruction
36
Privileged Exception
37
38
● Each of the interrupt request lines are assigned a different priority level.
● Interrupt request received over these lines are sent to a priority arbitration
circuit in the processor.
● A request is accepted only if it has higher priority level than that currently
assigned to the processor.
39
SIMULTANEOUS REQUESTS
• The processor must have some mechanisms to decide which request to service when
simultaneous requests arrive.
• INTR line is common to all devices (Figure 4.8a).
• INTA line is connected in a daisy-chain fashion.
• INTA signal propagates serially through devices.
• When several devices raise an interrupt-request, INTR line is activated.
Polling the status register of I/O devices is the simplest mechanism to determine by the
order in which the devices are polled.
40
• Processor responds by setting INTA line to 1. This signal is received by device 1.
• Device-1 passes signal on to device 2 only if it does not require any service.
• If device-1 has a pending-request for interrupt, the device-1
→ blocks INTA signal &
→ proceeds to put its identifying-code on data-lines.
• Device that is electrically closest to processor has highest priority
• Advantage: It requires fewer wires than the individual connections.
41
Arrangement of Priority Groups
• Here, the devices are organized in groups & each group is connected at a
different priority level.
Dr Shreema Shetty
Dept CSE
42
SCEM
43
44
EXCEPTIONS
• An interrupt is an event that causes → execution of one program to be
suspended & → execution of another program to begin.
• Exception refers to any event that causes an interruption. For ex: I/O interrupts.
1. Recovery from Errors
• These are techniques to ensure that all hardware components are operating
properly.
• For ex: Many computers include an ECC in memory which allows detection of
errors in stored-data.
(ECC Error Checking Code, ESR Exception Service Routine).
45
• If an error occurs, control-hardware → detects the errors & → informs processor
by raising an interrupt.
46
2. Debugging
47
i) Trace
• When a processor is operating in trace-mode, an exception occurs after
execution of every instruction (using debugging-program as ESR).
• Debugging-program enables user to examine contents of registers,
memory-locations and so on.
• On return from debugging-program,next instruction in program being debugged
is executed, then debugging-program is activated again.
• The trace exception is disabled during the execution of the debugging-program.
48
ii) Breakpoints
• Here, the program being debugged is interrupted only at specific points selected
by user.
• An instruction called Trap (or Software interrupt) is usually provided for this
purpose.
• When program is executed & reaches breakpoint, the user can examine memory
& register contents.
49
3. Privilege Exception
• For e.g.
When processor runs in user-mode, it will not execute instruction that change
priority of processor.
50
DIRECT MEMORY ACCESS (DMA)
• The transfer of a block of data directly b/w an external device & main-memory
w/o continuous involvement by processor is called DMA.
• DMA controller → is a control circuit that performs DMA transfers (Figure 8.13).
→ is a part of the I/O device interface. → performs the functions that would
normally be carried out by processor.
• While a DMA transfer is taking place, the processor can be used to execute
another program.
51
52
• DMA interface has three registers (Figure 8.12):
53
54
• The R/W bit determines direction of transfer.
If R/W=1, controller performs a read-operation (i.e. it transfers data from memory
to I/O),
Otherwise, controller performs a write-operation (i.e. it transfers data from I/O to
memory).
• If Done=1, the controller → has completed transferring a block of data and → is
ready to receive another command. (IE Interrupt Enable).
• If IE=1, controller raises an interrupt after it has completed transferring a block of
data. • If IRQ=1, controller requests an interrupt.
55
• Requests by DMA devices for using the bus are always given higher priority
than processor requests.
• There are 2 ways in which the DMA operation can be carried out:
1) Processor originates most memory-access cycles. DMA controller is said to
"steal" memory cycles from processor. Hence, this technique is usually called
Cycle Stealing.
2) DMA controller is given exclusive access to main-memory to transfer a block of
data without any interruption. This is known as Block Mode (or burst mode).
56
BUS ARBITRATION
• The device that is allowed to initiate data-transfers on bus at any given time is
called bus-master.
• Bus Arbitration is the process by which → next device to become the bus-master
is selected & → bus-mastership is transferred to that device.
57
CENTRALIZED ARBITRATION
• A single bus-arbiter performs the required arbitration (Figure: 4.20).
• Normally, processor is the bus-master.
• Processor may grant bus-mastership to one of the DMA controllers.
• A DMA controller indicates that it needs to become bus-master by activating BR line.
• The signal on the BR line is the logical OR of bus-requests from all devices connected
to it.
• Then, processor activates BG1 signal indicating to DMA controllers to use bus when it
becomes free.
• BG1 signal is connected to all DMA controllers using a daisy-chain arrangement. • If
DMA controller-1 is requesting the bus,
58
Then, DMA controller-1 blocks propagation of grant-signal to other devices.
Otherwise, DMA controller-1 passes the grant downstream by asserting BG2.
• Current bus-master indicates to all devices that it is using bus by activating BBSY line.
• The bus-arbiter is used to coordinate the activities of all devices requesting memory
transfers.
• Arbiter ensures that only 1 request is granted at any given time according to a priority
scheme.
(BR Bus-Request, BG Bus-Grant, BBSY Bus Busy).
59
60
61
• The timing diagram shows the sequence of events for the devices connected to
the processor.
62
DISTRIBUTED ARBITRATION
63
64
For example:
Assume 2 devices A & B have their ID 5 (0101), 6 (0110) and their code is 0111.
Each device compares the pattern on the arbitration line to its own ID starting from MSB.
If the device detects a difference at any bit position, it disables the drivers at that bit position.
Driver is disabled by placing ”0” at the input of the driver.
In e.g. “A” detects a difference in line ARB1, hence it disables the drivers on lines ARB1 & ARB0.
This causes pattern on arbitration-line to change to 0110. This means that “B” has won
contention.
65
BUS
• Bus → is used to inter-connect main-memory, processor & I/O-devices →
includes lines needed to support interrupts & arbitration.
• Bus protocol is set of rules that govern the behavior of various devices
connected to the buses.
66
• A typical bus consists of 3 sets of lines:
1) Address,
2) Data &
3) Control lines.
67
• During data-transfer operation,
68
• The two approaches are:
1) Centralized Arbitration: A single bus-arbiter performs the required arbitration.
2) Distributed Arbitration: All devices participate in selection of next bus-master.
• A conflict may arise if both the processor and a DMA controller or two DMA controllers
try to use the bus at the same time to access the main-memory.
• To resolve this, an arbitration procedure is implemented on the bus to coordinate the
activities of all devices requesting memory transfers.
• The bus arbiter may be the processor or a separate unit connected to the bus.
69
• The processor must inform the device that its request has been recognized by
sending INTA signal.
70
SYNCHRONOUS BUS
71
A sequence of events during a read-operation
• At time t0, the master (processor) → places the device-address on address-lines
& → sends an appropriate command on control-lines (Figure 7.3).
• The command will → indicate an input operation & → specify the length of the
operand to be read.
• Information travels over bus at a speed determined by physical & electrical
characteristics.
• Clock pulse width(t1-t0) must be longer than max. propagation-delay b/w
devices connected to bus.
72
The clock pulse width should be long to allow the devices to decode the address &
control signals.
• The slaves take no action or place any data on the bus before t1.
• Information on bus is unreliable during the period t0 to t1 because signals are changing
state.
• Slave places requested input-data on data-lines at time t1.
• At end of clock cycle (at time t2), master strobes (captures) data on data-lines into its
input-buffer
• For data to be loaded correctly into a storage device, data must be available at input of
that device for a period greater than setup-time of device.
73
74
A Detailed Timing Diagram for the Read-operation
75
• The picture shows two views of the signal except the clock (Figure 7.4).
• One view shows the signal seen by the master & the other is seen by the salve.
• Master sends the address & command signals on the rising edge at the
beginning of clock period (t0).
76
• Sometimes later, at tAS the signals reach the slave.
• The slave decodes the address.
• At t1, the slave sends the requested-data.
• At t2, the master loads the data into its input-buffer.
• Hence the period t2, tDM is the setup time for the master‟s input-buffer.
• The data must be continued to be valid after t2, for a period equal to the hold
time of that buffers.
Disadvantages
• The device does not respond. • The error will not be detected.
77
Multiple Cycle Transfer for Read-operation
78
• During, clock cycle-1, master sends address/command info the bus requesting a
“read‟ operation.
• At the active edge of the clock i.e. the beginning of clock cycle-2, it makes
accession to respond immediately.
• The data become ready & are placed in the bus at clock cycle-3.
79
• At the same times, the slave asserts a control signal called slave-ready.
• The master strobes the data to its input-buffer at the end of clock cycle-3.
• And the master sends a new address to start a new transfer in clock cycle4.
80
ASYNCHRONOUS BUS
• This method uses handshake-signals between master and slave for coordinating
data-transfers.
81
The Read Operation proceeds as follows:
• At t0, master places address/command information on bus.
• At t1, master sets MR-signal to 1 to inform all devices that the
address/command-info is ready.
MR-signal =1 causes all devices on the bus to decode the address.
The delay t1 – t0 is intended to allow for any skew that may occurs on the bus.
Skew occurs when 2 signals transmitted from 1 source arrive at destination at
different time
Therefore, the delay t1 – t0 should be larger than the maximum possible bus skew.
82
• At t2, slave
• At t3, SR signal arrives at master indicating that the input-data are available on bus.
• At t5, when the device-interface receives the 1-to-0 transition of MR signal, it removes
data and SR signal from the bus. This completes the input transfer.
83
84
• A change of state is one signal is followed by a change is the other signal. Hence
this scheme is called as Full Handshake.
Dr Shreema Shetty
Dept CSE
SCEM
85
INTERFACE-CIRCUITS
• An I/O Interface consists of the circuitry required to connect an I/O device to a
computer-bus.
On the other side, we have a data path with its associated controls to transfer data
between the interface and the I/O device known as port.
86
• Communication with the bus is the same for both formats.
• The conversion from the parallel to the serial format, and vice versa, takes place
inside the interface circuit.
• In parallel-port, the connection between the device and the computer uses
• This arrangement is suitable for devices that are physically close to the
computer.
• In serial port, it is much more convenient and cost-effective where longer cables
are needed. Dr Shreema Shetty
Dept CSE
SCEM
87
Functions of I/O Interface
4) Generates the appropriate timing signals required by the bus control scheme.
88
PARALLEL-PORT
Dr Shreema Shetty
Dept CSE
89
SCEM
90
• The output of the encoder consists of
• Interface-circuits contain
2) Status-flag SIN.
91
When a key is pressed, the Valid signal changes from 0 to1.
Then, SIN=1 when ASCII code is loaded into DATAIN.
SIN = 0 when processor reads the contents of the DATAIN.
• The interface-circuit is connected to the asynchronous bus.
• Data transfers on the bus are controlled using the handshake signals:
1) Master ready &
2) Slave ready.
92
INPUT-INTERFACE-CIRCUIT
93
INPUT-INTERFACE-CIRCUIT
• Output-lines of DATAIN are connected to the data-lines of bus by means of
3-state drivers (Fig 4.29).
94
INPUT-INTERFACE-CIRCUIT
95
• SIN signal is generated using a status-flag circuit .
SIN signal is connected to line D0 of the processor-bus using a 3-state driver.
• Address-decoder selects the input-interface based on bits A1 through A31.
• Bit A0 determines whether the status or data register is to be read, when
Master-ready is active.
• Processor activates the Slave-ready signal, when either the Read-status or
Read-data is equal to 1.
96
PRINTER INTERFACE TO PROCESSOR
97
Dr Shreema Shetty
Dept CSE
98
SCEM
99
GENERAL 8 BIT PARALLEL PROCESSING
100
• Data-lines P7 through PO can be used for either input or output purposes (Figure 4.34).
• For increased flexibility,
→ some lines can be used as inputs and
→ some lines can be used as outputs.
• The DATAOUT register is connected to data-lines via 3-state drivers that are controlled
by a DDR.
• The processor can write any 8-bit pattern into DDR. (DDR Data Direction Register).
• If DDR=1,
Then, data-line acts as an output-line;
Otherwise, data-line acts as an input-line.
101
• Two lines, C1 and C2 are used to control the interaction between interface-circuit and
I/0 device.
Two lines, C1 and C2 are also programmable.
• Line C2 is bidirectional to provide different modes of signaling, including the handshake.
• The Ready and Accept lines are the handshake control lines on the processor-bus side.
Hence, the Ready and Accept lines can be connected to Master-ready and Slave-ready.
• The input signal My-address should be connected to the output of an address-decoder.
The address-decoder recognizes the address assigned to the interface.
• There are 3 register select lines: RS0-RS2.
Three register select lines allows up to eight registers in the interface.
• An interrupt-request INTR is also provided.
INTR should be connected to the interrupt-request line on the computer-bus.
102