07.06.2013 Views

Scsi - Index of

Scsi - Index of

Scsi - Index of

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

324 struct usb_host_config *actconfig;/* the active configuration */<br />

325<br />

326 char **rawdescriptors; /* Raw descriptors for each config */<br />

327<br />

328 int have_langid; /* whether string_langid is valid yet */<br />

329 int string_langid; /* language ID for strings */<br />

330<br />

331 void *hcpriv; /* Host Controller private data */<br />

332<br />

333 struct list_head filelist;<br />

334 struct dentry *usbfs_dentry; /* usbfs dentry entry for the device */<br />

335<br />

336 /*<br />

337 * Child devices - these can be either new devices<br />

338 * (if this is a hub device), or different instances<br />

339 * <strong>of</strong> this same device.<br />

340 *<br />

341 * Each instance needs its own set <strong>of</strong> data structures.<br />

342 */<br />

343<br />

344 int maxchild; /* Number <strong>of</strong> ports if hub */<br />

345 struct usb_device *children[USB_MAXCHILDREN];<br />

346 };<br />

347 #define to_usb_device(d) container_<strong>of</strong>(d, struct usb_device, dev)<br />

看起来很复杂的一个数据结构,不过我们目前不需要去理解她的每一个成员,不过我们可以看到,其中有一个<br />

成员struct device dev,没错,这就是前面说的那个属于每个设备的struct device 结构体变量.<br />

实际上,U 盘驱动里边并不会直接去处理这个结构体,因为对于一个U 盘来说,她就是对应这么一个struct<br />

usb_device 的变量,这个变量由usb core 负责申请和赋值.但是我们需要记住这个结构体变量,因为日后<br />

我们调用usb core 提供的函数的时候,会把这个变量作为参数传递上去,因为很简单,要和usb core 交流,<br />

总得让人家知道我们是谁吧,比如后来要调用的一个函数,usb_buffer_alloc,它就需要这个参数.<br />

而对U 盘设备驱动来说,比这个struct usb_device 更重要的数据结构是,struct usb_interface.走到这<br />

一步,我们不得不去了解一点usb 设备的规范了,或者专业一点说,usb 协议.因为我们至少要知道什么是<br />

usb interface.<br />

从协议中来,到协议中去(中)<br />

星爷说,人有人他妈,妖有妖他妈.说的就是任何事物都有其要遵守的规矩.usb 设备要遵循的就是usb 协<br />

议. 不管是软件还是硬件,在设计的伊始,总是要参考usb协议.怎么设计硬件,如何编写软件,不看usb协议,<br />

谁也不可能凭空想象出来.毕竟不是写小说,有几人能像海岩那样,光凭想象就能写出便衣警察,永不瞑目,玉<br />

观音这些经典的爱情加案情的作品来呢.<br />

21<br />

usb 协议规定了,每个usb 设备都得有些基本的元素,称为描述符,有四类描述符是任何一种usb 设备都得<br />

有的.他们是,device descriptor,configuration descriptor,interface descriptor,endpoint<br />

descriptor.描述符里的冬冬是一个设备出厂的时候就被厂家给固化在设备里了.这种东西不管怎样也改变

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!