?? usb_drv.lst
字號:
555 * PURPOSE:
556 * This function manages the GET_CONFIGURATION request.
557 *----------------------------------------------------------------------------
558 * EXAMPLE:
559 *----------------------------------------------------------------------------
560 * NOTE:
561 *----------------------------------------------------------------------------
562 * REQUIREMENTS:
563 *****************************************************************************/
564 void usb_get_configuration (void)
565 {
566 1 Usb_clear_RXSETUP();
567 1 Usb_set_DIR();
568 1 if (USBCON & MSK_CONFG)
569 1 {
570 2 Usb_write_byte(1);
571 2 }
572 1 else
573 1 {
574 2 Usb_write_byte(0);
575 2 }
576 1
577 1 Usb_set_TXRDY();
578 1 while (!(Usb_tx_complete()));
579 1 Usb_clear_TXCMPL();
580 1 while (!(Usb_rx_complete()));
581 1 Usb_clear_RXOUT();
582 1 Usb_clear_DIR();
583 1 }
584
585
586 /*F**************************************************************************
587 * NAME: usb_get_status
588 *----------------------------------------------------------------------------
589 * PARAMS:
590 *
591 * return:
592 *----------------------------------------------------------------------------
593 * PURPOSE:
594 * This function manages the GET_STATUS request.
595 *----------------------------------------------------------------------------
596 * EXAMPLE:
597 *----------------------------------------------------------------------------
598 * NOTE:
599 *----------------------------------------------------------------------------
600 * REQUIREMENTS:
601 *****************************************************************************/
602 void usb_get_status (void)
603 {
604 1 Byte wIndex;
605 1
606 1 ACC = Usb_read_byte(); /* dummy read */
607 1 ACC = Usb_read_byte(); /* dummy read */
608 1 wIndex = Usb_read_byte();
609 1 Usb_clear_RXSETUP();
610 1 Usb_set_DIR();
611 1 switch(bmRequestType)
612 1 {
C51 COMPILER V7.02a USB_DRV 09/13/2007 11:53:01 PAGE 11
613 2 case REQUEST_DEVICE_STATUS:
614 2 {
615 3 Usb_write_byte(SELF_POWERED);
616 3 break;
617 3 }
618 2 case REQUEST_INTERFACE_STATUS:
619 2 {
620 3 Usb_write_byte(0x00);
621 3 break;
622 3 }
623 2 case REQUEST_ENDPOINT_STATUS:
624 2 {
625 3 wIndex = wIndex & MSK_EP_DIR;
626 3 Usb_write_byte(endpoint_status[wIndex]);
627 3 break;
628 3 }
629 2 }
630 1 Usb_write_byte(0x00);
631 1 Usb_set_TXRDY();
632 1 while ((!(Usb_tx_complete())) || (Usb_setup_received()));
633 1 Usb_clear_TXCMPL();
634 1 while ((!(Usb_rx_complete())) || (Usb_setup_received()));
635 1 Usb_clear_RXOUT();
636 1 Usb_clear_DIR();
637 1 }
638
639
640 /*F**************************************************************************
641 * NAME: usb_set_feature
642 *----------------------------------------------------------------------------
643 * PARAMS:
644 *
645 * return:
646 *----------------------------------------------------------------------------
647 * PURPOSE:
648 * This function manages the SET_FEATURE request.
649 *----------------------------------------------------------------------------
650 * EXAMPLE:
651 *----------------------------------------------------------------------------
652 * NOTE:
653 *----------------------------------------------------------------------------
654 * REQUIREMENTS:
655 *****************************************************************************/
656 void usb_set_feature (void)
657 {
658 1 if (bmRequestType == ZERO_TYPE)
659 1 {
660 2 Usb_clear_RXSETUP();
661 2 Usb_set_STALLRQ();
662 2 while (!(Usb_STALL_sent()));
663 2 Usb_clear_STALLRQ();
664 2 }
665 1 if (bmRequestType == INTERFACE_TYPE)
666 1 {
667 2 Usb_clear_RXSETUP();
668 2 Usb_set_STALLRQ();
669 2 while (!(Usb_STALL_sent()));
670 2 Usb_clear_STALLRQ();
671 2 }
672 1 if (bmRequestType == ENDPOINT_TYPE)
673 1 {
674 2 if (Usb_read_byte() == 0x00)
C51 COMPILER V7.02a USB_DRV 09/13/2007 11:53:01 PAGE 12
675 2 {
676 3 ACC = Usb_read_byte(); /* dummy read */
677 3 switch (Usb_read_byte()) /* check wIndex */
678 3 {
679 4 case ENDPOINT_1:
680 4 {
681 5 Usb_select_ep(EP_IN);
682 5 Usb_set_STALLRQ();
683 5 Usb_select_ep(EP_CONTROL);
684 5 endpoint_status[1] = 0x01;
685 5 Usb_clear_RXSETUP();
686 5 Usb_set_TXRDY();
687 5 while (!(Usb_tx_complete()));
688 5 Usb_clear_TXCMPL();
689 5 break;
690 5 }
691 4 case ENDPOINT_2:
692 4 {
693 5 Usb_select_ep(EP_OUT);
694 5 Usb_set_STALLRQ();
695 5 Usb_select_ep(EP_CONTROL);
696 5 endpoint_status[2] = 0x01;
697 5 Usb_clear_RXSETUP();
698 5 Usb_set_TXRDY();
699 5 while (!(Usb_tx_complete()));
700 5 Usb_clear_TXCMPL();
701 5 break;
702 5 }
703 4 default:
704 4 {
705 5 Usb_clear_RXSETUP();
706 5 Usb_set_STALLRQ();
707 5 while (!(Usb_STALL_sent()));
708 5 Usb_clear_STALLRQ();
709 5 break;
710 5 }
711 4 }
712 3 }
713 2 }
714 1 }
715
716
717 /*F**************************************************************************
718 * NAME: usb_clear_feature
719 *----------------------------------------------------------------------------
720 * PARAMS:
721 *
722 * return:
723 *----------------------------------------------------------------------------
724 * PURPOSE:
725 * This function manages the SET_FEATURE request.
726 *----------------------------------------------------------------------------
727 * EXAMPLE:
728 *----------------------------------------------------------------------------
729 * NOTE:
730 *----------------------------------------------------------------------------
731 * REQUIREMENTS:
732 *****************************************************************************/
733 void usb_clear_feature (void)
734 {
735 1 if (bmRequestType == ZERO_TYPE)
736 1 {
C51 COMPILER V7.02a USB_DRV 09/13/2007 11:53:01 PAGE 13
737 2 Usb_clear_RXSETUP();
738 2 Usb_set_STALLRQ();
739 2 while (!(Usb_STALL_sent()));
740 2 Usb_clear_STALLRQ();
741 2 }
742 1 if (bmRequestType == INTERFACE_TYPE)
743 1 {
744 2 Usb_clear_RXSETUP();
745 2 Usb_set_STALLRQ();
746 2 while (!(Usb_STALL_sent()));
747 2 Usb_clear_STALLRQ();
748 2 }
749 1 if (bmRequestType == ENDPOINT_TYPE)
750 1 {
751 2 if (Usb_read_byte() == 0x00)
752 2 {
753 3 ACC = Usb_read_byte(); /* dummy read */
754 3 switch (Usb_read_byte()) /* check wIndex */
755 3 {
756 4 case ENDPOINT_1:
757 4 {
758 5 Usb_select_ep(EP_IN);
759 5 if(Usb_STALL_requested())
760 5 {
761 6 Usb_clear_STALLRQ();
762 6 }
763 5 if(Usb_STALL_sent())
764 5 {
765 6 Usb_clear_STALLED();
766 6 }
767 5 UEPRST = 0x02;
768 5 UEPRST = 0x00;
769 5 Usb_select_ep(EP_CONTROL);
770 5 endpoint_status[EP_IN] = 0x00;
771 5 Usb_clear_RXSETUP();
772 5 Usb_set_TXRDY();
773 5 while (!(Usb_tx_complete()));
774 5 Usb_clear_TXCMPL();
775 5 break;
776 5 }
777 4 case ENDPOINT_2:
778 4 {
779 5 Usb_select_ep(EP_OUT);
780 5 if(Usb_STALL_requested())
781 5 {
782 6 Usb_clear_STALLRQ();
783 6 }
784 5 if(Usb_STALL_sent())
785 5 {
786 6 Usb_clear_STALLED();
787 6 }
788 5 UEPRST = 0x04;
789 5 UEPRST = 0x00;
790 5 Usb_select_ep(EP_CONTROL);
791 5 endpoint_status[EP_OUT] = 0x00;
792 5 Usb_clear_RXSETUP();
793 5 Usb_set_TXRDY();
794 5 while (!(Usb_tx_complete()));
795 5 Usb_clear_TXCMPL();
796 5 break;
797 5 }
798 4 case ENDPOINT_0:
C51 COMPILER V7.02a USB_DRV 09/13/2007 11:53:01 PAGE 14
799 4 {
800 5 Usb_clear_RXSETUP();
801 5 Usb_set_TXRDY();
802 5 while (!(Usb_tx_complete()));
803 5 Usb_clear_TXCMPL();
804 5 break;
805 5 }
806 4 default:
807 4 {
808 5 Usb_clear_RXSETUP();
809 5 Usb_set_STALLRQ();
810 5 while (!(Usb_STALL_sent()));
811 5 Usb_clear_STALLRQ();
812 5 break;
813 5 }
814 4 }
815 3 }
816 2 }
817 1 }
818
819
820
821
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1145 ----
CONSTANT SIZE = 120 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 2
IDATA SIZE = 7 ----
BIT SIZE = 1 ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -