Скачать презентацию Homework Reading Tokheim Section 13 -6 Скачать презентацию Homework Reading Tokheim Section 13 -6

fc6b106a748edb586fe55326381b5a66.ppt

  • Количество слайдов: 39

Homework • Reading – Tokheim, Section 13 -6 – Sargent and Shoemaker Extracts – Homework • Reading – Tokheim, Section 13 -6 – Sargent and Shoemaker Extracts – National Semiconductor UART Data Sheet • Labs – Continue labs with your assigned section 1

I/O Devices • Examples of I/O Devices – Serial ports – Parallel ports – I/O Devices • Examples of I/O Devices – Serial ports – Parallel ports – Floppy, Zip, and hard disk controllers – CD-ROM/CD-RW/DVD controllers – Keyboard Interface – Mouse Interface • Variations do not change the architecture 2

Accessing I/O Devices • Can’t do it under Unix – Why not? • Can Accessing I/O Devices • Can’t do it under Unix – Why not? • Can do it on the SAPCs – Why? • SAPCs allow us to learn about accessing I/O devices from “hands-on” experience 3

Addressing I/O Devices • Intel I/O devices have addresses assigned in an “orthogonal” space Addressing I/O Devices • Intel I/O devices have addresses assigned in an “orthogonal” space from memory addresses – Remember the M/IO# signal that is used with the address bus to select memory versus I/O devices? • Use I/O instructions for I/O device addresses inw outw inb outb 4

Addressing I/O Devices • The “input” instruction – direct addressing inw $0 xdd, %ax Addressing I/O Devices • The “input” instruction – direct addressing inw $0 xdd, %ax inb $0 xdd, %al # # 8 bit address • The “input” instruction – indirect addressing movw $0 x 3 f 8, %dx inw (%dx), %ax # 16 bit address inb (%dx), %al # 16 bit address • Reads from an I/O device to a register 5

Addressing I/O Devices • The “output” instruction – direct addressing outw %ax, $0 xdd Addressing I/O Devices • The “output” instruction – direct addressing outw %ax, $0 xdd outb %al, $0 xdd # # 8 bit address • The “output” instruction – indirect addressing movw $0 x 3 f 8, %dx outw %ax, (%dx) # 16 bit address outb %al, (%dx) # 16 bit address • Writes from a register to an I/O device 6

Addressing I/O Devices • In some processor architectures (Motorola), there is no M/IO# signal Addressing I/O Devices • In some processor architectures (Motorola), there is no M/IO# signal in the control bus • This is called using “memory mapped I/O” – I/O device addresses are in the same address space as memory – I/O device ports are accessed as memory addresses – Use equivalent of “move” instructions to write or read data to or from I/O device registers as memory 7

Addressing I/O Devices • COM port addresses (Neveln, Table 4. 2) COM Port 1 Addressing I/O Devices • COM port addresses (Neveln, Table 4. 2) COM Port 1 2 3 4 I/O Addresses 0 x 3 F 8 -0 x 3 FF 0 x 2 F 8 -0 x 2 FF 0 x 3 E 8 -0 x 3 EF 0 x 2 E 8 -0 x 2 EF * * corrects an error in the text 8

I/O Devices • We’ll discuss 2 types of I/O devices in detail: – Serial I/O Devices • We’ll discuss 2 types of I/O devices in detail: – Serial ports – Parallel ports • Covering the following aspects: – Physical connectors – Overview of interface electronics – Handshake procedures – I/O addresses assigned – Programming procedures 9

Serial Ports (COM 1: and COM 2: ) • EIA RS-232 C interface same Serial Ports (COM 1: and COM 2: ) • EIA RS-232 C interface same connector as LPT 1: 13 1 25 14 • COM 1: a DB-9 connector on back of computer with a subset of the RS-232 C signals (sufficient for async use) 5 1 9 6 • Requires a conversion cable (DB 9 - DB 25) to connect a PC to a standard RS-232 C device such as analog modem • “RS-232” level signals +3 to +15 volts is considered a logic 0 - 3 to - 15 volts is considered a logic 1 (Note: + 12 and -12 are voltages usually used) 10

Serial Port • DB 9 Pin Out • • • Pin 1 Pin 2 Serial Port • DB 9 Pin Out • • • Pin 1 Pin 2 Pin 3 Pin 4 Pin 5 Pin 6 Pin 7 Pin 8 Pin 9 Data Carrier Detect (DCD) Receive Data (RXD) Transmit Data (TXD) Data Terminal Ready (DTR) Signal Ground Data Set Ready (DSR) Request to Send (RTS) Clear to Send (CTS) Ring Indicator (RI) Input Output --Input Output Input • Single wire for sending data and single wire for receiving data plus return path (i. e. , ground) • Multiple control and status signals 11

Serial Port • The “inside story” on a serial port: Control Bus (M/IO# and Serial Port • The “inside story” on a serial port: Control Bus (M/IO# and W/R#) Address Bus (16 bits) To/From Processor Chip +5 V Transmit Data Receive Data National 16450 / 16550 4 Status Lines Called a UART 2 Control Lines (“You-art”) Ground Reference Data Bus (up to 32 bits) Physical Connector +12 V EIA-423 Drivers and Receivers -12 V 12

Serial Port Handshake • Connecting PC to an access server via a pair of Serial Port Handshake • Connecting PC to an access server via a pair of modems • Control / Status Lines (two straight-through cables) – – – Data Terminal Ready indicates that PC is on and ready Data Set Ready indicates that modem is on and ready With Request to Send, PC tells modem to turn on its carrier With Clear to Send, the modem indicates that carrier is on With Data Carrier Detect, the modem indicates carrier seen With Ring Indicator, modem indicates incoming call PC DTR DSR RTS CTS DCD RI TXD RXD GND Modem Analog signals on phone line Modem DTR DSR RTS CTS DCD RI TXD RXD GND Remote Access Server 13

Serial Port Handshake • Connecting two PCs via a NULL modem cable – Behaves Serial Port Handshake • Connecting two PCs via a NULL modem cable – Behaves like a pair of modems – Control / status lines are “cross-connected” – Transmit and receive data are “cross-connected” DTR DSR RTS CTS DCD GND TXD RXD (RI not normally needed) DTR DSR RTS CTS DCD GND TXD RXD 14

Serial Port Handshake • Bits are sent on TXD and RXD serially (one at Serial Port Handshake • Bits are sent on TXD and RXD serially (one at a time) – Bit Rate needs to be specified – When the sequence starts and stops has to be specified – How the bits are serialized has to be specified Arbitrary time since last character sent ASCII character sent With LSB first in time Optional Parity Bit value = 0 +12 V D 0 D 1 D 2 D 3 D 4 D 5 D 6 D 7 Bit value = 1 -12 V One Start Bit One or Two Stop Bits Bit Duration = 1 / Bit Rate 15

Parallel Serial Conversion • UART performs double buffered, bidirectional, parallel-to-serial / serial-to-parallel conversion: Overrun Parallel Serial Conversion • UART performs double buffered, bidirectional, parallel-to-serial / serial-to-parallel conversion: Overrun Error Data Ready Receive Holding Register Receive Shift Register RXD (Serial) Data Bus (Parallel) TXD (Serial) THRE TX Empty Transmit Holding Register Transmit Shift Register 16

Accessing the Serial Port • PC specification allows up to four serial ports – Accessing the Serial Port • PC specification allows up to four serial ports – COM 1: base address is 0 x 3 f 8 – COM 2: base address is 0 x 2 f 8 Write 0 x 3 f 8 Read D 7 D 6 D 5 D 4 D 3 D 2 D 1 D 0 0 x 3 fb DLAB Set Brk 0 x 3 fc 0 0 Stk Par Evn Par # Len Par Enb Stop Sel 1 Sel 0 Same as Write 0 Loop Out 2 Out 1 RTS DTR Same as Write 0 x 3 fd --- 0 x 3 fe --- RX TX THRE BRK FRM PAR OVRN Data ERR EMP Int ERR ERR RDY DCD RI DSR CTS DCD TE DSR CTS CHG RI CHG 17

Accessing the Serial Port • PC specification allows up to four serial ports – Accessing the Serial Port • PC specification allows up to four serial ports – COM 1: base address is 0 x 3 F 8 – COM 2: base address is 0 x 2 F 8 – Each has up to eight port addresses – Usually use six of these addresses • • Base: Base+1 Base+2: Base+3: Base+4: Base+5: Base+6: Receive buffer on read / Transmit buffer on write Interrupts and FIFO buffer Interrupt ID Line control (set up by Tutor for us) Modem control Line status Modem Status 18

Accessing the Serial Port • Don’t want to use hard coded numbers! • Look Accessing the Serial Port • Don’t want to use hard coded numbers! • Look at $pcinc/serial. h for symbolic constants #define. . . #define COM 1_BASE COM 2_BASE UART_TX UART_RX 0 x 3 f 8 0 x 2 f 8 0 /* send data */ 0 /* recv data */ UART_LCR UART_MCR UART_LSR UART_MSR 3 4 5 6 /* /* line control */ modem control */ line status */ modem status */ 19

Accessing the Serial Port • Examples: – Send an ‘A’ out on COM 2: Accessing the Serial Port • Examples: – Send an ‘A’ out on COM 2: (port mtip connected to) ps 2 f 8 41 (ASCII A = 0 x 41) – And you will see: ATutor> (Character A then prompt) – Read a character from COM 2: pd 2 f 8 – And you will see: 02 f 8 00 00 c 1 03 0 b 00 00 00 ff ff 20

Accessing the Serial Port • Port access support for C programs – Can use Accessing the Serial Port • Port access support for C programs – Can use functions specific to the PC – We have our own library ($pcinc/cpu. h) • Look at example $pcex/echo. c • Function prototypes are in cpu. h void outpt(int port, unsigned char outbyte); unsigned char inpt(int port); – Port address < 0 x. FFFF – Unsigned char is the 8 -bit character – Example for COM 2: outpt(0 x 2 F 8, 0 x 41); 21

Accessing the Serial Port • Construct addresses using symbolic constants unsigned char status; outpt(COM Accessing the Serial Port • Construct addresses using symbolic constants unsigned char status; outpt(COM 1_BASE + UART_TX, ‘A’); status = inpt(COM 1_BASE + UART_LSR); 22

Parallel Port (LPT 1: ) • LPT 1: a DB 25 connector on back Parallel Port (LPT 1: ) • LPT 1: a DB 25 connector on back of computer 13 25 – – 1 14 Data appears on pins 2 -9 Control/Status on pins 1 & 10 -17 Pins 18 -25 are ground “TTL” level signals • 0 -1 volts is considered low and a logic 0 • 3 -5 volts is considered high and a logic 1 • Very simple interface to understand use – Provides 8 bits of output (one byte at a time) – No transformation of data – Simple handshake protocol 23

Parallel Port • The “inside story” on a parallel port: Control Bus (M/IO# and Parallel Port • The “inside story” on a parallel port: Control Bus (M/IO# and W/R#) Address Bus (16 bits) Physical Connector +5 V 8 Data Lines (D 0–D 7) To/From Processor Chip Interface LSI Chip(s) 5 Status Lines (Busy) 4 Control Lines (Strobe#) Ground Reference Lines Data Bus (up to 32 bits) 24

Parallel Port Printer Handshake • Data byte sent to parallel data port (all 8 Parallel Port Printer Handshake • Data byte sent to parallel data port (all 8 bits at once) 1. Printer indicates ready for next data byte (Busy = 0) 2. PC sets up data bits on data lines D 0 -D 7 3. PC tells printer that data is ready Strobe# = 0 4. Printer acknowledges or “acks” (Busy = 1) and takes data 5. PC sets Strobe# =1 to be ready for next cycle Signals on Pins D 0 -D 7 (from PC) Strobe# (from PC) Busy (from Prtr) One Handshake Cycle Byte N-1 5 2 (Data valid for Byte N) 3 1 2 5 4 Byte N+1 3 1 *** *** 25

Accessing Parallel Port • IBM defines up to three parallel port addresses • We Accessing Parallel Port • IBM defines up to three parallel port addresses • We will use “LPT 1: ” with 0 x 378 as base address – Base used to send data to printer (D 0 -D 7) – Base+1 used to get status byte (with MSB = Busy# signal) – Base+2 used for control (with LSB = Strobe signal) • Can access parallel port using Tutor ‘ps’ command – ps 378 FF to set all data output bits to ones – ps 378 0 to set all data output bits to zeros Write Read 0 x 378 D 7 D 6 D 5 D 4 D 3 D 2 D 1 D 0 0 x 379 --- 0 x 37 a D IQ SI Bsy#Ack# PE SL Err# IRQ IN# AF ST D IQ SI IN# AF ST 26

Accessing Parallel Port • Port access support for C programs – Can use functions Accessing Parallel Port • Port access support for C programs – Can use functions specific to the PC – We have our own library ($pcinc/cpu. h) • Look at example $pcex/testlp. c • Function prototypes are in $pcinc/cpu. h void outpt(int port, unsigned char outbyte); unsigned char inpt(int port); – Port address < 0 x. FFFF – Unsigned char is the 8 -bit character – Example: outpt(0 x 378, 0 x. FF); 27

Accessing the Parallel Port • Examples: – Note that status port address is “read Accessing the Parallel Port • Examples: – Note that status port address is “read only” pd 378 00 7 F E 0. . . ps 378 55 pd 378 0378 55 7 F E 0. . . {has effect on 378} ps 379 66 pd 378 0378 55 7 F E 0. . . {no effect on 379} 28

Accessing the Parallel Port • Don’t want to use hard coded numbers! • Look Accessing the Parallel Port • Don’t want to use hard coded numbers! • Look at $pcinc/lp. h for symbolic constants #define LPT 1_BASE LP_DATA LP_STATUS LP_CNTRL 0 x 378 0 /* 8 bits of data */ 1 /* in: status bits */ 2 /* in, out: control bits*/ • Construct addresses using symbolic constants unsigned char cntrl, status; outpt(LPT 1_BASE + LP_CNTRL, cntrl); status = inpt(LPT 1_BASE + LP_STATUS); 29

Strategies for I/O Driver Code • Two Basic Strategies for I/O Driver Code – Strategies for I/O Driver Code • Two Basic Strategies for I/O Driver Code – Status Polling – Interrupt Driven • Status Polling – Uses only the port addresses on the I/O device – Ties up the entire processor for the duration of I/O • Interrupt Driven – Adds an interrupt line from I/O device to processor – Allows processor to do other work during I/O 30

Status Polling • Review the serial port details: – Status and Control Registers • Status Polling • Review the serial port details: – Status and Control Registers • We will look at assembly language driver to send and receive data in “full duplex” mode – Half Duplex – Sending or receiving alternately (data going only one direction at a time) – Full Duplex – Sending and receiving at same time (data going both directions simultaneously) 31

Initializing the UART • Tutor does this for us on COM 1: and COM Initializing the UART • Tutor does this for us on COM 1: and COM 2: – Select speed, data bits, parity, and number of stop bits – Turn on DTR and wait for DSR on • Half duplex modem signal handshake: – Transmit: Turn on RTS and wait for CTS on – Receive: Turn off RTS and wait for DCD on • Full duplex modem signal handshake: – Turn on RTS and leave it on – Transmit whenever CTS on – Receive whenever DCD on 32

Status Polling • Loop on send/receive data to/from COM 2: (Assume Tutor has initialized Status Polling • Loop on send/receive data to/from COM 2: (Assume Tutor has initialized bit rate and line control) 1. Turn on DTR & RTS, wait for DSR, CTS, & DCD 2. Read data ready (DR) 3. If data is ready, read a byte of receive data 4. Read transmit holding register empty (THRE) 5. If THR is empty, write a byte of transmit data 6. Jump back to step 2 • Processor loop is much faster than byte transfer rate • But, hard to do other work while looping on status 33

Status Polling Assembly Code • Step 1 a: Turn on DTR and RTS movw Status Polling Assembly Code • Step 1 a: Turn on DTR and RTS movw inb orb outb $0 x 2 fc, %dx (%dx), %al $0 x 03, %al, (%dx) # # modem control get current or on 2 lsbs set control 34

Status Polling Assembly Code • Step 1 b: Wait for DSR, CTS, and DCD Status Polling Assembly Code • Step 1 b: Wait for DSR, CTS, and DCD movw $0 x 2 fe, loop 1: inb (%dx), andb $0 xb 0, xorb $0 xb 0, jnz loop 1 # all 3 are on %dx # modem status %al # get current %al # get 3 signals %al # check all 3 # some missing now 35

Status Polling Assembly Code • Step 2: Read Data Ready • Step 3: If Status Polling Assembly Code • Step 2: Read Data Ready • Step 3: If ready, read a byte from receive data loop 2: movw inb andb jz movw inb movw $0 x 2 fd, %dx (%dx), %al $0 x 01, %al xmit # if $0 x 2 f 8, %dx (%dx), %al, somewhere $0 x 2 fd, %dx # line status # get data ready # look at dr recv data # i/o data addr # move rx to %al # save it somewhere # line status 36

Status Polling Assembly Code • Step 4: Read transmit holding register empty • Step Status Polling Assembly Code • Step 4: Read transmit holding register empty • Step 5: If empty, write a byte to transmit data xmit: inb andb jz movb movw outb jmp (%dx), %al $0 x 20, %al loop 2 somewhere, %al $0 x 2 f 8, %dx %al, (%dx) loop 2 # # # # get thre look at thre if tx hr empty get data to send i/o data addr send it and loop 37

COM Port Driver in C - Receive #include <serial. h> void unsigned char pollgetc() COM Port Driver in C - Receive #include void unsigned char pollgetc() { /* polling loop, waiting for DR bit to go on */ while ((inpt(COM 1_BASE + UART_LSR) & UART_LSR_DR) == 0) ; /* input character */ return inpt(COM 1_BASE + UART_RX); } 38

COM Port Driver in C - Transmit #include <serial. h> void pollputc(unsigned char ch) COM Port Driver in C - Transmit #include void pollputc(unsigned char ch) { /* polling loop, waiting for THRE bit to go on */ while ((inpt(COM 1_BASE + UART_LSR) & UART_LSR_THRE) == 0) ; /* output character */ outpt(COM 1_BASE + UART_TX, ch); } 39