📄 usbdcore.lst
字号:
248 */
249 struct usb_interface_descriptor *usbd_device_interface_descriptor (struct usb_device_instance
250 *device, int port, int configuration, int interface, int alternate)
251 {
252 struct usb_interface_instance *interface_instance;
253 if (!(interface_instance = usbd_device_interface_instance (device, port, configuration, interface))) {
254 return NULL;
255 }
256 if ((alternate < 0) || (alternate >= interface_instance->alternates)) {
257 return NULL;
258 }
259 return (interface_instance->alternates_instance_array[alternate].interface_descriptor);
260 }
261
262 /**
263 * usbd_device_endpoint_descriptor_index
264 * @device: which device
265 * @port: which port
266 * @configuration: index to configuration, 0 - N-1
267 * @interface: index to interface
268 * @alternate: index setting
269 * @index: which index
270 *
271 * Return the specified endpoint descriptor for the specified device.
272 */
273 struct usb_endpoint_descriptor *usbd_device_endpoint_descriptor_index (struct usb_device_instance
274 *device, int port, int configuration, int interface, int alternate, int index)
275 {
276 struct usb_alternate_instance *alternate_instance;
277
278 if (!(alternate_instance = usbd_device_alternate_instance (device, port, configuration, interface, altern
-ate))) {
279 return NULL;
280 }
281 if (index >= alternate_instance->endpoints) {
282 return NULL;
283 }
284 return *(alternate_instance->endpoints_descriptor_array + index);
285 }
286
287
288 /**
289 * usbd_device_endpoint_transfersize
290 * @device: which device
291 * @port: which port
292 * @configuration: index to configuration, 0 - N-1
293 * @interface: index to interface
294 * @index: which index
295 *
296 * Return the specified endpoint transfer size;
C51 COMPILER V8.09 USBDCORE 05/05/2008 19:48:28 PAGE 9
297 */
298 int usbd_device_endpoint_transfersize (struct usb_device_instance *device, int port, int configuration, in
-t interface, int alternate, int index)
299 {
300 struct usb_alternate_instance *alternate_instance;
301
302 if (!(alternate_instance = usbd_device_alternate_instance (device, port, configuration, interface, altern
-ate))) {
303 return 0;
304 }
305 if (index >= alternate_instance->endpoints) {
306 return 0;
307 }
308 return *(alternate_instance->endpoint_transfersize_array + index);
309 }
310
311
312 /**
313 * usbd_device_endpoint_descriptor
314 * @device: which device
315 * @port: which port
316 * @configuration: index to configuration, 0 - N-1
317 * @interface: index to interface
318 * @alternate: alternate setting
319 * @endpoint: which endpoint
320 *
321 * Return the specified endpoint descriptor for the specified device.
322 */
323 struct usb_endpoint_descriptor *usbd_device_endpoint_descriptor (struct usb_device_instance *device, int p
-ort, int configuration, int interface, int alternate, int endpoint)
324 {
325 struct usb_endpoint_descriptor *endpoint_descriptor;
326 int i;
327
328 for (i = 0; !(endpoint_descriptor = usbd_device_endpoint_descriptor_index (device, port, configuration, i
-nterface, alternate, i)); i++) {
329 if (endpoint_descriptor->bEndpointAddress == endpoint) {
330 return endpoint_descriptor;
331 }
332 }
333 return NULL;
334 }
335
336 /**
337 * usbd_endpoint_halted
338 * @device: point to struct usb_device_instance
339 * @endpoint: endpoint to check
340 *
341 * Return non-zero if endpoint is halted.
342 */
343 int usbd_endpoint_halted (struct usb_device_instance *device, int endpoint)
344 {
345 return (device->status == USB_STATUS_HALT);
346 }
347
348
349 /**
350 * usbd_rcv_complete - complete a receive
351 * @endpoint:
352 * @len:
353 * @urb_bad:
354 *
C51 COMPILER V8.09 USBDCORE 05/05/2008 19:48:28 PAGE 10
355 * Called from rcv interrupt to complete.
356 */
357 void usbd_rcv_complete(struct usb_endpoint_instance *endpoint, int len, int urb_bad)
358 {
359 if (endpoint) {
360 struct urb *rcv_urb;
361
362 /*usbdbg("len: %d urb: %p\n", len, endpoint->rcv_urb); */
363
364 /* if we had an urb then update actual_length, dispatch if neccessary */
365 if ((rcv_urb = endpoint->rcv_urb)) {
366
367 /*usbdbg("actual: %d buffer: %d\n", */
368 /*rcv_urb->actual_length, rcv_urb->buffer_length); */
369
370 /* check the urb is ok, are we adding data less than the packetsize */
371 if (!urb_bad && (len <= endpoint->rcv_packetSize)) {
372 /*usbdbg("updating actual_length by %d\n",len); */
373
374 /* increment the received data size */
375 rcv_urb->actual_length += len;
376
377 } else {
378 usberr(" RECV_ERROR actual: %d buffer: %d urb_bad: %d\n",
379 rcv_urb->actual_length, rcv_urb->buffer_length, urb_bad);
380
381 rcv_urb->actual_length = 0;
382 rcv_urb->status = RECV_ERROR;
383 }
384 } else {
385 usberr("no rcv_urb!");
386 }
387 } else {
388 usberr("no endpoint!");
389 }
390
391 }
392
393 /**
394 * usbd_tx_complete - complete a transmit
395 * @endpoint:
396 * @resetart:
397 *
398 * Called from tx interrupt to complete.
399 */
400 void usbd_tx_complete (struct usb_endpoint_instance *endpoint)
401 {
402 if (endpoint) {
403 struct urb *tx_urb;
404
405 /* if we have a tx_urb advance or reset, finish if complete */
406 if ((tx_urb = endpoint->tx_urb)) {
407 int sent = endpoint->last;
408 endpoint->sent += sent;
409 endpoint->last -= sent;
410
411 if( (endpoint->tx_urb->actual_length - endpoint->sent) <= 0 ) {
412 tx_urb->actual_length = 0;
413 endpoint->sent = 0;
414 endpoint->last = 0;
415
416 /* Remove from active, save for re-use */
C51 COMPILER V8.09 USBDCORE 05/05/2008 19:48:28 PAGE 11
417 urb_detach(tx_urb);
418 urb_append(&endpoint->done, tx_urb);
419 /*usbdbg("done->next %p, tx_urb %p, done %p", */
420 /* endpoint->done.next, tx_urb, &endpoint->done); */
421
422 endpoint->tx_urb = first_urb_detached(&endpoint->tx);
423 if( endpoint->tx_urb ) {
424 endpoint->tx_queue--;
425 usbdbg("got urb from tx list");
426 }
427 if( !endpoint->tx_urb ) {
428 /*usbdbg("taking urb from done list"); */
429 endpoint->tx_urb = first_urb_detached(&endpoint->done);
430 }
431 if( !endpoint->tx_urb ) {
432 usbdbg("allocating new urb for tx_urb");
433 endpoint->tx_urb = usbd_alloc_urb(tx_urb->device, endpoint);
434 }
435 }
436 }
437 }
438 }
439
440 /* URB linked list functions ***************************************************** */
441
442 /*
443 * Initialize an urb_link to be a single element list.
444 * If the urb_link is being used as a distinguished list head
445 * the list is empty when the head is the only link in the list.
446 */
447 void urb_link_init (urb_link * ul)
448 {
449 if (ul) {
450 ul->prev = ul->next = ul;
451 }
452 }
453
454 /*
455 * Detach an urb_link from a list, and set it
456 * up as a single element list, so no dangling
457 * pointers can be followed, and so it can be
458 * joined to another list if so desired.
459 */
460 void urb_detach (struct urb *urb)
461 {
462 if (urb) {
463 urb_link *ul = &urb->link;
464 ul->next->prev = ul->prev;
465 ul->prev->next = ul->next;
466 urb_link_init (ul);
467 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -