Input Output IO Block Diagram of a Simple

Input / Output (I/O) § Block Diagram of a Simple Computer System: Processor Connected Devices keyboard system: mouse components? display I/O interact? printer objective? disk drives Computer System communication links § I/O Input / Output etc. • Info. exchange between computer and connected devices • independent I/O components associated with each connected device Bus 14 Nov-01 Memory 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 1

I/O Ports I/O Keyboard Components Bus . . . Communication Components Connected Devices keyboard mouse display printer disk drives communication links etc. § Ports: exchange information between bus and I/O components § ports identified by I/O addresses § port operations: read and/or write values • but not necessarily both! 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 2

Ports (contd) § I/O ports memory cells Just because a port might allow a value to be written to it DOES NOT mean that the port can have a value read from it (or vice versa!) § Port Categorization: • control ports: write values to these – this controls behaviour of component/device • status ports: read values from these – find out about current state of component/device • data ports: read and/or write values of these – exchange application information 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 3

I/O Components § Programmer’s Model of I/O Components: • how is external behaviour encoded in port values? • control write – how does this affect device? • status read – what can we learn about device? • read/write data ? format? § Example: Display via port 04 E 9 H § Model: display is cursor driven • write ASCII encoded character to data port • written character is displayed at current cursor position • cursor position is “advanced” • new lines and scrolling too 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 4

External Events § Programs must sometimes process events that occur at external devices e. g. : receive a character from keyboard § Two fundamental approaches: (paradigms!) 1. Polling • Program decides when to check devices for events • sequential paradigm! 201 (easy, simple) 2. Hardware Interrupts • I/O component tells program it is time to process event! • Event-driven paradigm 203, 301, 333, 361, 485 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 5

Polling § Polling: • poll: read some state variable(s) • polling loop: poll until a particular state exists § Example of a polling loop: while ( value_of_status_port != 010 B ) {empty body} § sometimes called busy waiting § processor is busy doing nothing (i. e. waiting) until event occurs at device § what happens if events occur at other devices while processor is busy waiting? (94. 203 ) 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 6

Keyboard - Control Port 7 Control Port 0 x x x x Keyboard: unused § Model: when key is pressed on device, ASCII encoded character associated with key is made available in keyboard (component) data port Control Port: Write-only at address 0000 H bit 0: 0 = disable interrupt, 1 = enable interrupt MOV AL, 0 B ; initialize keyboard MOV DX, 0 H always use never use OUT [ DX ] , AL this in 201 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 7

Keyboard – Status Port 7 0 0 0 1 0 “interrupt enabled bit” always 0 in 94. 201 unused – always 0 Status Port: “data ready” bit Read-only at address 0001 H § component sets bit 1 = 1 when a keystroke received from device. i. e. bit 1: 0 = no data ready, 1 = data ready at data port MOV DX, 1 H Poll. Loop: ; wait for key to be pressed IN AL, [ DX ] ; read status port AND AL, 010 B ; test data bit JZ Poll. Loop ; loop until data ready ; now read data! 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 8

Keyboard – Reading from Data Port: Read-only at address 0002 H § read this port to receive ASCII value of the “ready” data § reading this port causes keyboard component to clear bit 1 (i. e. force bit 1 = 0) in status port • NB: data is not ready when bit 1 = 0 § So don’t try to reread old data again! ; when data ready – read data from component MOV DX, 02 H IN AL, [ DX ] 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 9

Display § Display Device • 25 rows (0 – 24) by 40 columns (0 – 39) • 1000 screen elements • each element can display one character • text mode only • device is always ready • no polling, no interrupt § Two programmer’s models: • Mapped: every screen element has its own read/write data port • Non-Mapped: cursor-driven 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 10

Mapped Display Mapped Model § 1000 data ports § each one mapped to a unique screen element § linear data port address space: 0100 H – 04 E 7 H 0100 H [ row 0, col 0 ] 0101 H [ row 0, col 1 ] Programming. . . Problem: 0128 H [ row 1, col 0 ] How to calculate the. . . data port address for a 04 E 6 H [ row 24, col 38 ] given [ row, col ]? 04 E 7 H [ row 24, col 39 ] § Write ASCII value to port: char is displayed § Read from port: ASCII value of char displayed 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 11

Mapped Display (contd) Mapped Mode e. g. : § Subroutine to save current contents of display void Save. Screen ( char & Buff [ ]) Pass by reference where Buff is a 1000 element array of bytes Save. Screen: PUSH BP MOV BP, SP ; save other reg’s used PUSH. . . ; set up loop to copy from screen MOV DX, 0100 H ; DX = port address MOV BX , [ BP + 4 ] ; BX = array pointer MOV SI, 0 ; SI = counter & index 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 12

Mapped Display (contd) ; loop to copy value from screen to Buff Get. Char: IN AL, [ DX ] ; get char from display MOV [ BX + SI ], AL ; save char in Buff ADD DX, 1 ; advance to next char ADD SI, 1 ; advance into Buff CMP SI, 1000 ; if more char’s to save JB Get. Char ; then save them ; clean up and go! POP. . . ; pop reg’s saved POP BP RET 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 13

Non-mapped Display Model : Cursor-driven display (used in assignments) Control Port: write-only @ 04 E 8 H 7 3 2 1 0 x x b 3 b 2 b 1 b 0 home = upper left corner § § b 0 b 1 b 2 b 3 unused 0 = no effect 1 = clear screen 1 = move cursor to home position = [ row 0 , col 0 ] 1 = cursor to column 0 of current row 1 = cursor one row down, same column if cursor was on line 24, then scroll one line up 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 14

Non-mapped Display (contd) Data Port: Write-only @ 04 E 9 H § discussed previously Cursor Data Ports: read / write § can read and change (write) cursor position § Cursor X (column) @ 04 EAH range: 0. . 39 § Cursor Y (row) @ 04 EBH range: 0. . 24 Non-Mapped Mode Example: Subroutine to display entire screen of data void Up. Date. Screen ( char & Buff [ ]) Buff is a 1000 element array of bytes 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 15

MOV DX, 04 E 8 H ; DX = port address MOV AL , 010 B ; AL = home cursor OUT [ DX ] , AL ; set up loop to copy from Buff to screen MOV DX, 04 E 9 H ; DX = port address MOV BX , [ BP + 4 ] ; BX = array pointer MOV SI, 0 ; SI = counter & index Do. Char: MOV AL , [ BX + SI ] ; get char from Buff OUT [DX] , AL ; display char ADD SI, 1 ; advance into Buff CMP SI, 1000 ; if more char’s to save JB Do. Char ; then save them 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 16

Unmapped Display Example (contd) (Rest of unmapped example as before in mapped example) § Bug in example? • write to last position on screen? • scroll? § Extensions to Non-Mapped Mode: • should probably include ability to: • turn on/off display of cursor • turn on/off auto-wrap & auto-scroll § Extend using more bits in control port! 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 17

Timer Device § Programs must often manage time • i. e. the computer systems’ objective includes meeting timing constraints § what is time? § Some examples: • Animation – motion is timing dependent • Changing display after fixed time – e. g. clear a dialog box • Turn a LED on/off – e. g. floppy disk access light 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 18

Timer Loops Various schemes are used to manage time, often involve hardware/software tradeoffs Timing loop: software-only solution § based on execution speed of processor § loop “counts” to waste time (busy waiting) e. g. for ( int i = 0; i < 10000; i++ ) { for (int j = 0; j < 10000; j++) { } // empty body } Advantage: simple: no explicit h/w involved Disadvantage: execution speed varies on different machines – not very portable (Download old DOS games ? ? ) 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 19

Timer via Hardware Often have hardware dedicated to managing time § Typically: no external device – just internal component § oscillator circuit generates “ticks” at a known frequency – e. g. square wave at some frequency § tick signal input to timer component § timer “counts” ticks in some way § since frequency of ticks is known, then counting a fixed number represents the passage of a known amount of time counts ticks Timer Component tick signal known frequency 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 20

Hardware Timer (contd) § Programmer’s Model of Timer Component • Timer maintains 16 -bit counter value • Can read/write using two 8 -bit data ports • Timer decrements counter every tick • Status: done bit – set (1) when counter reaches 0 • Control: start timer, stop timer, clear done bit • For counting periodic time intervals: – Read/Write using two 8 -bit ports – Control: copy 16 bit reload value to counter 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 21

Model of Hardware Timer software interface via ports control status data 16 -bit Reload Value known frequency (cycles per sec) 16 -bit Counter (decrements) 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 22

Timer § 8 -bit ports provided by timer component: Timer Control Port: write-only at address: 0010 H bit 0 0 = disable interrupt always use 1 = enable interrupt this in 201 bit 1 0 = no effect 1 = clear count done bit (bit 1 of status port) bits 3 & 2 0 0 = no change in operation 0 1 = copy reload value to counter and start timing 1 0 = stop timing 1 1 = start timing from current counter value bits 4 - 7 unused (writing to these bits has no effect) 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 23

Timer (contd) Timer Status Port: read-only at address 0011 H bit 0 0 = interrupt disabled always “disabled” in 94. 201 1 = interrupt enabled bit 1 0 = count not yet done 1 = count done bit 2 0 = timer stopped (i. e. not counting input pulses) 1 = timer timing (i. e. counting input pulses) bits 3 - 7 unused (always return 0) 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 24

Timer (contd) § TIMER Reload Value Lo: address: 0012 H read/write low byte of reload value § TIMER Reload Value Hi: address: 0013 H read/write high byte of reload value § TIMER Current Value Lo: address: 0014 H read/write low byte of current counter value § TIMER Current Value Hi: address: 015 H read/write high byte of current counter value 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 25

Timer Example Suppose we wish to perform “some processing” every second, and assume 1 second = 10000 timer ticks. ; initialize the timer MOV DX, 10 H ; Control port MOV AL, 1000 B ; stop timer OUT [DX], AL MOV AX, 10000 ; Set up Reload value : = 10000 MOV DX, 012 H ; set low byte of reload value OUT [DX], AL MOV DX, 13 H MOV AL, AH ; set high byte of reload value OUT [DX], AL 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 26

Timer Example (contd) Once_A_Second_Loop: MOV DX, 10 H ; TIMER Control MOV AL, 0110 B ; clear count done, copy reload OUT [DX], AL ; value to counter & start timing <do once-a-second processing here > ; poll until timer finished one second MOV DX, 11 H ; TIMER Status port Wait_More: IN AL, [DX] ; get status AND AL, 10 B ; check count done bit JZ Wait_More ; if not done, try again! JMP Once_A_Second_Loop 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 27

Screen Saver Example § Normal operation: display has application specific contents – mode = normal § If time between key presses exceeds some value then enter mode = screen saved mode is used to organize • save contents of screen behaviour - system & cursor coordinates behaves differently in • clear display different modes • When next key pressed: – read and discard keystroke data – restore: contents of screen, cursor position – return to mode = normal 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 28

Aside: Timer Abstraction § hardware/software “box” § simplifies use of timer § hides details of timer § software interface void Init. Reload( unsigned int Count ); • initialize: Reload value : = Count void Pause. Timer ( ); • stop, does not change counter void Start. Timer ( ); • clear done bit, start (current counter value) void Reload. Timer( ); • Counter : = Reload; clear done bit, start boolean. Time. Out ( ); • returns true (AL != 0) if timer has timed out • returns false (AL = 0) if timer has not timed out 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 29

Aside: Timer Abstraction (contd) H/W & S/W details are hidden inside “box” Init. Reload Pause. Timer. . . Time. Out Timer Abstraction “Box” 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 30

Screen Saver Example (contd) Back to Screen Saver Example: § program must initialize and start Timer MOV AX, count_value PUSH AX CALL Init. Reload ADD SP, 2 CALL Reload. Timer § program must poll timer to see if time to save screen § may have to poll from several places in program (overcome this in 94. 203 ) § where is a good place to poll timer ? • while “busy waiting” for keystrokes ! 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 31

char Read. Key ( ); §polls until a key is pressed Read. Key Algorithm: §reads and returns keystroke data done = false; Do // do loop terminates on next slide if ( key ready) { // poll for keystroke first new_key = read key; Reload. Timer; if ( mode = = screen saved) { restore screen; mode = normal; } // not done yet! discard key ! else { // mode was normal already done = true; // return new_key!} } // end of if ( key ready) 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 32

Screen Saver Example (contd) <still in do loop!> // have dealt with case where key is ready if ( mode = = normal ) { if ( Time. Out ) { Pause. Timer; // needed ? ? save screen; mode = screen saved; clear screen; } } while ( ! done ); // end of do-loop return ( new_key ); 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 33

Screen Saver Example (contd) Implementation: § Assume the following Data Variables: § Mode: DB 0 ; 0 = normal, 1 = screen saved § Cursor. X: DB Hmmm. . need to reserve 1000 § Cursor. Y: DB char buffer… § Buffer: DB ; 1000 character buffer Assume we can call routines: void Save. Screen( char & Buffer, int Cursor. X, int Cursor. Y ); void Restore. Screen( char & Buffer, int Cursor. X, int Cursor. Y ); Read. Key: ; no param’s – no need to set up BP <save reg’s used, but not AX> 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 34

Screen Saver Example (contd) Do. Loop: ; poll keyboard MOV DX, 01 H ; keyboard status port IN AL, [ DX ] AND AL, 010 B ; key ready? JZ No. Key. Ready ; keystroke ready! – read key MOV DX, 02 H ; keyboard data port IN AL, [ DX ] ; AL = new_key PUSH AX ; save new_key CALL Reload. Timer CMP BYTE PTR [ Mode ], 1 ; screen saved? JNE Done ; if no – then done! 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 35

Screen Saver Example (contd) ; have read key while screen saved – restore screen via ; void Restore. Screen( char & Buff, int cursor. X, int Cursor. Y ); MOV AX, Cursor. Y PUSH AX MOV AX, Cursor. X PUSH AX MOV AX, Buffer PUSH AX CALL Restore. Screen ADD SP, 6 MOV BYTE PTR [Mode], 0 ; mode = normal POP AX ; discard new_key !!! 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 36

No. Key. Ready: ; time to save screen ? CMP BYTE PTR [ Mode ], 0 ; normal? JNE Do. Loop CALL Time. Out CMP AL, 1 ; timed out ? JNE Do. Loop MOV PUSH CALL ADD 14 Nov-01 AX, Cursor. Y AX AX, Cursor. X AX AX, Buffer AX Save. Screen SP, 6 ; yes, save the screen 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 37

Screen Saver Example (contd) ; have just saved screen – update mode MOV BYTE PTR [ Mode ], 1 ; clear screen CALL Clear. Screen JMP Do. Loop Done: POP AX ; return new_key. . . ; restore registers used RET 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 38

Other I/O Devices – Issues to consider § § § § § What is the programmer’s model? external interactions at device? purpose of component/device? relevant state variables? how do ports and values at ports relate to component/device behaviour? encoding? control, status and data values? port addresses? read and/or write ? time implications? 94. 203 is the time taken by the component/device to respond to events relevant to programming? • delay from external events to port values? • delay for internal events to be sent to device? 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 39

I/O Issues (contd) § byte vs. block oriented transfers • byte: one data byte at a time • processor handles individual byte transfers • block: set up a buffer • component handles individual byte transfers § Example: Printer • byte vs. block oriented? § Control: • put printer on/off-line • page eject • reset • self-test 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 40

Status: • on/off-line? • paper jam? • out of paper? • out of ink? • printer ready/busy? • self-test pass/fail? Data: • encoded: ASCII text, graphics? § time delays? • write data printer busy printer ready • page eject printer busy printer ready • reset printer busy printer ready 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 41

A/D Converter (Analog to Digital Converter) § input = analog signal § computer cannot process analog signal § must convert to “digital” value § represent analog signal at a point in time by an encoded binary value § computer can then work with binary values that represent analog values § encoding scheme depends on reference point 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 42

A/D Converter (8 -bit) Signal Value e. g. temperature Analog smax s 2 s 1 sn Max = FFH … tn t 1 t 2 smin Digital Outputs 14 Nov-01 time Min = 00 H Sampling Times: t 2 -t 1=delta t 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 43

A/D Converter Analog Signal Digital Output Value X+1 Possible Digital X Output X-1 Values Sampling Request 14 Nov-01 Time 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 44

A/D Example -Temperature Sensor § input = temperature dependent analog signal • typically scaled between max and min analog values • max corresponds to temp = tempmax • min corresponds to temp = tempmin • suppose 8 -bit digital values • digital reading = 00 H tempmin, FFH tempmax • reading of xx. H can be interpreted as temperature temp = ( xx. H (tempmax – tempmin ) / FFH ) + tempmin § control: start taking reading § status: busy/ reading ready § data: 8 -bit? more? accuracy? jitter? time delays? start reading busy reading ready 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 45

A/D Example (contd) § Sample and Process A/D Input Periodically initialize timer while ( true ) { Request a snapshot reload and start timer start A/D conversion Converter prepares output poll until A/D data ready read A/D data Application dependent process A/D data poll until timeout Wait for rest of delta t } 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 46

D/A Converter § § D/A Converter (Digital to Analog) device outputs analog signal control ? status • busy/ready § data • write data starts conversion § time delays • write data busy ready § What if write new data while converter busy? 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 47

A Block-Oriented Device Example Communication Transmitter § wish to transmit a buffer of data bytes across some medium § program deals with message level – blocks of bytes § h/w deals with byte-level § component/device handle all details of medium and transmitting data § Program must: • set up block of data bytes in buffer • pass buffer to component • tell component to send 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 48

Block Oriented Device (contd) Passing buffer to component: options? § where is buffer stored while accessed by component? 1. processor givescomponent one data byte at a time • component must have local memory • essentially a byte-oriented approach? • redundant? inefficient? component transfers component processor gives bytes out to device data one byte internal at a time memory 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 49

Block Oriented Device (contd) 2. processor loads component with pointer to buffer • component must be able to read from memory • component reads bytes from memory and transfers bytes out to device • bus contention? component reads bytes from memory and transfers bytes out to device processor loads data Component into buffer in memory 14 Nov-01 Component has “direct memory access” (DMA) 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 50

Block Oriented Device (contd) § Both options exist in practice! § hardware / software tradeoffs! Consider Option 2: load component with pointer to buffer § status • busy / ready § start transfer • select protocol? § data • buffer address – 16 -bit, write • buffer length? – write • assume buffer fixed size? terminator? 14 Nov-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 25 -30 -io 51
- Slides: 51