读书笔记 <Bootstrap Yourself with Linux USB Stack>
第一章 USB and Linux Introduction
- 关于USB的硬件
三种类型:
USB Transceiver, 通常包含一个USB core在芯片上
Standalone USB Controller, transceiver + digital portion
Integrated USB Controller,
第二章 USB: An Overview
- USB System Architecture
分为三个主要部分:
USB device
USB host
USB interconnect
- USB host
HCD: host control driver
USBD: USB driver
IRP: input/output request packets
它由以下几部分组成:
Client Software
USB System Software
Host Controller
- USB Device
它由以下3部分组成:
Function
USB Logical Device
USB Bus Interface
- USB Host和USB Device之间如何交互
Endpoint, 一个device可以根据其function提供多个endpoint, 每个以device address, endpoint number, endpoint direction唯一标识.
Endpoint Zero是一个特殊的endpoint, 每个device都必须要实现它. 它供Usb host初始化和获得device的信息.
Endpoint需要通过以下几点描述它自己:
The bus access frequency/latency requirement
The bandwidth requirement
The endpoint number
The error-handling behavior requirements
The maximum packet size that the endpoint is capable of sending or receiving
The transfer type for the endpoint
The direction in which data is transferred between the endpoint and thehost
pipe, 它用来在逻辑上表示device endpoint和host software之间的联系. 最重要的一个pipe, 是用来连接host和endpoint zero的.
stream pipe, 非USB-define format的数据
message pipe, USB-define format的数据
- Enumeration
它由host和device侧的USB logical layer共同配合完成.
USB标准定义了标注流程:
1. The USB device is attached to the host, which receives an event indicating a change in the pipe’s status. The USB device is in the powered state, and the port it is attached to is disabled.
2. The host queries about the change in the bus.
3. Once the host determines that a new device is attached, it waits for at least 100ms for the device to become stable after power, after which it enables and resets the port.
4. After a successful reset, the USB device is in a default state and can draw power to a range of 100 mA from VBUS pin.
5. Once the device is in a default state, the host assigns a unique address to the USB device, which moves the device to an address state.
6. The host starts communicating with the USB device in the default control pipe and reads the device descriptor.
7. Subsequently, the host reads the device configuration information.
8. The host selects the configuration, which move the device to a configured state and makes it ready for use.
Description
标准定义device, configuration,interface, endpoint, string五类description.
- USB Transfers
定义了4种transfer, 它们都描述了下述的属性:
n Direction of communication flow
n Constraint in the packet size
n Bus access constraints
n Latency constraints
n Required data sequences
n Error handling
Control Transfer,
Bulk Transfer, 大数据
Interrupt Transfer, 小数据
Isochronous Transfer, audio,video之类的实时大数据
- 一些重要术语
Short packet. A short packet can be defined as a packet whose payload is
shorter than the maximum size or zero length packet (ZLP). A short
packet could indicate the end of a transfer.
Zero length packet (ZLP). A zero length data packet transfer does not
contain data as part of the transfer. When the data to be sent is an exact
multiple of wMaxPacketSize, a ZLP has to be sent after the data transfer
is complete to indicate the end of the transfer. Sometimes a ZLP feature
is implemented as part of the hardware or has to be taken care when
designing Chapter 9/USB.
STALL. A STALL indicates that a function is unable to transmit or
receive data or that even a control pipe request is not supported. The
state of a function after returning a STALL is undefined.
第三章, Overview of the linux USB Subsystem
- Linux kernel中的USB相关代码结构
- 关于Gadget subsystem
USB controller driver实现了USB device controller, 它