Download presentation
Presentation is loading. Please wait.
Published byKory Lester Modified over 9 years ago
1
Spring 2014 SILICON VALLEY UNIVERSITY CONFIDENTIAL 1 Introduction to Embedded Systems Dr. Jerry Shiao, Silicon Valley University
2
SILICON VALLEY UNIVERSITY CONFIDENTIAL 2 Spring 2014 Section 15 USB Drivers Universal Serial Bus Originally Created to replace different (slow) busses: Standardized way to connect up-to 127 devices. Printers, Scanners, Mice, Joysticks, Webcams, Modems, Speakers, Storage Devices, Network Connections. Layout: Tiered Star Topology with up-to 6 Tiers USB 1.1 Master/Slave Interface. A PC is normally the master or Host and each of the peripherals linked to it act as slaves or Devices. Low Speed ( 1.5Mbits/sec ), High Speed ( 12 Mbits/sec ). USB 2.0 Superset of USB 1.1. Supports High Speed 480 Mbits/sec. USB 3.0 Backwards compatible to USB 2.0. Super Speed > 4.8 Gbits/sec
3
SILICON VALLEY UNIVERSITY CONFIDENTIAL 3 Spring 2014 Section 15 USB Drivers USB Host Controller Single-Master Implementation: Host Controller Polls the USB Devices. USB Device never sends unless requested by the Host Controller. USB Device can request a bandwidth for its data transfers (i.e. support video and audtio I/O). USB Device Classes. Standard for any USB Device of a specific type. Special Driver not needed from a vendor. Storage Devices, Keyboards, Mice, Joysticks, Network Devices, Modems. USB Device not in the defined classes require Vendor-Specific Driver. Video Devices, USB-to-Serial Devices. Plug-and-Play System. USB Drivers Drivers for Host System: Controls the USB Devices that are plugged in. Drivers in Device: Controls how that single device looks to the host computer as a USB Device. USB Gadget Drivers
4
SILICON VALLEY UNIVERSITY CONFIDENTIAL 4 Linux Device Drivers Copyright 2005 Section 15 USB Drivers USB Device USB Core provides an interface for USB Drivers to access and control the USB Hardware. Abstraction layer to hide the different types of USB Hardware Controllers.
5
SILICON VALLEY UNIVERSITY CONFIDENTIAL 5 Linux Device Drivers Copyright 2005 Section 15 USB Drivers USB Device USB Endpoints Sources or Sinks of Data at the USB Device. Carry Data in one direction. Out Endpoint: Host Computer to USB Device. In Endpoint: USB Device to Host Computer. Control Endpoint: Endpoint 0, Guaranteed Configuring USB Device. Retrieving Information from USB Device. Retrieving Status Reports from USB Device. Interrupt Endpoint: Guaranteed Host retrieves data from USB Device at fixed rate. Sends control to USB Device. USB Keyboards and Mice. Bulk Endpoint: Not Guaranteed Transfer large amounts of data. Printers, Storage, and Network Devices. Isochronous Endpoint: Not Guaranteed Transfer constant stream of data. Real-Time Data Collections (audio and video drivers).
6
SILICON VALLEY UNIVERSITY CONFIDENTIAL 6 www.beyondlogic.org Section 15 USB Drivers USB Device USB Endpoints USB Device unique address (max 127). USB Device Endpoint n Input/Output Buffers. Data are buffered in the Out Buffers until the Host requests the data.
7
SILICON VALLEY UNIVERSITY CONFIDENTIAL 7 Linux Device Drivers Copyright 2005 Section 15 USB Drivers USB Device USB Devices consists of Configuration, Interfaces, and endpoints. USB Drivers bind to USB Interfaces, not the entire USB Device. USB Interfaces handle only one type of a USB logical connection, such as a mouse, keyboard, or a audio stream. USB Devices have multiple Interfaces. USB Speaker has two interfaces: USB Keyboard for the buttons and a USB audio stream.
8
SILICON VALLEY UNIVERSITY CONFIDENTIAL 8 Linux Device Drivers Copyright 2005 Section 15 USB Drivers USB Device Enumeration Process of determining what USB Device has just been connected to the Bus. Host retrieve USB Device Configuration from the device: USB Device Descriptor: Vendor ID/ Product ID Number of Configurations. USB Configuration Descriptor: Power Consumption. Number of Interfaces (USB Drivers). USB Interface Descriptor: Interface Class/Subclass. Number of Endpoints of an Interface. USB Endpoint Descriptor: Type of Endpoints. Maximum Packet Size. Polling Interval. Host assigns an address (1-127) to USB Device. Host enables a Device Descriptor configuration.
9
SILICON VALLEY UNIVERSITY CONFIDENTIAL 9 Linux Device Drivers Copyright 2005 Section 15 USB Drivers USB Device Enumeration # Vendors, devices and interfaces. Please keep sorted. # Syntax: #vendor vendor_name #device device_name #interface interface_name 0001 Fry's Electronics 142b Arbiter Systems, Inc. 7778 Counterfeit flash drive [Kingston] 0002 Ingram 0003 Club Mac # #List of USB ID's # #Maintained by Stephen J. Gowdy # #If you have any new entries, please submit #http://www.linux-usb.org/usb-ids.html #or send entries as patches (diff -u old new) in #body of your email. #The latest version can be obtained from #http://www.linux-usb.org/usb.ids # # Version: 2014.02.03 # Date: 2014-02-03 20:34:03
10
SILICON VALLEY UNIVERSITY CONFIDENTIAL 10 Linux Device Drivers Copyright 2005 Section 15 USB Drivers USB Device Enumeration HOST 1)The Linux daemon, khubd, is awaken when root hub detects an USB Device is attached. 2)Khubd issues a reset to the USB Device and request Device Descriptor. 3)Khubd issues a Set Address command, placing the USB Device in the addressed state. 4)Khubd requests the Configuration Descriptors and selects a suitable configuration. 5)Khubd issues a Set Configuration request. 6)Khubd requests USB core to bind to a matching client driver (Vendor ID/Product ID). USB Device 1)USB Device attached. 2)USB Device uses Endpoint 0 3)USB Device configured with address (1-27). 4)USB Device sends its Configuration Descriptors. Usually only one configuration, 5)USB Device configuration set.
11
SILICON VALLEY UNIVERSITY CONFIDENTIAL 11 Linux Device Drivers Copyright 2005 Section 15 USB Drivers USB Descriptors USB Devices have a hierarchy of descriptors, which describes the Device to the host.
12
SILICON VALLEY UNIVERSITY CONFIDENTIAL 12 Linux Device Drivers Copyright 2005 Section 15 USB Drivers USB Descriptors Device Descriptor USB Device can have only one Device Descriptor. USB Revision. Product and Vendor ID, load USB Drivers. Number of configurations (Configuration Descriptor branches). Configuration Descriptor Once enumerated, only one Configuration Descriptor can be Enabled (few devices have more than one). Max amount of power. Power (i.e. 500 milliamp units) that the USB Device can draw from the host. USB Device is self or bus powered. Host with a mains power supply would use bus powered. NOTE: Bus powered shares the bus power among all the ports and the hub. Device requiring more than 500 mA must be self-powered. Self- powered USB Device does not draw from the host and has its own power source. Number of Interfaces.
13
SILICON VALLEY UNIVERSITY CONFIDENTIAL 13 Linux Device Drivers Copyright 2005 Section 15 USB Drivers USB Descriptors Interface Descriptor Grouping of the endpoints into a functional group performing a single feature of the USB Device. Multi-function Fax/Scanner/Printer has: 1) Interface Descriptor 1 has the endpoints of the Fax function. 2) Interface Descriptor 2 has the endpoints of the Scanner function. 3) Interface Descriptor 3 has the endpoints of the Printer function. USB Device can have 1 or many Interface Descriptors enabled at once. Endpoint Descriptor Endpoint number (0-15). Specify the type of transfer (Control, Isochronous, Bulk, Interrupt). Maximum packet size the endpoint is capable of send/receive. Polling interval for endpoint data transfers. Isochronous and Interrupt endpoints. String Descriptor Optional human readable information.
14
SILICON VALLEY UNIVERSITY CONFIDENTIAL 14 Linux Device Drivers Copyright 2005 Section 15 USB Drivers USB Transactions Each USB Transaction consists of a: Token Packet (Header defining OUT/IN endpoint, Start-of-Frame (SOF), SETUP). Describe what is to follow. Data transaction will be read or written. Device’s address and designated endpoint. Optional Data Packet (Payload). Status Packet. Acknowledge Transactions. Provide means of Error Correction (endpoint stalled or not available to accept data). USB Host Centric Bus: Host Initiates all transactions.
15
SILICON VALLEY UNIVERSITY CONFIDENTIAL 15 Linux Device Drivers Copyright 2005 Section 15 USB Drivers USB Transactions
16
SILICON VALLEY UNIVERSITY CONFIDENTIAL 16 Linux Device Drivers Copyright 2005 Section 15 USB Drivers USB Transactions
17
SILICON VALLEY UNIVERSITY CONFIDENTIAL 17 Linux Device Drivers Copyright 2005 Section 15 USB Drivers USB Transactions
18
SILICON VALLEY UNIVERSITY CONFIDENTIAL 18 Linux Device Drivers Copyright 2005 Section 15 USB Drivers USB Transactions Control Transfer: Enumeration with Device Descriptor 1) Setup Stage is where the request is sent. Consisting of three packets. a) Host: Setup Token contains USB Device address and endpoint number (0). b) Host: Data Packet with PID 0 with the Setup packet containing the request (i.e. Read Device Descriptor). c) USB Device: Handshake Packet used for acknowledging successful receipt or to indicate an error.
19
SILICON VALLEY UNIVERSITY CONFIDENTIAL 19 Linux Device Drivers Copyright 2005 Section 15 USB Drivers USB Transactions Control Transfer: Setup 1) Host send Setup Token identifying the packet is a Setup packet. ADDR field hold the address of the device the host is requesting the Device Descriptor. ENDP field is zero, indicating the default pipe. 2) Device Descriptor Request. 3) USB Device acknowledges receiving Setup packet with no errors.
20
SILICON VALLEY UNIVERSITY CONFIDENTIAL 20 Linux Device Drivers Copyright 2005 Section 15 USB Drivers USB Transactions Control Transfer: Data IN: When the host is ready to receive control data, the host issues an IN Token. OUT: When the host is ready to send the USB Device a control data packet, the host issues an OUT Token.
21
SILICON VALLEY UNIVERSITY CONFIDENTIAL 21 Linux Device Drivers Copyright 2005 Section 15 USB Drivers USB Transactions Control Transfer: Data 1) Host send IN Token requesting data from the endpoint. The Device Descriptor from the USB Device. ADDR field hold the address of the device the host is requesting the Device Descriptor. ENDP field is zero, indicating the default pipe. 2) USB Device sends first 8 bytes of Device Descriptor. 3) Host acknowledges receiving Data Descriptor packet.
22
SILICON VALLEY UNIVERSITY CONFIDENTIAL 22 Linux Device Drivers Copyright 2005 Section 15 USB Drivers USB Transactions Control Transfer: Handshake OUT: Host sent OUT Token(s) during Data Stage. The USB Device will acknowledge successful receipt of data by sending a zero length packet in response to a IN Token. IN: Host send IN Token(s) during the Data Stage. Host acknowledge the successful recept of data by sending OUT Token followed by zero length data packet.
23
SILICON VALLEY UNIVERSITY CONFIDENTIAL 23 Linux Device Drivers Copyright 2005 Section 15 USB Drivers USB Transactions Control Transfer: Handshake 1) Host sends OUT Token indicating a Status transaction is to follow. ADDR field hold the address of the device the host is requesting the Device Descriptor. ENDP field is zero, indicating the default pipe. 2) Host sends zero length packet indicating overall transaction was successful. 3) USB Device acknowledges receiving Data Descriptor packet.
24
SILICON VALLEY UNIVERSITY CONFIDENTIAL 24 Linux Device Drivers Copyright 2005 Section 15 USB Drivers USB Transactions Interrupt Transfer: Interrupts are device driver. On USB, if a device requires attention of the host, the device must wait until the host polls the device before the device can report its event. An interrupt request is queued by the device until the host polls the device. Low-speed: 8 Bytes Full-speed: 64 Bytes High-speed: 1024 Bytes
25
SILICON VALLEY UNIVERSITY CONFIDENTIAL 25 Linux Device Drivers Copyright 2005 Section 15 USB Drivers USB Transactions Interrupt Transfer IN Token: Host will periodically poll the interrupt endpoint. Rate of polling is specified in the Endpoint Descriptor. Queued interrupt will be sent in data packet when device receives the IN Token. If no interrupt, device will send a NAK status packet. If error has occurred at the endpoint, device will send a STALL status packet. OUT Token: Host sends device interrupt data, OUT Token followed by data packet. If data received at endpoint buffer, device will send ACK status. If endpoint buffer is not empty, device will send NAK status. If error has occurred on endpoint, device will send STALL status.
26
SILICON VALLEY UNIVERSITY CONFIDENTIAL 26 Linux Device Drivers Copyright 2005 Section 15 USB Drivers USB Transactions Isochronous Transfer: Isochronous transfers occur continuously and periodically. Contain time sensitive information (audio or video stream). Maximum payload size specified by Endpoint Descriptor of an Isochronous Endpoint. Problem with bandwidth restrictions: Alternative interfaces with varying isochronous payload sizes.
27
SILICON VALLEY UNIVERSITY CONFIDENTIAL 27 Linux Device Drivers Copyright 2005 Section 15 USB Drivers USB Transactions Bulk Transfer: Bulk Transfers Used for large bursty data. Print-job sent to USB printer or receive image generated from USB scanner. Bulk transfers use spare un- allocated bandwidth on the bus after all other transactions have been allocated. Isochronous or interrupt data will be sent on bus before bulk data. Bulk transfers should only be used for time insensitive communications. No guarantee of latency. Full-speed endpoints: 8 to 64 Bytes data packets. High-speed endpoints: 512 Bytes data packets.
28
SILICON VALLEY UNIVERSITY CONFIDENTIAL 28 Linux Device Drivers Copyright 2005 Section 15 USB Drivers USB Transactions Bulk Transfer IN Token: Host sends IN Token when the host is ready to receive bulk data. USB Device will send data packet with bulk data. USB Device will send STALL if endpoint has an error. USB Device will send NAK if endpoint has no bulk data to send. OUT Token: Host sends OUT Token when the host has bulk data to send. USB Device will send ACK if endpoint buffer was empty and bulk data received in the buffer. USB Device will send STALL if endpoint has an error. USB Device will send NAK if endpoint buffer not empty.
29
SILICON VALLEY UNIVERSITY CONFIDENTIAL 29 Linux Device Drivers Copyright 2005 Section 15 USB Drivers USB Request Block ( URB ) USB Drivers communicates to USB Devices using URB. Send or Receive Data to or from USB Endpoints on USB Device. Endpoint of USB Device will queue URBs. URB Cycle: Created by USB Device Driver. Assigned to Endpoint by USB Device Driver. Submitted to USB Host Controller for specified USB Device. Processed by USB Host Controller: Transfers to the USB Device. USB Host Controller notifies the USB Device Driver via Callback Handler. URB can be released.
30
SILICON VALLEY UNIVERSITY CONFIDENTIAL 30 Linux Device Drivers Copyright 2005 Section 15 USB Drivers USB Request Block ( URB ) Create URB: struct urb *usb_alloc_urb(int iso_packets, int mem_flags); Release URB: void usb_free_urb(struct urb *urb); Interrupt URB: Initialize URB for Interrupt Endpoint. void usb_fill_int_urb(struct urb *urb, struct usb_device *dev, unsigned int pipe, void *transfer_buffer, int buffer_length, usb_complete_t complete, void *context, int interval); Bulk URB: Initialize URB for Bulk Endpoint. void usb_fill_bulk_urb(struct urb *urb, struct usb_device *dev, unsigned int pipe, void *transfer_buffer, int buffer_length, usb_complete_t complete, void *context);
31
SILICON VALLEY UNIVERSITY CONFIDENTIAL 31 Linux Device Drivers Copyright 2005 Section 15 USB Drivers USB Request Block ( URB ) Control URB: Initialize Control URB. void usb_fill_control_urb(struct urb *urb, struct usb_device *dev, unsigned int pipe, unsigned char *setup_packet, void *transfer_buffer, int buffer_length, usb_complete_t complete, void *context); Submit URB to USB Core to be sent to USB Device. int usb_submit_urb(struct urb *urb, int mem_flags); Unlinking URB from USB Core: int usb_kill_urb(struct urb *urb); int usb_unlink_urb(struct urb *urb);
32
SILICON VALLEY UNIVERSITY CONFIDENTIAL 32 Linux Device Drivers Copyright 2005 Section 15 USB Drivers USB Request Block ( URB ) Completing URB: URB successfully send to USB Device. USB Device returns proper acknowledgement for IN and OUT URB. URB Status Variable is 0. Error in Sending or Receiving Data from USB Device. URB Status Variable has Error Value. URB “unlinked” from the USB Core. USB Driver has cancelled submitted URB.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.