Linux驱动程序笔记5——usb概述2

来源:互联网 发布:男生喜欢手办恶心知乎 编辑:程序博客网 时间:2024/05/16 12:02

struct usb_device {

intdevnum;     //设备号,也称设备地址
chardevpath[16];
u32route;
enum usb_device_statestate; 
enum usb_device_speedspeed; 

struct usb_tt*tt;
intttport;

unsigned int toggle[2];

struct usb_device *parent;
struct usb_bus *bus;     //usb设备所在的总线
        //0号端口,可以双向传输
struct usb_host_endpoint ep0; //usb主机端口结构体,详见注释1

struct device dev;

struct usb_device_descriptor descriptor;//usb设备描述符,详见注释2
struct usb_host_bos *bos;
struct usb_host_config *config;

struct usb_host_config *actconfig; //配置结构体,详见注释3
         //由此我们看出usb最多支持33个端口,1个控制端口,16个输入端口,16个输出端口
struct usb_host_endpoint *ep_in[16];//输入端口
struct usb_host_endpoint *ep_out[16];//输出端口

char **rawdescriptors;

unsigned short bus_mA;
u8 portnum;
u8 level;

unsigned can_submit:1;
unsigned persist_enabled:1;
unsigned have_langid:1;
unsigned authorized:1;
unsigned authenticated:1;
unsigned wusb:1;
unsigned lpm_capable:1;
unsigned usb2_hw_lpm_capable:1;
unsigned usb2_hw_lpm_enabled:1;
int string_langid;

/* static strings from the device */
char *product;
char *manufacturer;
char *serial;

struct list_head filelist;
#ifdef CONFIG_USB_DEVICE_CLASS
struct device *usb_classdev;
#endif
#ifdef CONFIG_USB_DEVICEFS
struct dentry *usbfs_dentry;
#endif

int maxchild;
struct usb_device **children;

u32 quirks;
atomic_t urbnum;

unsigned long active_duration;

#ifdef CONFIG_PM
unsigned long connect_time;

unsigned do_remote_wakeup:1;
unsigned reset_resume:1;
#endif
struct wusb_dev *wusb_dev;
int slot_id;
enum usb_device_removable removable;
};

注释1:
struct usb_host_endpoint {
struct usb_endpoint_descriptordesc; //端口描述符,详见注释1-1
struct usb_ss_ep_comp_descriptorss_ep_comp;
struct list_headurb_list;  //本端点的请求块的队列
void*hcpriv;
struct ep_device*ep_dev; /* For sysfs info */

unsigned char *extra;   /* Extra descriptors */
int extralen;
int enabled;
};

注释1-1:
struct usb_endpoint_descriptor {
__u8  bLength;
__u8  bDescriptorType;

__u8  bEndpointAddress;  //端口地址
__u8  bmAttributes;
__le16 wMaxPacketSize; //一次传输的最大数据量
__u8  bInterval;

/* NOTE:  these two are _only_ in audio endpoints. */
/* use USB_DT_ENDPOINT*_SIZE in bLength, not sizeof. */
__u8  bRefresh;
__u8  bSynchAddress;
} __attribute__ ((packed));

注释2:
struct usb_device_descriptor {
__u8  bLength;
__u8  bDescriptorType;

__le16 bcdUSB;
__u8  bDeviceClass;
__u8  bDeviceSubClass;
__u8  bDeviceProtocol;
__u8  bMaxPacketSize0;//一次传输的最大数据量
__le16 idVendor;
__le16 idProduct;
__le16 bcdDevice;
__u8  iManufacturer;
__u8  iProduct;
__u8  iSerialNumber;
__u8  bNumConfigurations;
} __attribute__ ((packed));

注释3:
struct usb_host_config {
struct usb_config_descriptordesc; //配置描述符,详见注释3-1

char *string;/* iConfiguration string, if present */

         //接口代表一种功能,而配置是功能的组合
struct usb_interface_assoc_descriptor *intf_assoc[USB_MAXIADS];

/* the interfaces associated with this configuration,
 * stored in no particular order */
struct usb_interface *interface[USB_MAXINTERFACES];

/* Interface information available even when this is not the
 * active configuration */
struct usb_interface_cache *intf_cache[USB_MAXINTERFACES];

unsigned char *extra;   /* Extra descriptors */
int extralen;
};