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.

740 /* Calculate and store the pipe values */<br />

741 us->send_ctrl_pipe = usb_sndctrlpipe(us->pusb_dev, 0);<br />

742 us->recv_ctrl_pipe = usb_rcvctrlpipe(us->pusb_dev, 0);<br />

743 us->send_bulk_pipe = usb_sndbulkpipe(us->pusb_dev,<br />

744 ep_out->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);<br />

745 us->recv_bulk_pipe = usb_rcvbulkpipe(us->pusb_dev,<br />

746 ep_in->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);<br />

747 if (ep_int) {<br />

748 us->recv_intr_pipe = usb_rcvintpipe(us->pusb_dev,<br />

749 ep_int->bEndpointAddress &<br />

USB_ENDPOINT_NUMBER_MASK);<br />

750 us->ep_bInterval = ep_int->bInterval;<br />

751 }<br />

752 return 0;<br />

753 }<br />

这个函数应该可以说是我们这几个无聊的函数中最后一个了,但它也是相对来说最复杂的一个.请容我<br />

慢慢给您道来.702 行,us->pusb_intf,可还记得,在associate_dev 中赋得值,如不记得请回过去查一<br />

下.<br />

55<br />

没错,us->pusb_intf 就是我们故事中最开始一再提到的那个interface(指针).而它的成员<br />

cur_altsetting,就是当前的setting,或者说设置.在讲associate_dev 的时候也已经遇到过,是一个<br />

struct usb_host_interface 的结构体指针.现在这里用另一个指针临时代替一下, altsetting.接下来会<br />

用<br />

到它的成员,desc 和endpoint.回顾struct usb_host_interface,可以看到,它这两个成员,struct<br />

usb_interface_descriptor desc,和struct usb_host_endpoint *endpoint.其中,desc 不用多说,正<br />

是<br />

这个interface 的接口描述符,而endpoint 这个指针记录的是几个endpoint,它们以数组的形式被存储,<br />

而endpoint 指向数组头.这些冬冬都是在usb core 枚举的时候就设置好了,我们无需操任何心,只需拿来<br />

用就是了.这里给出struct usb_host_endpoint 的定义,来自include/linux/usb.h:<br />

43 /* host-side wrapper for parsed endpoint descriptors */<br />

44 struct usb_host_endpoint {<br />

45 struct usb_endpoint_descriptor desc;<br />

46<br />

47 unsigned char *extra; /* Extra descriptors */<br />

48 int extralen;<br />

49 };<br />

接着定义了几个struct usb_endpoint_descriptor 的结构体指针.顾名思义,这就是对应endpoint 的<br />

描述符的.其定义来自于include/linux/usb_ch9.h:<br />

260 /* USB_DT_ENDPOINT: Endpoint descriptor */<br />

261 struct usb_endpoint_descriptor {<br />

262 __u8 bLength;<br />

263 __u8 bDescriptorType;<br />

264<br />

265 __u8 bEndpointAddress;

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

Saved successfully!

Ooh no, something went wrong!