📄 usb_drv.lst
字号:
260 2 usb_mass_storage_get_lun();
261 2 break;
262 2 case MASS_STORAGE_RESET:
263 2 usb_mass_storage_reset();
264 2 break;
265 2 default:
266 2 Usb_set_STALLRQ();
267 2 while (!Usb_STALL_sent());
268 2 Usb_clear_STALLRQ();
269 2 Usb_clear_STALLED();
270 2 break;
271 2 }
272 1 }
273
274
275 /*F**************************************************************************
276 * NAME: usb_set_address
277 *----------------------------------------------------------------------------
278 * PARAMS:
279 *
280 * return:
281 *----------------------------------------------------------------------------
282 * PURPOSE:
283 * This function manages the SET_ADDRESS request. The new address is stored
284 * in the USBADDR register
285 *----------------------------------------------------------------------------
286 * EXAMPLE:
287 *----------------------------------------------------------------------------
288 * NOTE:
289 *----------------------------------------------------------------------------
290 * REQUIREMENTS:
291 *****************************************************************************/
292 void usb_set_address (void)
293 {
294 1 Byte add;
295 1
296 1 Usb_clear_DIR();
297 1 add = Usb_read_byte(); /* store the LSB of wValue = address */
298 1 UEPRST = 0x01 ;
299 1 UEPRST = 0x00 ;
300 1 Usb_clear_RXSETUP();
301 1 Usb_set_TXRDY(); /* send a ZLP for STATUS phase */
302 1 Usb_set_FADDEN();
C51 COMPILER V6.20c USB_DRV 07/10/2002 15:17:37 PAGE 6
303 1 while (!(Usb_tx_complete()));
304 1 Usb_clear_TXCMPL();
305 1 Usb_configure_address(add);
306 1 }
307
308
309 /*F**************************************************************************
310 * NAME: usb_set_configuration
311 *----------------------------------------------------------------------------
312 * PARAMS:
313 *
314 * return:
315 *----------------------------------------------------------------------------
316 * PURPOSE:
317 * This function manages the SET_CONFIGURATION request.
318 *----------------------------------------------------------------------------
319 * EXAMPLE:
320 *----------------------------------------------------------------------------
321 * NOTE:
322 *----------------------------------------------------------------------------
323 * REQUIREMENTS:
324 *****************************************************************************/
325 void usb_set_configuration (void)
326 {
327 1 Usb_clear_DIR();
328 1 Usb_clear_RXSETUP();
329 1 Usb_set_TXRDY(); /* send a ZLP for STATUS phase */
330 1 Usb_set_CONFG();
331 1 while (!Usb_tx_complete());
332 1 Usb_clear_TXCMPL();
333 1 Usb_select_ep(EP_IN); /* endpoints configuration */
334 1 UEPCONX = BULK_IN ;
335 1 Usb_select_ep(EP_OUT);
336 1 UEPCONX = BULK_OUT;
337 1 }
338
339
340 /*F**************************************************************************
341 * NAME: usb_get_descriptor
342 *----------------------------------------------------------------------------
343 * PARAMS:
344 *
345 * return:
346 *----------------------------------------------------------------------------
347 * PURPOSE:
348 * This function manages the GET_DESCRIPTOR request.
349 *----------------------------------------------------------------------------
350 * EXAMPLE:
351 *----------------------------------------------------------------------------
352 * NOTE:
353 *----------------------------------------------------------------------------
354 * REQUIREMENTS:
355 *****************************************************************************/
356 void usb_get_descriptor (void)
357 {
358 1 Byte data_to_transfer;
359 1 Uint16 wLength;
360 1 Byte descriptor_type;
361 1 Byte string_type;
362 1
363 1 Usb_set_DIR(); /* set out on EP0 */
364 1 zlp = FALSE; /* no zero length packet */
C51 COMPILER V6.20c USB_DRV 07/10/2002 15:17:37 PAGE 7
365 1
366 1 string_type = Usb_read_byte(); /* read LSB of wValue */
367 1 descriptor_type = Usb_read_byte(); /* read MSB of wValue */
368 1 switch (descriptor_type)
369 1 {
370 2 case DEVICE:
371 2 {
372 3 data_to_transfer = sizeof (usb_device_descriptor);
373 3 pbuffer = &(usb_device_descriptor.bLength);
374 3 break;
375 3 }
376 2
377 2 case CONFIGURATION:
378 2 {
379 3 data_to_transfer = sizeof (usb_configuration);
380 3 pbuffer = &(usb_configuration.cfg.bLength);
381 3 break;
382 3 }
383 2
384 2 case STRING:
385 2 {
386 3 switch (string_type)
387 3 {
388 4 case LANG_ID:
389 4 {
390 5 data_to_transfer = sizeof (usb_language);
391 5 pbuffer = &(usb_language.bLength);
392 5 break;
393 5 }
394 4 case MAN_INDEX:
395 4 {
396 5 data_to_transfer = sizeof (usb_manufacturer);
397 5 pbuffer = &(usb_manufacturer.bLength);
398 5 break;
399 5 }
400 4 case PROD_INDEX:
401 4 {
402 5 data_to_transfer = sizeof (usb_product);
403 5 pbuffer = &(usb_product.bLength);
404 5 break;
405 5 }
406 4 case SN_INDEX:
407 4 {
408 5 data_to_transfer = sizeof (usb_serial_number);
409 5 pbuffer = &(usb_serial_number.bLength);
410 5 break;
411 5 }
412 4 default:
413 4 {
414 5 Usb_clear_RXSETUP();
415 5 while (!Usb_setup_received())
416 5 {
417 6 Usb_set_STALLRQ(); /* send stall */
418 6 while ((!(Usb_STALL_sent())) && (Usb_setup_received()));
419 6 Usb_clear_STALLED();
420 6 Usb_clear_STALLRQ();
421 6 }
422 5 Usb_clear_DIR(); /* set in on EP0 */
423 5 return;
424 5 }
425 4 }
426 3 break;
C51 COMPILER V6.20c USB_DRV 07/10/2002 15:17:37 PAGE 8
427 3 }
428 2
429 2 default:
430 2 {
431 3 Usb_clear_RXSETUP();
432 3 while (!Usb_setup_received())
433 3 {
434 4 Usb_set_STALLRQ(); /* send stall */
435 4 while ((!(Usb_STALL_sent())) && (Usb_setup_received()));
436 4 Usb_clear_STALLED();
437 4 Usb_clear_STALLRQ();
438 4 }
439 3 Usb_clear_DIR(); /* set in on EP0 */
440 3 return;
441 3 }
442 2 }
443 1
444 1 ACC = Usb_read_byte(); /* don't care of wIndex field */
445 1 ACC = Usb_read_byte();
446 1 ((Byte*)&wLength)[1] = Usb_read_byte(); /* read wLength */
447 1 ((Byte*)&wLength)[0] = Usb_read_byte();
448 1 if (wLength > data_to_transfer)
449 1 {
450 2 if ((data_to_transfer % EP_CONTROL_LENGTH) == 0)
451 2 {
452 3 zlp = TRUE; /* send a zero length packet */
453 3 }
454 2 else
455 2 {
456 3 zlp = FALSE; /* no need of zero length packet */
457 3 }
458 2 }
459 1 else
460 1 {
461 2 data_to_transfer = (Byte)wLength; /* send only requested number of data */
462 2 }
463 1 Usb_clear_RXSETUP() ; /* clear the receive setup flag */
464 1
465 1 while (data_to_transfer > EP_CONTROL_LENGTH)
466 1 {
467 2 pbuffer = send_ep0_packet(pbuffer, EP_CONTROL_LENGTH);
468 2 data_to_transfer -= EP_CONTROL_LENGTH;
469 2 while ((!(Usb_rx_complete())) && (!(Usb_tx_complete())));
470 2 if ((Usb_rx_complete())) /* if no cancel from USB Host */
471 2 {
472 3 Usb_clear_RXOUT();
473 3 return;
474 3 }
475 2 if (Usb_tx_complete())
476 2 {
477 3 Usb_clear_TXCMPL();
478 3 }
479 2 }
480 1 /* send last data packet */
481 1 pbuffer = send_ep0_packet(pbuffer, data_to_transfer);
482 1 data_to_transfer = 0;
483 1 while ((!(Usb_rx_complete())) && (!(Usb_tx_complete())));
484 1 if ((Usb_rx_complete())) /* if no cancel from USB Host */
485 1 {
486 2 Usb_clear_RXOUT();
487 2 return;
488 2 }
C51 COMPILER V6.20c USB_DRV 07/10/2002 15:17:37 PAGE 9
489 1 if (Usb_tx_complete())
490 1 {
491 2 Usb_clear_TXCMPL();
492 2 }
493 1 if (zlp == TRUE)
494 1 {
495 2 send_ep0_packet(pbuffer, 0);
496 2 while ((!(Usb_rx_complete())) && (!(Usb_tx_complete())));
497 2 if ((Usb_rx_complete())) /* if no cancel from USB Host */
498 2 {
499 3 Usb_clear_RXOUT();
500 3 return;
501 3 }
502 2 if (Usb_tx_complete())
503 2 {
504 3 Usb_clear_TXCMPL();
505 3 }
506 2 }
507 1 while ((!(Usb_rx_complete())) && (!(Usb_setup_received())));
508 1 if (Usb_setup_received())
509 1 {
510 2 return;
511 2 }
512 1
513 1 if (Usb_rx_complete())
514 1 {
515 2 Usb_clear_DIR(); /* set in on EP0 */
516 2 Usb_clear_RXOUT();
517 2 }
518 1 }
519
520
521 /*F**************************************************************************
522 * NAME: usb_get_configuration
523 *----------------------------------------------------------------------------
524 * PARAMS:
525 *
526 * return:
527 *----------------------------------------------------------------------------
528 * PURPOSE:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -