Linux USB Device Driver Primer
来源:互联网 发布:阿芙 知乎 编辑:程序博客网 时间:2024/05/18 12:41
Linux USB Device driverProgramming
Data Flow Types
~~~~~~~~~~~~~~~~
a) Controltransfers:are used to request and send reliableshort data packets. It is used to configure devices and every one isrequired to support a minimum set of control commands. Here is a listof standard commands:
GET_STATUS
CLEAR_FEATURE
SET_FEATURE
SET_ADDRESS
GET_DESCRIPTOR
SET_DESCRIPTOR
GET_CONFIGURATION
SET_CONFIGURATION
GET_INTERFACE
SET_INTERFACE
SYNCH_FRAME
b) Bulktransfers: are used to request or send reliable data packets upto the full bus bandwidth. Devices like scanners or scsi adapters usethis transfer type.
c) Interrupttransfers: are similar to bulk transfers which are polledperiodically. If an interrupt transfer was submitted the hostcontroller driver will automatically repeat this request in aspecified interval.
d) Isochronoustransfers: send or receive data streams in <realtime> withguaranteed bus bandwidth but without any reliability. In generalthese transfer types are used for audio and video devices.
StandardDescriptors
~~~~~~~~~~~~~~~~~~~~
USBDescriptor Hierarchy
a) Device Descriptor
# structusb_device;
describesgeneral information about a USB device. It includes information thatapplies globally to the device and all of the device'sconfigurations. A USB device has only one device descriptor
用于描述整个USB设备,包含该设备的基本信息。一个设备只有一个usb_device.
包括:
struct usb_device*parent; //所属的USB HUB
struct usb_bus*bus; //所属总线
structusb_host_endpoint ep0; //endpoint 0 data (default control pipe)
struct devicedev; //Kernel基本设备信息:device list,便于kernel统一管理device
structusb_device_descriptor descriptor; //设备描述符:VendorID ProductID ……(来至硬件)
structusb_host_config *config; //所有可用配置
structusb_host_config *actconfig; //当前激活的配置
structusb_host_endpoint *ep_in[16]; //array of IN endpoints
structusb_host_endpoint *ep_out[16]; //array of OUT endpoints
b) ConfigurationDescriptor
# structusb_host_config;
Configurations can be activated exclusively by the standard controltransfer set_configuration. Different configurations can be used tochange <global> device settings like power consumption.
包括:
structusb_config_descriptor desc; //配置描述符:power接口(来至硬件)
char*string; //String 描述符:厂商名,产品名(来至硬件)
/* List of anyInterface Association Descriptors in this configuration. */
structusb_interface_assoc_descriptor *intf_assoc[USB_MAXIADS]; //Interface Association
/* the interfacesassociated with this configuration*/
structusb_interface *interface[USB_MAXINTERFACES]; //当前配置下拥有的接口
/* Interfaceinformation available even when this is not the active configuration*/
structusb_interface_cache *intf_cache[USB_MAXINTERFACES];
c) InterfaceDescriptor
# structusb_interface;
An interfacemay include alternate settings that allow the endpoints and/or theircharacteristics to be varied after the device has been configured.Alternate settings can be selected exclusively by the standardcontrol transfer set_interface. For example a multifunctional devicelike a video camera with internal microphone could have threealternate settings to change the bandwidth allocation on the bus.
* Cameraactivated
* Microphoneactivated
* Camera andmicrophone activated
使用哪些端点采用何种方式进行通信。
每个interface用多种设置。
包括:
structusb_host_interface *altsetting; //该接口可用的设置
structusb_host_interface *cur_altsetting; //当前使用的设置:对应的端点
structusb_interface_assoc_descriptor *intf_assoc; //接口描述符组:端点个数,可用设置(来至硬件)
struct devicedev;
struct device*usb_dev;
d)SettingDescriptor
structusb_host_interface;
很简单,仅包括该设置对应的接口描述符及对应端点。
包括:
structusb_interface_descriptor desc; //接口描述符
structusb_host_endpoint *endpoint; //端点
e) EndpointDescriptor
# structusb_host_endpoint;
Contain URBqueue list.contains information required by the host to determine thebandwidth requirements of each endpoint. An endpoint represents alogical data source or sink of a USB device. Endpoint zero is usedfor all standard control transfers and there is never a descriptorfor this endpoint. The USB specification [4] uses the term pipe foran endpoint too.
数据传送。
包括:
structusb_endpoint_descriptor desc; //端点描述符:端点类型IN/OUTinterrupt/Bulk(来至硬件)
structusb_ss_ep_comp_descriptor ss_ep_comp; //SuperSpeed companiondescriptor for this endpoint
struct list_head urb_list; //端点对应URB List
struct ep_device *ep_dev; /* For sysfs info */
f) Driver
struct usb_driver;
一个interface对应一个usb_driver
identifies USB<interface> driver to usbcore. Connect to structusb_interface.
USB <interface>drivers must provide a name, probe() and disconnect() methods, and anid_table.
包括:
callbackFuncs.
probe(); Called to see if the driver is willing to manage a particular
* interfaceon a device. If it is, probe returns zero and uses
* usb_set_intfdata() to associate driver-specific data with the
* interface. It may also use usb_set_interface() to specify the
* appropriate altsetting.
Device Classes
~~~~~~~~~~~~
USBDevice Classes
DeviceClass
ExampleDevice
Display
Monitor
Communication
Modem
Audio
Speakers
Massstorage
Harddrive
Humaninterface
Dataglove
Grouping devices or interfaces together in classes and thenspecifying the characteristics in a Class Specification allows thedevelopment of host software which can manage multipleimplementations based on that class. A class specification servesas a framework defining the minimum operation of all devices orinterfaces which identify themselves as members of the class.
URB
~~~~
# struct urb
The Linux USBsubsystem uses <only one> data transfer structure called USBRequest Block (URB).
The URB structurecontains all parameters to setup any USB transfer type. All transferrequests are sent asynchronously to the USB core and the completionof the request is signalled via a callback function.
URB functions:
*purb_tusb_alloc_urb(int iso_packets);
*voidusb_free_urb (purb_t purb);
*usb_fill_bulk_urb(); //Initializes a bulk urb with the properinformation needed to submit it to a device.
*intusb_submit_urb(purb_t purb); //This function sends a transferrequest asynchronously to the USB core.
*intusb_unlink_urb(purb_t purb); //This function cancels a scheduledrequest before it is completed.
<CompatibilityWrappers>
*intusb_control_msg(); //Issues a blocking standard control request.
*intusb_bulk_msg(); //Issues a blocking bulk transfer.
USB devicedriver example
~~~~~~~~~~~~~~~~~~~~~~
非常完善的例子
USB device driverskeleton demo in kernel_doc/drvivers/usb/USB-skeleton.c
- Linux USB Device Driver Primer
- Linux Device Driver ---USB
- linux device driver之usb驱动编程
- understanding linux usb ehci device driver(2)
- understanding linux usb ehci device driver(1)
- understanding linux usb ehci device driver(2)
- understanding linux usb ehci device driver(3)
- Linux下USB HID device driver研究
- understanding linux usb ehci device driver
- understanding linux usb ehci device driver(1)
- understanding linux usb ehci device driver(1)
- understanding linux usb ehci device driver(1)
- understanding linux usb ehci device driver(2)
- understanding linux usb ehci device driver(3)
- Delete usb Device Driver
- How to write a Linux USB Device Driver
- understanding linux usb ehci device driver(1) 1
- understanding linux usb ehci device driver(2)
- error while loading shared libraries,permission denied的问题
- JS通用选项卡
- strcat
- ubuntu 安装tomcat7
- libev timer封装使用
- Linux USB Device Driver Primer
- android 3D游戏开发 - 潜入理解
- LINQ技术
- make英文介绍(实例)
- WMI007-WMI学习笔记(七)——Queries(查询(.NET))
- windows命令
- Struts2 自定义拦截器栈后无法得到表单参数之解决办法
- XML技术
- android内存管理机制