Professional Documents
Culture Documents
Joe Flynn
Questra Corporation
jflynn@questra.com
(716)381-0260
Outline
?USB Overview
?USB Hardware Controllers
?Architecture of an Embedded USB Device
?USB Device Driver Architecture
?Case Study of a USB Device Driver
?Testing Strategies
?Issues to consider
?Conclusions
1
USB Overview
?Hardware Overview
–Topology
?Protocol Characteristics
–Packet Types
–USB Transactions
?Enumeration
–Enumeration States
Hardware Overview
Mic
?Physical Layer
– 2-wire differential signaling, NRZI
Mouse Speaker Mic
2
The Transaction Protocol is Host Based
Packet Types
3
A Typical USB Transaction Consists
of Three Packets
Idle
DATA0/
DATA0/ T/O NAK STALL DATA0/
DATA0/ DATA0
Data DATA
DATA 1
1 DATA1
DATA1
Idle
T/O
Idle
Host Function
4
The Basic USB Model has Several
Layers of Abstraction
Host Client SW
Function Device
manages an
Interface a collection
x of
interface
Endpoint 0 Interfaces
- Required, shared
Pipe Bundle Interface
- Configuration access Buffers No USB
to an
No USB
Format Specific Format
- Capability control interface
USB Device
USB System a collection
Endpoint
manages devices Zero of
Default endpoints
Pipe to
Data Endpoint Zero Data Per USB
Unspecified Framed
Endpoint
USB Bus Interface
Data
Host USB Bus
Cntrl USB Framed
Data Interface
SIE
Transactions SIE
USB Wire
Pipe, connection abstraction
between two horizontal layers
Data transport mechanism
USB-relevant format of transported data
?Attached State
–Entered by attaching USB Cable
?Powered State
–USB Host Applies power
?Default state
–USB Host resets bus
?Addressed State
–USB Host sends Set Address with non-zero address
?Configured state
–USB Host sends Set Configuration with non-zero
value
?Suspended state
–USB Host stops sending SOF for 3 msec
10
5
The Device State Machine
Hub
Configured Bus Activity
Reset
Attached Powered Suspended
Bus Activity
Hub Reset Idle Bus
or Deconfigured
Default Suspended
Reset
Idle Bus
11
Query Change
Reset Device
Default
Get Device Descriptor via Default Pipe and Address
Addr.
Addr.
Assigned
Read All Configuration Information
Configure and Assign Configuration Value
Configured
12
6
Outline
?USB Overview
?USB Hardware Controllers
?Architecture of an Embedded USB Device
?USB Device Driver Architecture
?Case Study of a USB Device Driver
?Testing Strategies
?Issues to consider
?Conclusions
13
?Discrete Components
–NetChip,
NetChip, Intel, National Semiconductor, Phillips
?USB IP Cores as part of an ASIC
–Sand, Motorola, Texas Instruments, .etc
?Combination USB Host and USB Peripheral chip
–ScanLogic
?Combination micro-processor and USB Core
–8/16 bit processor Mitsubishi, .etc
?Single Chip Solutions
–Netchip NET1031 Single chip scanner controller.
14
7
USB Controller Hardware Architecture
?USB Core
?Registers for Control and Endpoint Data
Transfer
?FIFO Controller
–Input and Output FIFOs for Control Endpoint
–Input or Output FIFO for other Endpoints
?DMA Controller
?Internal Bus
?Serial Interface Engine
?Output Pads
15
USB Pads
16
8
Key Features of a USB Controller
18
9
Outline
?USB Overview
?USB Hardware Controllers
?Architecture of an Embedded USB Device
?USB Device Driver Architecture
?Case Study of a USB Device Driver
?Testing Strategies
?Issues to consider
?Conclusions
19
API API
Driver
Fifo Fifo
20
10
System Architecture
ISR
Thread
USB Protocol
Thread
Main Thread
USB Controller
Hardware
File System
Thread
21
?ISR Thread
–Low Level Interrupt Service routine(s)
•USB Controller Interrupt
•DMA Controller Interrupt
?USB Protocol Thread
–Task which implements USB Protocol
•Control, Bulk, Isochrnous,
Isochrnous, Interrupt Endpoints
•Attach/Dettach
Attach/Dettach,, SOF, Suspend/Resume
?Main Thread
–Thread which executes the product application
–Calls and is triggered by Callback from USB Driver
layer
?File System Thread
–Lower Priority File System Thread
22
11
Interrupt Sources
?SOF
?Attach/Dettach
Attach/Dettach
?Suspend/Resume
?Setup Packet
?Data IN Ack
?Data OUT Ack
?FIFO Empty or Low level threshold met
?FIFO Full or High level threshold met
?DMA Complete
23
Driver/Hardware Enumeration
Architecture
Embedded Application
Enumeration Routines
ISR, Descriptor structures USB Driver
Hardware
24
12
Single Thread Architecture
Embedded Application
Main Thread, Class/Vendor Requests
Enumeration
USB Driver
Hardware
25
USB Driver
Hardware
26
13
Outline
?USB Overview
?USB Hardware Controllers
?Architecture of an Embedded USB Device
?USB Device Driver Architecture
?Case Study of a USB Device Driver
?Testing Strategies
?Issues to consider
?Conclusions
27
Endpoint Data
Control Protocol
Attach/ Status Transfer Protocols
Power - Standard Requests
Detach & - Bulk In/Out
Management - Class Requests
Processing Control - Isochronous In/Out
- Vendor Requests
- Interrupt In/Out
Clock DMA
USB Driver Low Level Access Methods and ISRs
Driver Driver
28
14
USB Device Driver Architecture
Callback
Driver Interface Function
UsbIsr
29
?USBInit()
USBInit()
?USBDelete()
USBDelete()
?USBOpen()
USBOpen()
?USBClose()
USBClose()
?USBRead()
USBRead()
?USBWrite()
USBWrite()
?USBIoctl()
USBIoctl()
30
15
USBInit()
USBInit() and USBDelete()
USBDelete()
?USBInit()
USBInit() - Initialize USB Driver
–Installs driver in IO system
–Creates or acquires OS resources
•Semaphores, queues, ISR vector, task, memory, etc.
–Initializes USB Controller hardware
–Enable USB Controller to allow enumeration
?USBDelete()
USBDelete() - Delete USB Driver
–Disable USB Controller Hardware
–Return OS resources
•Semaphores, queues, ISR vector, task, memory, etc.
–Remove driver from IO system
31
USBOpen()
USBOpen() and USBClose()
USBClose()
?USBOpen()
USBOpen() - Opens an endpoint
–If not the Control endpoint
•Verifies device is enumerated
•Verifies endpoint is part of current configuration/interface
–Selects CPU or DMA transfer mode
•If DMA selects endpoint’
s FIFO for use with DMA
–Set Endpoint states to OPENED
?USBClose()
USBClose() - Closes an endpoint
–Disables DMA controller’s use of endpoint’
s FIFO
–Set endpoint state to CLOSED
32
16
USBRead()
USBRead()
33
Out Token
Data Packet
ACK
Data Data Packet
Buffer Out Token
Data Packet
34
17
USBWrite()
USBWrite()
35
Data Packet
IN Token
Data Packet
ACK
Data
Buffer Data Packet
IN Token
Data Packet
ACK
36
18
Control Read
?Call USBRead(
USBRead( EP0 ) to read a Setup Packet
–Read from EP0 OUT FIFO
?Identify Setup Packet
–Standard, Class or Vendor
?Create response to Setup Packet
–For example prepare to return a Descriptor
?Call USBWrite(
USBWrite( EP0 ) to write the response
–Perform normal USBWrite()
USBWrite() function to EP0 IN FIFO
–Wait for Host to return a Zero Byte packet
terminating Control transfer
?Repeat
37
Control Write
?Call USBRead(
USBRead( EP0) to read a Setup Packet
–Read from EP0 OUT FIFO
?Identify Setup Packet
–Standard, Class or Vendor
?Prepare to receive data from Host
?Call USBRead(
USBRead( EP0 ) to read data from the Host
–Perform normal USBRead()
USBRead() function from EP0 OUT
FIFO
–Send a Zero Byte packet to the Host terminating the
Control transfer
?Repeat
38
19
Callback Message Queue
39
Outline
?USB Overview
?USB Hardware Controllers
?Architecture of an Embedded USB Device
?USB Device Driver Architecture
?Case Study of a USB Device Driver
?Testing Strategies
?Issues to consider
?Conclusions
40
20
Windows 98 OS Application
TWAIN
Still Still Still Digital Camara
or Image Color
image image image Application
other Management
control event control
Image (ICM 2.0)
panel monitor center
API
User-mode
minidriver
User Mode Driver Interface
IHV
ISV
USB USB Device
Driver
USB Cable
41
Application
Still Image
Still Image Still Image
Still Image Still Image
Still Image Color
Color
Control Event Control
TWAIN Manager
ISIS
Control Event Control Manager
API API
Panel
Panel Monitor
Monitor Center
Center (ICM 2.0)
(ICM 2.0)
User Mode
User Mode MiniDriver
MiniDriver User Mode
User Mode MiniDriver
MiniDriver User Mode
User Mode MiniDriver
MiniDriver
User Mode
WDM Still
WDM Still Image
Image WDM Still
WDM Still Image
Image Kernel Mode
MiniDriver for
MiniDriver for USB
USB MiniDriver for
MiniDriver for SCSI
SCSI COMM Ports
COMM Ports
USB
USB SCSI
SCSI
42
21
Design Constraints
?Hardware Selection
–Still image architecture requires Control, Bulk In,
Bulk Out and Interrupt endpoints.
43
Outline
?USB Overview
?USB Hardware Controllers
?Architecture of an Embedded USB Device
?USB Device Driver Architecture
?Case Study of a USB Device Driver
?Testing Strategies
?Issues to consider
?Conclusions
44
22
Effective Testing Strategies
Analyzer View
46
23
Host Software Testing Strategies
47
?Unit Tests
–Driver Install and Uninstall
–Enumeration Test
–Device Driver API
•Open/Close endpoints
•Data Transfer (read and write)
•Select Endpoint using DMA
•IO Control Test
–Loopback Testing (>1000x, vary transfer sizes)
–Vendor/Class Request Support
?System Tests
–Perform typical use cases with Product software
–System Level Power Management
48
24
USB Organization’
s Testing Resources
–Interoperability Guidelines
–Test Tools
•USBCheck,
USBCheck, HIDView
–Compliance Workshops
•Verifies USB Compliance and Interoperability
•in-house USB Compliance and Interoperability
–Verify throughout product development
49
USB Analyzers
? Drawbacks
–Purchase Price
–Selecting which one you want
–Some PC’ s have demonstrated signal/noise errors
with USB analyzer’s attached
50
25
Outline
?USB Overview
?USB Hardware Controllers
?Architecture of an Embedded USB Device
?USB Device Driver Architecture
?Case Study of a USB Device Driver
?Testing Strategies
?Issues to consider
?Conclusions
51
Issues to consider
?USB 2.0
–Do you need it?
–NOT supported in Windows XP
?Protocol Stacks
–PIMA/ISO-15740
–USB Mass Storage Devices
–WDM Still Image Architecture
52
26
Outline
?USB Overview
?USB Hardware Controllers
?Architecture of an Embedded USB Device
?USB Device Driver Architecture
?Case Study of a USB Device Driver
?Testing Strategies
?Issues to consider
?Conclusions
53
Conclusion
54
27
For More Information
Joe Flynn
Questra Corporation
jflynn@questra
jflynn@questra.com
.com
(716)381-0260
56
28