72
UNIT 3 Input and Output System

UNIT 3 Input and Output System

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: UNIT 3 Input and Output System

UNIT 3Input and Output System

Page 2: UNIT 3 Input and Output System

External Devices

• I/O operations are done using different externaldevices also called as I/O Module, that provide ainterface for exchanging data between the externalenvironment and the computer.

• An external device attaches to the computer by a linkto an I/O module.

• The link is used to exchange control, status, and databetween the I/O module and the external device.

• An external device connected to an I/O module is oftenreferred to as a Peripheral Device or, simply, aPeripheral.

2R. V. Bidwe, PICT, Pune.

Page 3: UNIT 3 Input and Output System

3R. V. Bidwe, PICT, Pune.

Page 4: UNIT 3 Input and Output System

• Peripherals are of three categories:

1. Human readable: Suitable for communicating withthe computer user.

Eg. Printers, Video Display Terminals (VDTs).

2. Machine readable: Suitable for communicating withequipment.

Eg. Magnetic Disks or tapes, Sensors, Actuators.

3. Communication: Suitable for communicating withremote devices.

Eg. Devices which allow a computer to exchange data with a remotedevice, which may be a human-readable device, a machinereadable device, or even another computer. (Routers, Servers)

4R. V. Bidwe, PICT, Pune.

Page 5: UNIT 3 Input and Output System

How I/O Module works?

• Data transfer using I/O Module, involvesfollowing steps:

1. The processor tells the I/O module to check thestatus of the attached device.

2. The I/O module returns the device status.

3. If the device is operational and ready to transmit,the processor requests the transfer of data, bymeans of a command to the I/O module.

4. The I/O module obtains a unit of data (e.g., 8 or 16bits) from the external device.

5. The data are transferred from the I/O module to theprocessor.

R. V. Bidwe, PICT, Pune. 5

Page 6: UNIT 3 Input and Output System

I/O Modules: Module Function

• The major functions or requirements for anI/O module fall into the following categories:

• Control and Timing

• Processor Communication

• Device Communication

• Data Buffering

• Error Detection

6R. V. Bidwe, PICT, Pune.

Page 7: UNIT 3 Input and Output System

• Control and Timing:

– During any period of time, the processor maycommunicate with one or more external devices,depending on the program’s need for I/O.

– The internal resources, such as main memory and thesystem bus, must be shared among a number ofactivities, including data I/O.

– It is required to coordinate the flow of trafficbetween internal resources and external devices.

R. V. Bidwe, PICT, Pune. 7

Page 8: UNIT 3 Input and Output System

• Processor Communication:It involves the following:

– Command Decoding: The I/O module acceptscommands from the processor, decodes commandto appropriate signals, and send signals toperipheral through control bus. For example, anI/O module for a disk drive might accept thefollowing commands: READ SECTOR, WRITESECTOR, SEEK track number, and SCAN record ID.

– Data: Data are exchanged between the processorand the I/O module over the data bus.

R. V. Bidwe, PICT, Pune. 8

Page 9: UNIT 3 Input and Output System

– Status Reporting: Because peripherals are so slowcompared to processor, it is important to knowthe status of operation. For example, if an I/Omodule is asked to send data to the processor(read), it may not be ready to do so because it isstill working on the previous I/O command.

– Address Recognition: Each I/O device have aaddress which is used to recognize particularperipheral. Thus, an I/O module must recognizeone unique address for each peripheral it controls.

R. V. Bidwe, PICT, Pune. 9

Page 10: UNIT 3 Input and Output System

• Device Communication: The I/O module must beable to perform Communication in betweendifferent peripherals. This communication involvescommands, status information, and data.

• Data Buffering: The I/O module must be able tobuffer data during data operations.

• Error Detection: An I/O module is often responsiblefor error detection and for subsequently reportingerrors to the processor.

R. V. Bidwe, PICT, Pune. 10

Page 11: UNIT 3 Input and Output System

I/O Module Structure

R. V. Bidwe, PICT, Pune. 11

Page 12: UNIT 3 Input and Output System

Techniques for I/O Operations

• There are three different techniques

1. Programmed I/O

2. Interrupt Driven I/O

3. Direct Memory Access

R. V. Bidwe, PICT, Pune. 12

Page 13: UNIT 3 Input and Output System

• Programmed I/O

– Data are exchanged between the processor and theI/O module.

– The processor executes a program that gives it directcontrol of the I/O operation, including sensing devicestatus, sending a read or write command, andtransferring the data.

– When the processor issues a command to the I/Omodule, it must wait until the I/O operation iscomplete. If the processor is faster than the I/Omodule, this is wasteful of processor time.

R. V. Bidwe, PICT, Pune. 13

Page 14: UNIT 3 Input and Output System

• Interrupt-driven I/O

– The processor issues an I/O command, itcontinues doing its own work. When peripheral isready, receive an interrupt and start working.

• Disadvantage of Programmed I/O andInterrupt-driven I/O:– With both programmed and interrupt I/O, The

processor is responsible for data operations. SoProcessor is continuously used in such operations.

R. V. Bidwe, PICT, Pune. 14

Page 15: UNIT 3 Input and Output System

• Direct Memory Access (DMA)

– In this mode, the data operations are donewithout processor involvement.

R. V. Bidwe, PICT, Pune. 15

Page 16: UNIT 3 Input and Output System

R. V. Bidwe, PICT, Pune. 16

Page 17: UNIT 3 Input and Output System

Programmed I/O

• When the processor is executing a program andencounters an instruction relating to I/O, itexecutes that instruction by issuing a commandto the appropriate I/O module.

• With programmed I/O, the I/O module willperform the requested action and then set theappropriate bits in the I/O status register.

• The I/O module takes no further action to alertthe processor. In particular, it does not interruptthe processor.

R. V. Bidwe, PICT, Pune. 17

Page 18: UNIT 3 Input and Output System

• Thus, it is the responsibility of the processorperiodically to check the status of the I/Omodule until it finds that the operation iscomplete.

• To explain the programmed I/O technique, weview it first from the point of view of the I/Ocommands issued by the processor to the I/Omodule, and then from the point of view of theI/O instructions executed by the processor.

R. V. Bidwe, PICT, Pune. 18

Page 19: UNIT 3 Input and Output System

Programmed I/O: I/O Commands

• Control: Used to activate a peripheral and tell it whatto do.

• Test: Used to test various status conditions associatedwith an I/O module and its peripherals.

• Read: Causes the I/O module to obtain an item of datafrom the peripheral and place it in an internal buffer.

• Write: Causes the I/O module to take an item of data(byte or word) from the data bus and subsequentlytransmit that data item to the peripheral.

R. V. Bidwe, PICT, Pune. 19

Page 20: UNIT 3 Input and Output System

Programmed I/O: I/O Instructions

• Processor gives commands to I/O module throughspecial instructions.

• Typically, there will be many I/O devices connectedthrough I/O modules to the system.

• Each device is given a unique identifier or address.

• When the processor issues an I/O command, thecommand contains the address of the desired device.

R. V. Bidwe, PICT, Pune. 20

Page 21: UNIT 3 Input and Output System

• When the processor, main memory, and I/Oshare a common bus, two modes ofaddressing are possible:

1. Memory Mapped I/O

2. Isolated I/O

R. V. Bidwe, PICT, Pune. 21

Page 22: UNIT 3 Input and Output System

• Memory - Mapped I/O:

– In this configuration same address space is used forboth memory and I/O.

– In such scenarios the devices (I/O) are treated as apart of the memory only.

– There are no specific I/O instructions. It allows thecomputer to used the same instructions for both I/Otransfers and memory transfers.

– Some instructions are memory reference instructionsand others are I/O reference.

– They are only one set of read/write control signals.R. V. Bidwe, PICT, Pune. 22

Page 23: UNIT 3 Input and Output System

• Isolated I/O:

– The isolated I/O configuration separates all I/Ointerface addresses from the memory addresses.

– The devices of I/O are treated in a separatedomain as compared to memory.

– In the isolated I/O configuration, the CPU hasdistinct input and output instructions.

– In isolated I/O configuration the memory addressand I/O address have its own address space.

R. V. Bidwe, PICT, Pune. 23

Page 24: UNIT 3 Input and Output System

R. V. Bidwe, PICT, Pune. 24

Page 25: UNIT 3 Input and Output System

R. V. Bidwe, PICT, Pune. 25

Page 26: UNIT 3 Input and Output System

Programmed I/O: Problem

• The processor has to wait a long time till I/Omodule gives status of peripheral for eitherreception or transmission of data.

• The processor, while waiting, must repeatedlycheck the status of the I/O module.

• As a result, the level of the performance of theentire system is severely degraded.

R. V. Bidwe, PICT, Pune. 26

Page 27: UNIT 3 Input and Output System

Interrupt-Driven I/O

• An alternative to programmed I/O is Interrupt-drivenI/O.

• Here the processor to issue an I/O command to amodule and then go on to do some other useful work.

• The I/O module will then interrupt the processor torequest service when it is ready to exchange data withthe processor.

• The processor then executes the data transfer.

R. V. Bidwe, PICT, Pune. 27

Page 28: UNIT 3 Input and Output System

How it works?

• Fig 7.4 (b), slide no 16.

R. V. Bidwe, PICT, Pune. 28

Page 29: UNIT 3 Input and Output System

Interrupt Processing

R. V. Bidwe, PICT, Pune. 29

Page 30: UNIT 3 Input and Output System

Interrupt-Driven I/O: Design Issues

1. Because there will almost invariably be multipleI/O modules, how does the processordetermine which device issued the interrupt?

– Solution:

1. Multiple Interrupt Lines

2. Software Poll

3. Daisy Chain (Hardware Poll, Vectored)

4. Bus Arbitration (Vectored)

R. V. Bidwe, PICT, Pune. 30

Page 31: UNIT 3 Input and Output System

2. If multiple interrupts have occurred, howdoes the processor decide which one toprocess?

• Give priority to interrupt.

• Methods:

–Polling

–Hardware can be used

R. V. Bidwe, PICT, Pune. 31

Page 32: UNIT 3 Input and Output System

Case Study: 8259

• 8259 is Programmable Interrupt Controller (PIC).

• It is connected to 8086 to manage complexinterrupt systems.

• It manages interrupt requests as per priority ofinterrupts.

• 8259 act as a multiplexer, combining multipleinterrupt input sources into single interruptrequest to the processor.

R V Bidwe, PICT, Pune. 32

Page 33: UNIT 3 Input and Output System

• 8259 is a very flexible peripheral controllerchip:

– It supports eight input interrupt requests fromperipherals and issues a single interrupt signal toprocessor.

– PIC can deal with up to 64 interrupt inputs bycascading eight 8259’s together.

– Various priority schemes can also programmed.

R V Bidwe, PICT, Pune. 33

Page 34: UNIT 3 Input and Output System

Why 8259?

R V Bidwe, PICT, Pune. 34

Page 35: UNIT 3 Input and Output System

R V Bidwe, PICT, Pune. 35

Page 36: UNIT 3 Input and Output System

Interfacing 8259 with Microprocessor and other devices

R V Bidwe, PICT, Pune. 36

Devices may be Slave 8259’s.

Page 37: UNIT 3 Input and Output System

R V Bidwe, PICT, Pune. 37

Block Diagram : 8259

Page 38: UNIT 3 Input and Output System

❚ Data bus buffer: bidirectional D0-D7 bus, it is connected tothe processor.

❚ R/W Logic: Using these pins 8259 is interfaced withprocessors.

❚ Cascade buffer/ comparator: These logic allows for cascadingmultiple 8259 controller in Master-Slave configuration.

R V Bidwe, PICT, Pune. 38

Page 39: UNIT 3 Input and Output System

❚ Three types of Registers:

1. IRR (Interrupt Request Register): It storesinterrupt requests. Interrupt lines (IR0-IR7)goes high, when it accepts interrupt, andstore it accordingly.

2. IMR (Interrupt Mask Register): This logic blockmasks the interrupt lines based onprogramming by the processor. It preventsmasked interrupt lines by interrupting theprocessor.

3. ISR (In Service Register): It stores all interruptlevels that are currently being serviced.

R V Bidwe, PICT, Pune. 39

Page 40: UNIT 3 Input and Output System

❚Priority resolver: Determine the interruptpriority of the active interrupt inputs.

❚ Control Logic: It contains two pins,

1. INTR : It is output pin used to interrupt theCPU.

2. INTA(#): Through this pin 8259 getacknowledgement for INT signal.

R V Bidwe, PICT, Pune. 40

Page 41: UNIT 3 Input and Output System

Pin Diagram: 8259

R V Bidwe, PICT, Pune. 41

Page 42: UNIT 3 Input and Output System

R V Bidwe, PICT, Pune. 42

Page 43: UNIT 3 Input and Output System

R V Bidwe, PICT, Pune. 43

Page 44: UNIT 3 Input and Output System

R V Bidwe, PICT, Pune. 44

Page 45: UNIT 3 Input and Output System

R V Bidwe, PICT, Pune. 45

Page 46: UNIT 3 Input and Output System

R V Bidwe, PICT, Pune. 46

Page 47: UNIT 3 Input and Output System

Drawbacks of Programmed and Interrupt-Driven I/O

• Interrupt-driven I/O, simple programmed I/Oboth requires active participation of Processor indata transfer process.

• Thus, both these forms of I/O suffer from twoinherent drawbacks:1. The I/O transfer rate is limited by the speed with

which the processor can test and service a device.

2. The processor is tied up in managing an I/Otransfer, as number of instructions must beexecuted for each I/O transfer.

R. V. Bidwe, PICT, Pune. 47

Page 48: UNIT 3 Input and Output System

DMA Introduction• Direct Memory Access (DMA) is a method of

allowing data to be moved from one location toanother in a computer without involving the centralprocessor (CPU).

• It is also a fast way of transferring data within (andsometimes between) computer.

• The device requests CPU (through a DMA controller)to Hold its data, address bus and control bus, so thatdevice may transfer data to/from memory.

• DMA transfer is only initiated only after receivingHLDA signal from CPU.

48R V Bidwe, PICT, Pune.

Page 49: UNIT 3 Input and Output System

CPU DMA Peripherals

49R V Bidwe, PICT, Pune.

Page 50: UNIT 3 Input and Output System

How DMA works

R. V. Bidwe, PICT, Pune. 50

Page 51: UNIT 3 Input and Output System

DMA Terminologies

• DMA channel: System pathway used by adevice to transfer information directly to andfrom memory. There are usually 8 channels ina computer system.

• DMA controller: Dedicated hardware used forcontrolling the DMA operation.

• Single-cycle mode: DMA data transfer is doneone byte at a time.

• Burst-mode: DMA transfer is finished when alldata has been moved.

51R V Bidwe, PICT, Pune.

Page 52: UNIT 3 Input and Output System

How DMA Works?

• It is a Different Module on a system.

• In data transfers, we can use this withoutinvolving Processor.

• DMA uses system bus to do data transferoperations. So, the DMA module must use thebus only when

– The processor does not need it.– It must force the processor to suspend operation

temporarily.R. V. Bidwe, PICT, Pune. 52

Page 53: UNIT 3 Input and Output System

• Eg. The processor wishes to read or write a block ofdata through DMA module. Then processor issuesDMA module the following information:

– Whether a read or write is requested, using the RD(#) orWR(#) line between the processor and the DMA module.

– The address of the I/O device involved, communicated onthe Data Lines.

– The starting location in memory to read from or write to,communicated on the data lines and stored by the DMAmodule in its Address Register.

– The number of words to be read or written, againcommunicated via the data lines and stored in the DataCount Register. R. V. Bidwe, PICT, Pune. 53

Page 54: UNIT 3 Input and Output System

Typical DMA Block Diagram

R. V. Bidwe, PICT, Pune. 54

Page 55: UNIT 3 Input and Output System

DMA with Processor for System Bus

• Two control signals are used to request andacknowledge a Direct Memory Access (DMA)transfer in the microprocessor-based system.

– The HOLD signal as an input(to the processor) isused to request a System bus.

– The HLDA signal as an output that acknowledges theavailability of system bus.

• When the processor recognizes the HOLD, itstops its execution and enters hold cycles.

55R V Bidwe, PICT, Pune.

Page 56: UNIT 3 Input and Output System

The 8237 DMA Controller

• The 8237 supplies memory & I/O, the Controlsignals, Memory address information andData during the DMA transfer.

• It is actually a Special-purposeMicroprocessor whose job is high-speed datatransfer between memory and I/O.

• It gives better performance than 8257.

56R V Bidwe, PICT, Pune.

Page 57: UNIT 3 Input and Output System

• It is able to transmit bulk of data between systemmemory and peripherals and vice versa.

• Memory to memory data transfer is also available.

• It supports four independent DMA channels whichmay be expanded to any number by cascading morenumber of 8237.

• Distinctive feature is that, it provides manyProgrammable Control and ability of DynamicReconfiguration features which enhances datatransfer rate of system.

57R V Bidwe, PICT, Pune.

Page 58: UNIT 3 Input and Output System

Block Diagram 8237

58R V Bidwe, PICT, Pune.

Page 59: UNIT 3 Input and Output System

R. V. Bidwe, PICT, Pune. 59

Page 60: UNIT 3 Input and Output System

8237 Internal Registers

CAR• The Current Address Register holds a 16-bit

memory address used for the DMA transfer.

CWCR

• The Current Word Count Register programs achannel for the number of bytes to transferredduring a DMA action.

60R V Bidwe, PICT, Pune.

Page 61: UNIT 3 Input and Output System

CR

• The Command Register programs theoperation of the 8237 DMA controller.

• The register uses Bit Position 0 to select thememory-to-memory DMA transfer mode.

– Memory-to-Memory DMA transfers use DMAchannel 0 to hold the source address.

– DMA channel 1 holds the destination address.

61R V Bidwe, PICT, Pune.

Page 62: UNIT 3 Input and Output System

BA and BWC

• The Base Address (BA) and Base WordCount (BWC) registers are used to hold theBase Address value and Initial Count valueof a transfer. Also used when auto-initialization is selected for a channel.

• In Auto-initialization Mode, these registersare used to reload the CAR and CWCRValues.

62R V Bidwe, PICT, Pune.

Page 63: UNIT 3 Input and Output System

63

• The Mode Register programs the mode ofoperation for a channel.

• Each channel has its own mode register asselected by Bit Positions 1 And 0.

– Bits of the mode register select Operation,Auto-initialization, Increment/Decrement, andMode for the channel.

MR

R V Bidwe, PICT, Pune.

Page 64: UNIT 3 Input and Output System

64

• The Bus Request Register is used to requesta DMA transfer via software.– very useful in memory-to-memory transfers, where an

external signal is not available to begin the DMA transfer.

MRSR

• The Mask Register Set/Reset sets or clears thechannel mask.– if the mask is set, the channel is disabled.– the RESET signal sets all channel masks

to disable them.

BR

R V Bidwe, PICT, Pune.

Page 65: UNIT 3 Input and Output System

65

• The Mask Register clears or sets all ofthe masks with one command instead ofindividual channels, as with the MRSR.

MSR

R V Bidwe, PICT, Pune.

Page 66: UNIT 3 Input and Output System

66

• The Status Register shows status of eachDMA channel. The TC bits indicate if thechannel has reached its Terminal Count(transferred all its bytes).

• When the terminal count is reached, theDMA controller will enter in a Burst Mode.

SR

R V Bidwe, PICT, Pune.

Page 67: UNIT 3 Input and Output System

Master clear

• Acts exactly the same as the RESET signal tothe 8237.

– As with the RESET signal, this command disables allchannels

Clear Mask Register

• Enables all four DMA channels.

67R V Bidwe, PICT, Pune.

Page 68: UNIT 3 Input and Output System

Clear The First/Last Flip-flop

• Clears the first/last (F/L) flip-flop within 8237.

• The F/L flip-flop selects which byte (low or highorder) is read/written in the current address andcurrent count registers.– if F/L = 0, the low-order byte is selected.

– if F/L = 1, the high-order byte is selected.

• Any read or write to the address or count registerautomatically toggles the F/L flip-flop.

Page 69: UNIT 3 Input and Output System

I/O Channels and Processors

• The Evolution of the I/O Function

R. V. Bidwe, PICT, Pune. 69

Page 70: UNIT 3 Input and Output System

The Evolution of the I/O Function

1. The CPU directly controls a peripheral device. This isseen in simple microprocessor- controlled devices.

2. A controller or I/O module is added. The CPU usesProgrammed I/O without interrupts. With this step,the CPU becomes somewhat divorced from thespecific details of external device interfaces.(Programmable I/O)

3. The same configuration as in step 2 is used, but nowinterrupts are employed. The CPU need not spendtime waiting for an I/O operation to be performed,thus increasing efficiency. (Interrupt-driven I/O)

R. V. Bidwe, PICT, Pune. 70

Page 71: UNIT 3 Input and Output System

4. The I/O module is given direct access to memoryvia DMA. It can now move a block of data to orfrom memory without involving the CPU, exceptat the beginning and end of the transfer.

5. The I/O module is enhanced to become aprocessor in its own right, with a specializedinstruction set tailored for I/O.

The CPU directs the I/O processor to executean I/O program in memory. The I/O processorfetches and executes these instructions withoutinvolving CPU.

This allows the CPU to specify a sequence ofI/O activities and to be interrupted only when theentire sequence has been performed.

R. V. Bidwe, PICT, Pune. 71

Page 72: UNIT 3 Input and Output System

6. The I/O module has a local memory of its ownand is, in fact, a computer in its own right.

With this architecture, a large set of I/Odevices can be controlled, with minimal CPUinvolvement.

A common use for such an architecture hasbeen to control communication with interactiveterminals. The I/O processor takes care of most ofthe tasks involved in controlling the terminals.

R. V. Bidwe, PICT, Pune. 72