Io Module5
Io Module5
Outline
• Introduction • External interface
• Accessing I/O devices Serial transmission
• An example I/O device Parallel interface
Keyboard • USB
• I/O data transfer Motivation
Programmed I/O USB architecture
DMA USB transactions
• Error detection and • IEEE 1394
correction Advantages
Parity encoding
Transactions
Error correction
Bus arbitration
CRC
Configuration
Introduction
• I/O devices serve two main purposes
To communicate with outside world
To store data
• I/O controller acts as an interface between the
systems bus and I/O device
Relieves the processor of low-level details
Takes care of electrical interface
• I/O controllers have three types of registers
Data
Command
Status
Introduction (cont’d)
Introduction (cont’d)
• To communicate with an I/O device, we need
Access to various registers (data, status,…)
» This access depends on I/O mapping
– Two basic ways
Memory-mapped I/O
Isolated I/O
A protocol to communicate (to send data, …)
» Three types
– Programmed I/O
– Direct memory access (DMA)
– Interrupt-driven I/O
Accessing I/O Devices
• I/O address mapping
Memory-mapped I/O
» Reading and writing are similar to memory read/write
» Uses same memory read and write signals
» Most processors use this I/O mapping
Isolated I/O
» Separate I/O address space
» Separate I/O read and write signals are needed
» Pentium supports isolated I/O
– 64 KB address space
Can be any combination of 8-, 16- and 32-bit I/O
ports
– Also supports memory-mapped I/O
Accessing I/O Devices (cont’d)
• Accessing I/O ports in Pentium
Register I/O instructions
in accumulator, port8 ; direct format
– Useful to access first 256 ports
in accumulator,DX ; indirect format
– DX gives the port address
Block I/O instructions
» ins and outs
– Both take no operands---as in string instructions
» ins: port address in DX, memory address in ES:(E)DI
» outs: port address in DX, memory address in ES:(E)SI
» We can use rep prefix for block transfer of data
An Example I/O Device
• Keyboard
Keyboard controller scans and reports
– Key depressions and releases
» Supplies key identity as a scan code
– Scan code is like a sequence number of the key
Key’s scan code depends on its position on the
keyboard
No relation to the ASCII value of the key
Interfaced through an 8-bit parallel I/O port
» Originally supported by 8255 programmable peripheral
interface chip (PPI)
An Example I/O Device (cont’d)
• 8255 PPI has three 8-bit registers
» Port A (PA)
» Port B (PB)
» Port C (PC)
These ports are mapped as follows
8255 register Port address
PA (input port) 60H
PB (output port) 61H
PC (input port) 62H
Command register 63H
An Example I/O Device (cont’d)
Mapping of 8255 I/O ports
An Example I/O Device (cont’d)
• Mapping I/O ports is similar to mapping memory
Partial mapping
Full mapping
cont’d
External Interface (cont’d)
External Interface (cont’d)
• SCSI uses client-server model
Uses terms initiator and target for client and server
» Initiator issues commands to targets to perform a task
– Initiators are typically SCSI host adaptors
» Targets receive the command and perform the task
– Targets are SCSI devices like disk drives
• SCSI transfer proceeds in phases
Command
Message in IN and OUT from
Message out the initiator point
Data in
of view
Data out
Status
External Interface (cont’d)
SCSI uses asynchronous mode for all bus negotiations
» Uses handshaking using REQ and ACK signals for each byte
of data
On a synchronous SCSI
» Data are transferred synchronously
» REQ-ACK signals are not used for each byte
» A number of bytes (e.g., 8) can be sent without waiting for
ACK
– Improves throughput
– Minimizes adverse impact of cable propagation delay
USB
• Universal Serial Bus
Originally developed in 1995 by a consortium including
» Compaq, HP, Intel, Lucent, Microsoft, and Philips
USB 1.1 supports
» Low-speed devices (1.5 Mbps)
» Full-speed devices (12 Mbps)
USB 2.0 supports
» High-speed devices
– Up to 480 Mbps (a factor of 40 over USB 1.1)
» Uses the same connectors
– Transmission speed is negotiated on device-by-device basis
USB (cont’d)
• Motivation for USB
Avoid device-specific interfaces
» Eliminates multitude of interfaces
– PS/2, serial, parallel, monitor, microphone, keyboard,…
Avoid non-shareable interfaces
» Standard interfaces support only one device
Avoid I/O address space and IRQ problems
» USB does not require memory or address space
Avoid installation and configuration problems
» Don’t have to open the box to install and configure jumpers
Allow hot attachment of devices
USB (cont’d)
• Additional advantages of USB
Power distribution
» Simple devices can be bus-powered
– Examples: mouse, keyboards, floppy disk drives, wireless
LANs, …
Control peripherals
» Possible because USB allows data to flow in both directions
Expandable through hubs
Power conservation
» Enters suspend state if there is no activity for 3 ms
Error detection and recovery
» Uses CRC
USB (cont’d)
USB cables
USB (cont’d)
• USB encoding
Uses NRZI encoding
» Non-Return to Zero-Inverted
USB (cont’d)
• NRZI encoding
A signal transition occurs if the next bit is zero
» It is called differential encoding
Two desirable properties
» Signal transitions, not levels, need to be detected
» Long string of zeros causes signal changes
Still a problem
» Long strings of 1s do not causes signal change
To solve this problem
» Uses bit stuffing
– A zero is inserted after every six consecutive 1s
USB (cont’d)
Bit stuffing
USB (cont’d)
• Transfer types
» Four types of transfer
Interrupt transfer
» Uses polling
– Polling interval can range from 1 ms to 255 ms
Isochronous transfer
» Used in real-time applications that require constant data
transfer rate
– Example: Reading audio from CD-ROM
» These transfers are scheduled regularly
» Do not use error detection and recovery
USB (cont’d)
Control transfer
» Used to configure and set up USB devices
» Three phases
– Setup stage
Conveys type of request made to target device
– Data stage
Optional stage
Control transfers that require data use this stage
– Status stage
Checks the status of the operation
» Allocates a guaranteed bandwidth of 10%
» Error detection and recovery are used
– Recovery is by means of retries
USB (cont’d)
Bulk transfer
» For devices with no specific data transfer rate
requirements
– Example: sending data to a printer
» Lowest priority bandwidth allocation
» If the other three types of transfers take 100% of the
bandwidth
– Bulk transfers are deferred until load decreases
» Error detection and recovery are used
– Recovery is by means of retries
USB (cont’d)
• USB architecture
USB host controller
» Initiates transactions over USB
Root hub
» Provides connection points
Two types of host controllers
» Open host controller (OHC)
– Defined by Intel
» Universal host controller (UHC)
– Specified by National Semiconductor, Microsoft, Compaq
» Difference between the two
– How they schedule the four types of transfers
USB (cont’d)
• UHC scheduling
Schedules periodic transfers first
» Periodic transfers: isochronous and interrupts
» Can take up to 90% of bandwidth
• OHC scheduling
Different from UHC scheduling
Reserves space for non-periodic transfers first
» Non-periodic transfers: control and bulk
» 10% bandwidth reserved
Upstream port
Downstream ports
USB (cont’d)
• USB transactions
Transfers are done in one or more transactions
» Each transaction consists of several packets
Transactions may have between 1 and 3 phases
» Token packet phase
– Specifies transaction type and target device address
» Data packet phase (optional)
– Maximum of 1023 bytes are transferred
» Handshake packet phase
– Except for isochronous transfers, others use error detection
for guaranteed delivery
– Provides feedback on whether data has been received
without error
USB (cont’d)
USB IRP frame
USB (cont’d)
Hardware encoded
special pattern