1. Trang chủ
  2. » Công Nghệ Thông Tin

Tài liệu Design of a USB Device Driver ppt

28 423 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 28
Dung lượng 579,88 KB

Nội dung

1 1 Design of a USB Device Driver Design of a USB Device Driver Joe Flynn Questra Corporation jflynn@questra.com (716)381-0260 2 Outline Outline ? ? USB Overview USB Overview ? ? USB Hardware Controllers USB Hardware Controllers ? ? Architecture of an Embedded USB Device Architecture of an Embedded USB Device ? ? USB Device Driver Architecture USB Device Driver Architecture ? ? Case Study of a USB Device Driver Case Study of a USB Device Driver ? ? Testing Strategies Testing Strategies ? ? Issues to consider Issues to consider ? ? Conclusions Conclusions 2 3 USB Overview USB Overview ? ? Hardware Overview Hardware Overview – – Topology Topology ? ? Protocol Characteristics Protocol Characteristics – – Packet Types Packet Types – – USB Transactions USB Transactions ? ? Enumeration Enumeration – – Enumeration States Enumeration States ? ? Examples of USB devices Examples of USB devices 4 Hardware Overview Hardware Overview Physical Hardware View Physical Hardware View Logical Hardware View Logical Hardware View Pen Kbd Mouse Mic Mic Phone Monitor PC PC Monitor Speaker Pen Mouse Mic Phone PC HUB HUB HOST/HUB Kbd ? ? Topology Topology – – Tiered Star Tiered Star (Distributes Connectivity Points) (Distributes Connectivity Points) – – 127 logical connections 127 logical connections (up to 5 meters per segment) (up to 5 meters per segment) – – Up to 6 tiers Up to 6 tiers ? ? Bus transactions Bus transactions – – Speed: 12Mbps aggregate Speed: 12Mbps aggregate • • 1.5Mbps sub-channel 1.5Mbps sub-channel – – Isochronous Isochronous and Asynchronous and Asynchronous – – Media access controlled by host Media access controlled by host ? ? Configuration Configuration – – Dynamic insertion-removal Dynamic insertion-removal – – Autoconfiguration Autoconfiguration on change on change ? ? Physical Layer Physical Layer – – 2-wire differential signaling, NRZI 2-wire differential signaling, NRZI coded with bit stuffing coded with bit stuffing – – 4 pin connector, 4 wire cable 4 pin connector, 4 wire cable – – Supply Supply Sourcing Sourcing +5V +5V Speaker 3 5 The Transaction Protocol is Host Based The Transaction Protocol is Host Based ? ? Host based token polling Host based token polling – – Data from host-to-function and function-to-host Data from host-to-function and function-to-host – – Host handles most of the protocol complexity Host handles most of the protocol complexity – – Peripheral design is simple and low-cost Peripheral design is simple and low-cost ? ? Robustness Robustness – – Handshake to acknowledge data transfer and flow control Handshake to acknowledge data transfer and flow control – – Very low raw physical bit error rate ( <10 Very low raw physical bit error rate ( <10 -10 -10 ) ) – – CRC protection plus hardware retry option CRC protection plus hardware retry option – – Data Toggle Sequence bits Data Toggle Sequence bits ? ? Bounded transfer characteristics Bounded transfer characteristics – – Data transfer bandwidth and latency Data transfer bandwidth and latency prenegotiated prenegotiated – – Flow control for peripheral buffer management Flow control for peripheral buffer management Data Transfer Data TransferToken Token Handshake Handshake 6 Packet Types Packet Types ? ? Token - OUT, IN, SOF, SETUP Token - OUT, IN, SOF, SETUP – – First packet in any transaction First packet in any transaction – – Specifies function address, endpoint Specifies function address, endpoint – – Specifies data direction Specifies data direction ? ? Data - DATA0, DATA1 Data - DATA0, DATA1 – – 0 - 1023 bytes 0 - 1023 bytes ? ? Handshake - ACK, NAK, STALL Handshake - ACK, NAK, STALL – – Report status of data transaction Report status of data transaction – – Flow control Flow control – – Stall conditions Stall conditions ? ? Special - PRE Special - PRE – – Enables Hub for low speed communications Enables Hub for low speed communications 4 7 A Typical USB Transaction Consists A Typical USB Transaction Consists of Three Packets of Three Packets Idle Idle Idle Idle NAK STALL DATA0/ DATA 1 DATA0/ DATA 1 T/O ACKACK DATA0/ DATA1 DATA0/ DATA1 ACK STALLNAK T/O DATA0 ACK T/O Function Function Host Host Token Token Idle Idle Handshake Handshake Data Data IN OUT SET 8 There are Four Types of USB There are Four Types of USB Transactions Transactions ? ? Isochronous Isochronous (Audio, telephony …) (Audio, telephony …) – – Periodic, Bounded latencies, guaranteed bandwidth Periodic, Bounded latencies, guaranteed bandwidth ? ? Interrupt (Mouse, joystick …) Interrupt (Mouse, joystick …) – – Asynchronous, Asynchronous, bursty bursty , non-periodic, low bandwidth , non-periodic, low bandwidth ? ? Bulk (Printer, scanner, digital camera …) Bulk (Printer, scanner, digital camera …) – – Non-periodic, Non-periodic, bursty bursty , high bandwidth utilization , high bandwidth utilization ? ? Control (Configuration messages …) Control (Configuration messages …) – – Bursty Bursty , host-initiated (bus management, , host-initiated (bus management, configuration) configuration) 5 9 The Basic USB Model has Several The Basic USB Model has Several Layers of Abstraction Layers of Abstraction Host Endpoint 0 Endpoint 0 - Required, shared - Required, shared - Configuration access - Configuration access - Capability control - Capability control Pipe, connection abstraction Pipe, connection abstraction between two horizontal layers between two horizontal layers Data transport mechanism Data transport mechanism USB-relevant format of transported data USB-relevant format of transported data SIE SIE Host Cntrl USB Bus Interface USB Bus Interface USB System manages devices USB Device a collection of endpoints Data Data Data Per Data Per Endpoint Endpoint Default Default Pipe to Pipe to Endpoint Zero Endpoint Zero Unspecified Unspecified USB USB Framed Framed Data Data Endpoint Zero Buffers Buffers Interface Interface Specific Specific Function a collection of Interfaces Pipe Bundle Pipe Bundle to an to an interface interface No USB No USB Format Format No USB No USB Format Format Interface x Client SW manages an interface USB Wire Transactions USB Framed Data Device 10 Enumeration: Device perspective Enumeration: Device perspective ? ? Attached State Attached State – – Entered by attaching USB Cable Entered by attaching USB Cable ? ? Powered State Powered State – – USB Host Applies power USB Host Applies power ? ? Default state Default state – – USB Host resets bus USB Host resets bus ? ? Addressed State Addressed State – – USB Host sends Set Address with non-zero address USB Host sends Set Address with non-zero address ? ? Configured state Configured state – – USB Host sends Set Configuration with non-zero USB Host sends Set Configuration with non-zero value value ? ? Suspended state Suspended state – – USB Host stops sending SOF for 3 USB Host stops sending SOF for 3 msec msec 6 11 The Device State Machine The Device State Machine Attached Powered Suspended Bus Activity Bus Activity Idle Bus Idle Bus Default Configured Address Suspended Suspended Suspended Bus Activity Idle Bus Bus Activity Bus Activity Idle Bus Address Assigned Device Configured Hub Hub Configured Configured Hub Reset Hub Reset or or Deconfigured Deconfigured Reset Reset Power Power Interruption Interruption Reset Reset Idle Bus Device Deconfigured 12 Enumeration is the Process of Assigning Enumeration is the Process of Assigning Addresses and Setting Configurations Addresses and Setting Configurations Connect Cable Connect Cable Attached Attached Status Change Status Change Query Change Query Change Port Enable Port Enable Powered Powered Default Default Reset Device Reset Device Get Device Descriptor via Default Pipe and Address Get Device Descriptor via Default Pipe and Address Addr Addr . . Assigned Assigned Assign a Unique Address Assign a Unique Address Read All Configuration Information Read All Configuration Information Configure and Assign Configuration Value Configure and Assign Configuration Value Configured Configured Host Host Hub Hub Device Device 7 13 Outline Outline ? ? USB Overview USB Overview ? ? USB Hardware Controllers USB Hardware Controllers ? ? Architecture of an Embedded USB Device Architecture of an Embedded USB Device ? ? USB Device Driver Architecture USB Device Driver Architecture ? ? Case Study of a USB Device Driver Case Study of a USB Device Driver ? ? Testing Strategies Testing Strategies ? ? Issues to consider Issues to consider ? ? Conclusions Conclusions 14 ? ? Discrete Components Discrete Components – – NetChip NetChip , Intel, National Semiconductor, Phillips , Intel, National Semiconductor, Phillips ? ? USB IP Cores as part of an ASIC USB IP Cores as part of an ASIC – – Sand, Motorola, Texas Instruments, .etc Sand, Motorola, Texas Instruments, .etc ? ? Combination USB Host and USB Peripheral chip Combination USB Host and USB Peripheral chip – – ScanLogic ScanLogic ? ? Combination micro-processor and USB Core Combination micro-processor and USB Core – – 8/16 bit processor Mitsubishi, .etc 8/16 bit processor Mitsubishi, .etc ? ? Single Chip Solutions Single Chip Solutions – – Netchip Netchip NET1031 Single chip scanner controller. NET1031 Single chip scanner controller. Types of USB Controllers Types of USB Controllers 8 15 ? ? USB Core USB Core ? ? Registers for Control and Endpoint Data Registers for Control and Endpoint Data Transfer Transfer ? ? FIFO Controller FIFO Controller – – Input and Output Input and Output FIFOs FIFOs for Control Endpoint for Control Endpoint – – Input or Output FIFO for other Endpoints Input or Output FIFO for other Endpoints ? ? DMA Controller DMA Controller ? ? Internal Bus Internal Bus ? ? Serial Interface Engine Serial Interface Engine ? ? Output Pads Output Pads USB Controller Hardware Architecture USB Controller Hardware Architecture 16 Example of USB Controller Example of USB Controller EP0 FIFO Processor Bus USB Core Logic DMA and FIFO Control EP3 FIFOEP2 FIFOEP1 FIFOEP0 FIFO USB Internal Bus EPx Status Reg USB Control Reg EPx Ctl Reg Register Bank EP 0 Control EP 1 Bulk/ISO IN EP2 Bulk/Iso Out EP3 Interrupt IN Serial Interface Engine Output Pad Enable USB Pads 9 17 ? ? Implements most USB Requests in hardware Implements most USB Requests in hardware – – Standard Requests Standard Requests • • GET_DESCRIPTOR and SET_DESCRIPTOR may be GET_DESCRIPTOR and SET_DESCRIPTOR may be implemented in software for versatility implemented in software for versatility – – Class/Vendor Requests as appropriate Class/Vendor Requests as appropriate ? ? USB Event Interrupts and status USB Event Interrupts and status – – Setup, Suspend, Resume, SOF, Reset, Zero Byte Setup, Suspend, Resume, SOF, Reset, Zero Byte Packet Packet – – DMA Complete DMA Complete – – Transmit/Receive Transmit/Receive Ack Ack / / Nack Nack /Error status /Error status – – FIFO empty/full or at high/low threshold level FIFO empty/full or at high/low threshold level ? ? FIFOs FIFOs supporting supporting – – multiple packet depth multiple packet depth – – Hardware Retry of Packet Transfers on error Hardware Retry of Packet Transfers on error Key Features of a USB Controller Key Features of a USB Controller 18 ? ? Hardware should provide ability to Hardware should provide ability to – – initiate a Remote Wakeup initiate a Remote Wakeup – – detect a USB Reset detect a USB Reset – – reset USB Controller reset USB Controller – – Select endpoint as DMA destination Select endpoint as DMA destination – – Detect enumeration Detect enumeration – – Read Current Configuration and Interface Read Current Configuration and Interface – – Stall endpoints Stall endpoints Key Features of a USB Controller II Key Features of a USB Controller II 10 19 Outline Outline ? ? USB Overview USB Overview ? ? USB Hardware Controllers USB Hardware Controllers ? ? Architecture of an Embedded USB Device Architecture of an Embedded USB Device ? ? USB Device Driver Architecture USB Device Driver Architecture ? ? Case Study of a USB Device Driver Case Study of a USB Device Driver ? ? Testing Strategies Testing Strategies ? ? Issues to consider Issues to consider ? ? Conclusions Conclusions 20 Architecture of an Embedded USB Architecture of an Embedded USB Device Device Fifo Fifo Fifo Fifo Hardware Hardware Data packets from host Data packets from host Application Application Driver Driver USB Protocol USB Protocol API API API API Logical pipe Logical pipe Logical pipe Logical pipe [...]... DMA Driver DMA Controller 28 14 USB Device Driver Architecture Callback Function Driver Interface UsbDrv UsbDevCreate USB_ open USB_ close USB_ read USB_ write USB_ ioctl Context of Callback Message Queue COMMOM USB Functions Utilities USB HW/SW Initialize Functions UsbOpen UsbClose UsbRead UsbWrite UsbIoctl UsbIsr Framer Layer Hardware Specific Functions USB Controller Hardware 29 USB Device Driver API... Purchase a USB Evaluation Board & source code ? Utilize USB Organizations Test Resources 45 Analyzer View 46 23 Host Software Testing Strategies ? Schedule availability of Host software USB mini -driver –Host Test Application ? Request Host Test Application support –Enumeration –Data Transfer –Data Transfer Loopback Testing –Vendor/Class Request Support ? Leverage USB Evaluation sample source –Stimulate... transfer mode is DMA • Setup and start DMA read of fixed size from Endpoint FIFO • Block until DMA is complete or a timeout occurs –else • ISR Called • Loop until all data is read, a timeout occurs or a short packet is received • Exit ISR 33 USB Read Process Endpoint FIFO USB Driver USB Host Out Token Data Packet Data Buffer ACK Data Packet Out Token Data Packet Data Packet ACK 34 17 USBWrite() USBWrite()... notification to application of asynchronous events USB Reset –Enumeration –Configuration Change –Interface Change –Suspend/Resume –Attach/Dettach Attach/Dettach –SOF –Report Setup Packet received by Control Endpoint 0 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... endpoints Design of the communications protocol is contingent on the Twain data source and any classes supported ? Host Application defines –Features supported by camera application –Power Management requirements 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... transfer mode is DMA • Setup and start DMA write of fixed size to Endpoint FIFO • Block until DMA is complete or a timeout occurs –else • ISR Called • Loop until all data is written, or a timeout occurs • Exit ISR 35 USB Write Process Endpoint FIFO USB Driver USB Host Data Packet IN Token Data Packet Data Buffer ACK Data Packet IN Token Data Packet ACK 36 18 Control Read ? Call USBRead( EP0 ) to read... USBRead( EP0) to read a Setup Packet USBRead( –Read from EP0 OUT FIFO ? Identify Setup Packet –Standard, Class or Vendor ? Prepare to receive data from Host ? Call USBRead( EP0 ) to read data from the Host USBRead( –Perform normal USBRead() function from EP0 OUT USBRead() FIFO –Send a Zero Byte packet to the Host terminating the Control transfer ? Repeat 38 19 Callback Message Queue ? Message Interface... image control panel Still image event monitor Application Still image control center TWAIN or other Image API Digital Camara Application Image Color Management (ICM 2.0) Still Image DDI User-mode minidriver User Mode Kernel Mode WDM still image driver for USB Provided by: Microsoft Driver Interface IHV ISV USB USB Device Driver USB Cable 41 WDM Still Image Architecture Attempts to Keep All Custom Software... Support both CPU and DMA transfers ? Data Transfer Speed is a priority – Transfer Data inside ISR – Optimize code execution of critical routines – Design a solution with parallelism of processing and data transfer – Dedicate the DMA to the highest bus bandwidth scenarios ? USB Compliance testing occurs throughout development ? Take advantage ofUSB Test tools – USB Analyzers – Compliance Worksheets... 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 ? Selecting a more capable USB controller simplifies the design USB Device Drivers . Consists of Three Packets of Three Packets Idle Idle Idle Idle NAK STALL DATA0/ DATA 1 DATA0/ DATA 1 T/O ACKACK DATA0/ DATA1 DATA0/ DATA1 ACK STALLNAK T/O DATA0. data direction ? ? Data - DATA0, DATA1 Data - DATA0, DATA1 – – 0 - 1023 bytes 0 - 1023 bytes ? ? Handshake - ACK, NAK, STALL Handshake - ACK, NAK, STALL

Ngày đăng: 13/12/2013, 00:15

TỪ KHÓA LIÊN QUAN