USB卷五USB设备的枚举过程
LK版本:2.6.35.3
2013年1月14日 任务目标:
分析整理USB设备枚举过程;
本文要点:
1、USB设备枚举数据结构;
2、USB设备枚举流程;
硬件框图:
2
数据结构:
descriptor usb_device{} *config
… …
**rawdescriptors bLength usb_device_descriptor{} bDescriptorType bNumConfigurations desc usb_host_config{} intf_cache[] … …
… …
每个配置
bLength usb_config_descriptor{} bDescriptorType wTotalLength bNumInterfaces num_altsetting usb_interface_cache{} altsetting[0] … …
bConfigurationValue 每个接口cache
… …
desc usb_host_interface{} *endpoint … …
bLength usb_interface_descriptor{} bDescriptorType bInterfaceNumber bAlternateSetting
bNumEndpoints … …
desc usb_host_endpoint{} urb_list … …
bLength usb_endpoint_descriptor{} bDescriptorType bEndpointAddress bmAttributes bInterval … …
每个端点
每个接口设置
成员说明:
struct usb_device { … …; struct device dev; /* generic device interface */ struct usb_device_descriptor descriptor; /* descriptor*/
struct usb_host_config *config; /* all of the configs */
struct usb_host_config *actconfig; /*the active configuration */ … …; char **rawdescriptors; /* raw descriptors for each config */ … …; char *product; /*iProduct string, if present */
char *manufacturer; /*iManufacturer string, if present */ char *serial;
/*iSerialNumber string,if present */
};
struct usb_device_descriptor { __u8 bLength; __u8 bDescriptorType; __le16 bcdUSB; __u8 bDeviceClass; __u8 bDeviceSubClass; __u8 bDeviceProtocol; __u8 bMaxPacketSize0; __le16 idVendor; __le16 idProduct; __u8 bNumConfigurations;
...... }
bLength :描述符的长度 #define USB_DT_DEVICE_SIZE 18; bDescriptorType :值为USB_DT_DEVICE :0x01
bcdUSB :USB spec 的版本号,如果是2.0版本,值为0x0200,如是1.1版本,则值 为0x0110。
bDeviceClass bDeviceSubClass bDeviceProtocol
idVendor idProduct
bMaxPacketSize0:端点0一次可以处理的最大字节数。 Q:为什么要放在设备描述符里呢?
A:由于它自己没有一个描述符,而每个设备又都有这么一个端点
所以这个信息被保存在了设备描述符里,其中,这个值只能是 8,16,32或64这四者之一,高速模式值只能为64, 低速模式 只能为8,对于中速,可以为8,16,32,64,单位字节。
bNumConfigurations :设备当前速度模式下支持的配置数量
分别指每个设备属于一个Class ,然后Class 下面又分了 SubClass ,SubClass 下面又按各种设备遵循的不同的通信协议继续细分 设备的厂商和ID 号,在USB 设备与驱动匹配时会用
到此成员参数 包括两份:一份来自USB 接口