📄 upsd_usb.lst
字号:
530 1 {
531 2 STALL_EP0(); // stall EP0
532 2 }
533 1 }
534
535
536
537
538 static void OnGetInterface()
539 /******************************************************************************
540 Function : static void OnGetInterface()
541 Parameters : none
542 Description: Handler for OnGetInterface() control requests.
543 ******************************************************************************/
544 {
545 1
546 1 #pragma asm // Send back 0 length DATA1 packet
547 1 anl UCON0,#uRX0E+uSTALL0 ;mask, keep RX flag
548 1 orl UCON0,#uTSEQ0+uTX0E ;set TSEQ bit+enable endpoint
549 1 #pragma endasm
550 1
551 1 }
C51 COMPILER V7.06 UPSD_USB 10/15/2004 20:55:31 PAGE 10
552
553
554
555
556 static void OnSetInterface()
557 /******************************************************************************
558 Function : static void OnSetInterface()
559 Parameters : none
560 Description: Handler for SET_INTERFACE() control requests.
561 ******************************************************************************/
562 {
563 1 STALL_EP0(); // No features currently implemented, so stall EP0
564 1 }
565
566
567
568
569
570 static void OnGetDescriptor()
571 /******************************************************************************
572 Function : static void OnGetDescriptor()
573 Parameters : none
574 Description: Handler for GET_DESCRIPTOR() control requests
575 ******************************************************************************/
576 {
577 1 data unsigned int bytesRequested;
578 1
579 1 switch (setupPacket.wValue.hi)
580 1 {
581 2 case
582 2 DT_DEVICE:
583 2 pTransmitBufferEP0 = (uchar*) &deviceDesc;
584 2 bytesToTransmitEP0 = sizeof(deviceDesc);
585 2 break;
586 2
587 2 case
588 2 DT_CONFIGURATION:
589 2 pTransmitBufferEP0 = (uchar*) &configDesc;
590 2 bytesToTransmitEP0 = configDesc.wTotalLength.lo;
591 2 break;
592 2
593 2 case
594 2 DT_STRING:
595 2 pTransmitBufferEP0 = (uchar*) stringDescTable[setupPacket.wValue.lo<4?setupPacket.wValue.lo:4];
596 2 bytesToTransmitEP0 = *pTransmitBufferEP0;// choose requested string
597 2 break;
598 2
599 2 #if HID_DEVICE
600 2 case
601 2 DT_HID_CLASS:
602 2 pTransmitBufferEP0 = (uchar*) &hidClassDesc;
603 2 bytesToTransmitEP0 = hidClassDescSize;
604 2 break;
605 2
606 2 case
607 2 DT_HID_REPORT:
608 2 pTransmitBufferEP0 = (uchar*) &reportDesc;
609 2 bytesToTransmitEP0 = reportDescSize;
610 2 break;
611 2
612 2 case
613 2 DT_HID_PHYSICALD:
C51 COMPILER V7.06 UPSD_USB 10/15/2004 20:55:31 PAGE 11
614 2 pTransmitBufferEP0 = (uchar*) &PhysicalReportDesc;
615 2 bytesToTransmitEP0 = PhysicalReportDescSize;
616 2 break;
617 2
618 2 #endif
619 2
620 2 default:
621 2 STALL_EP0(); // Unrecognized descriptor, so stall EP0
622 2 return;
623 2 }
624 1
625 1 bytesRequested = (setupPacket.wLength.hi << 8) | setupPacket.wLength.lo;
626 1 shortTransfer = (bytesToTransmitEP0 < bytesRequested);
627 1 if (bytesToTransmitEP0 > bytesRequested)
628 1 {
629 2 bytesToTransmitEP0 = bytesRequested;
630 2 }
631 1 UCON0 &= ~uTSEQ0; // TransmitDataEP0 will toggle sequence bit to DATA1
632 1 TransmitBufferEP0();
633 1 }
634
635
636
637
638
639
640 static void OnSetDescriptor()
641 /******************************************************************************
642 Function : static void OnSetDescriptor()
643 Parameters : none
644 Description: Handler for SET_DESCRIPTOR() control requests
645 ******************************************************************************/
646 {
647 1 STALL_EP0(); // No features currently implemented, so stall EP0
648 1 }
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666 BOOL ReadSetupPacket()
667 /******************************************************************************
668 Function : BOOL ReadSetupPacket()
669 Parameters : none
670 Description: Reads a setup packet from EP0.
671 Returns TRUE if successful; stalls the endpoint and returns
672 FALSE on an invalid packet size.
673 ******************************************************************************/
674 {
675 1 data int i;
C51 COMPILER V7.06 UPSD_USB 10/15/2004 20:55:31 PAGE 12
676 1 uchar* p = (uchar*) &setupPacket;
677 1
678 1 if ((USTA & 0x0F) != 8) // Stall EP0 if SETUP packet is not the correct size
679 1 {
680 2 STALL_EP0();
681 2 return FALSE;
682 2 }
683 1
684 1 for (i = 0; i < 8; i++) // Read the setup packet
685 1 {
686 2 *p++ = UDR0;
687 2 }
688 1 USTA |= uRSEQ; // Set data toggle bit (expecting DATA1)
689 1
690 1 return TRUE;
691 1 }
692
693
694
695
696
697
698
699
700
701
702
703 void OnSetupPacket()
704 /******************************************************************************
705 Function : void OnSetupPacket()
706 Parameters : none
707 Description: Basic handler for SETUP packets received on EP0.
708 ******************************************************************************/
709 {
710 1 pTransmitBufferEP0 = NULL;
711 1 bytesToTransmitEP0 = 0;
712 1 // If it's a standard request...
713 1 if ((setupPacket.bmRequestType & 0x60) == 0)
714 1 {
715 2 switch (setupPacket.bRequest) // Handle the request
716 2 {
717 3 case GET_STATUS: OnGetStatus(); return;
718 3 case CLEAR_FEATURE: OnClearFeature(); return;
719 3 case SET_FEATURE: OnSetFeature(); return;
720 3 case SET_ADDRESS: OnSetAddress(); return;
721 3 case GET_DESCRIPTOR: OnGetDescriptor(); return;
722 3 case SET_DESCRIPTOR: OnSetDescriptor(); return;
723 3 case GET_CONFIGURATION: OnGetConfiguration(); return;
724 3 case SET_CONFIGURATION: OnSetConfiguration(); return;
725 3 case GET_INTERFACE: OnGetInterface(); return;
726 3 case SET_INTERFACE: OnSetInterface(); return;
727 3 default:
728 3 break;
729 3 }
730 2 }
731 1 STALL_EP0(); // It's not a request we handle, so stall endpoint
732 1 }
733
734
735
736
737
C51 COMPILER V7.06 UPSD_USB 10/15/2004 20:55:31 PAGE 13
738
739
740
741
742
743
744
745
746 void BaseEp0TxHandler()
747 /******************************************************************************
748 Function : void BaseEp0TxHandler()
749 Parameters : none
750 Description: Handler for successful data transmission on control endpoint (EP0).
751 Use it only for control transfers !!!
752 ******************************************************************************/
753 {
754 1
755 1 if (!TransmitBufferEP0()) // Send next chunk of data in transaction
756 1 {
757 2 // The current request has finished
758 2 if (setupPacket.bRequest == SET_ADDRESS) // The current request has finished
759 2 {
760 3 UADR = setupPacket.wValue.lo | uUSBEN;
761 3 if (setupPacket.wValue.lo != 0)
762 3 usbState = US_ADDRESSED;
763 3 else
764 3 usbState = US_DEFAULT;
765 3 }
766 2 setupPacket.bRequest = REQUEST_COMPLETE;
767 2 }
768 1 }
769
770
771
772
773
774
775
776
777
778 /* *************************************************************************
779 *** ***
780 ** *** End of File *** **
781 *** ***
782 ************************************************************************* */
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1210 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = 14 13
PDATA SIZE = ---- ----
DATA SIZE = ---- 10
IDATA SIZE = 3 ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -