25.2.4 USB驱动程序框架
Linux内核代码driver/usb/usb-skeleton.c文件是一个标准的USB设备驱动程序。编写一个USB设备的驱动可以参考usb-skeleton.c文件,实际上,可以直接修改该文件驱动新的USB设备。下面以usb-skeleton.c文件为例分析usb-skel设备驱动框架。
1.基本数据结构
usb-skel设备使用自定义结构usb_skel记录设备驱动用到的所有描述符,该结构定义如下:struct usb_skel {
struct usb_device * udev; /* the usb device for
this device */
// USB设备描述符
struct usb_interface * interface; /* the
interface for this device
*/
// USB接口描述符
struct semaphore limit_sem; /* limiting
the number of writes in
progress */
// 互斥信号量
unsigned char * bulk_in_buffer; /* the
buffer to receive data */
// 数据接收缓冲区
size_t bulk_in_size; /* the size
of the receive buffer */
// 数据接收缓冲区大小
__u8 bulk_in_endpointAddr; /* the
a