Presentation is loading. Please wait.

Presentation is loading. Please wait.

Homework Reading Labs Tokheim, Section 13-6 S and S Extracts

Similar presentations


Presentation on theme: "Homework Reading Labs Tokheim, Section 13-6 S and S Extracts"— Presentation transcript:

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

2 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

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

4 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 inb outw outb

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

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

7 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

8 Addressing I/O Devices
COM port addresses (Neveln, Table 4.2) * corrects an error in the text COM Port I/O Addresses 1 0x3F8-0x3FF 2 0x2F8-0x2FF 3 0x3E8-0x3EF 4 0x2E8-0x2EF *

9 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

10 Serial Ports (COM1: and COM2:)
EIA RS-232C interface same connector as LPT1: COM1: a DB-9 connector on back of computer with a subset of the RS-232C signals (sufficient for async use) Requires a conversion cable (DB9 - DB25) to connect a PC to a standard RS-232C 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) 13 1 25 14 5 1 9 6

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

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

13 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 DTR DTR DSR DSR RTS Analog signals on phone line RTS CTS CTS Remote Access Server PC DCD Modem Modem DCD RI RI TXD TXD RXD RXD GND GND

14 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 DTR DSR DSR RTS RTS CTS CTS DCD DCD GND GND TXD TXD RXD RXD (RI not normally needed)

15 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 ASCII character sent With LSB first in time Optional Parity Bit Arbitrary time since last character sent Bit value = 0 +12V D0 D1 D2 D3 D4 D5 D6 D7 -12V Bit value = 1 One Start Bit One or Two Stop Bits Bit Duration = 1 / Bit Rate

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

17 Accessing the Serial Port
PC specification allows up to four serial ports COM1: base address is 0x3f8 COM2: base address is 0x2f8 Write Read 0x3f8 D7 D6 D5 D4 D3 D2 D1 D0 D7 D6 D5 D4 D3 D2 D1 D0 0x3fb Set Brk Stk Par Evn Par Par Enb # Stop Len Sel 1 Len Sel 0 DLAB Same as Write 0x3fc Loop Out2 Out1 RTS DTR Same as Write - - - 0x3fd RX ERR TX EMP THRE BRK Int FRM ERR PAR ERR OVRN ERR Data RDY - - - 0x3fe DCD CHG TE RI DSR CHG CTS CHG DCD RI DSR CTS

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

19 Accessing the Serial Port
Don’t want to use hard coded numbers! Look at $pcinc/serial.h for symbolic constants #define COM1_BASE 0x3f8 #define COM2_BASE 0x2f8 #define UART_TX 0 /* send data */ #define UART_RX 0 /* recv data */ . . . #define UART_LCR 3 /* line control */ #define UART_MCR 4 /* modem control */ #define UART_LSR 5 /* line status */ #define UART_MSR 6 /* modem status */

20 Accessing the Serial Port
Examples: Send an ‘A’ out on COM2: (port mtip connected to) ps 2f8 41 (ASCII A = 0x41) And you will see: ATutor> (Character A then prompt) Read a character from COM2: pd 2f8 02f c1 03 0b ff ff ff ff ff ff ff ff

21 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 < 0xFFFF Unsigned char is the 8-bit character Example for COM2: outpt(0x2F8, 0x41);

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

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

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

25 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 D0-D7 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 One Handshake Cycle D0-D7 (from PC) Byte N-1 2 (Data valid for Byte N) 2 Byte N+1 * * * Strobe# (from PC) 5 3 5 3 * * * Busy (from Prtr) 4 1 1 * * *

26 Accessing Parallel Port
IBM defines up to three parallel port addresses We will use “LPT1:” with 0x378 as base address Base used to send data to printer (D0-D7) 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 to set all data output bits to zeros Write Read 0x378 D7 D6 D5 D4 D3 D2 D1 D0 D7 D6 D5 D4 D3 D2 D1 D0 0x379 - - - Bsy# Ack# PE SL Err# IRQ 0x37a D IQ SI IN# AF ST D IQ SI IN# AF ST

27 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 < 0xFFFF Unsigned char is the 8-bit character Example: outpt(0x378, 0xFF);

28 Accessing the Parallel Port
Examples: Note that status port address is “read only” pd 378 F E ps F E {has effect on 378} ps F E {no effect on 379}

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

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

31 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)

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

33 Status Polling Loop on send/receive data to/from COM2:
(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

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

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

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

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

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

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


Download ppt "Homework Reading Labs Tokheim, Section 13-6 S and S Extracts"

Similar presentations


Ads by Google