📄 main.lst
字号:
562 {
563 1 // Here you can have SRC routine long as you want ..
564 1
565 1
566 1 if (rcvReport.u.cmd) // If this is a new command coming in ...
567 1 {
568 2 if (rcvReport.u.cmd == CMD_STATUS)
569 2 {
570 3 // For CMD_GET_STATUS, don't overwrite current cmd we're working on
571 3 returnStatus = TRUE;
572 3 }
573 2 else
574 2 {
575 3 // Copy into 'current command' global variable
576 3 memcpy(currentCmd.u.buffer, rcvReport.u.buffer, sizeof(rcvReport));
577 3 memset((uchar*)&status, 0, sizeof(status));
578 3 // g_debug1 = currentCmd.u.cmd;
579 3 }
580 2
581 2 // Some commands are processed at this point
582 2 switch (rcvReport.u.cmd)
583 2 {
584 3 case CMD_RESET:
585 3 WDKEY=0; // watchdog will trigger reset in a second
586 3 currentCmd.u.cmd = 0;
587 3 break;
588 3
589 3 case CMD_SET_PAGE:
590 3 UPSD_xreg.PAGE = rcvReport.u.setRegs.page;
591 3 currentCmd.u.cmd = 0;
592 3 break;
593 3
594 3 case CMD_SET_VM:
595 3 UPSD_xreg.VM = rcvReport.u.setRegs.vm;
596 3 currentCmd.u.cmd = 0;
597 3 break;
598 3
599 3 case CMD_SET_REGS:
600 3 UPSD_xreg.PAGE = rcvReport.u.setRegs.page;
601 3 UPSD_xreg.VM = rcvReport.u.setRegs.vm;
602 3 currentCmd.u.cmd = 0;
603 3 break;
604 3
605 3 default:
606 3 // Prepare first segment of any response to go back to host
607 3 PrepareTransmitSegment(0);
608 3 break;
609 3 }
610 2 }
611 1 }
612
613
C51 COMPILER V7.06 MAIN 10/15/2004 20:55:29 PAGE 11
614
615
616
617
618
619
620
621
622
623
624 static BOOL HandleReport()
625 /******************************************************************************
626 Function : static BOOL HandleReport()
627 Parameters : none
628 Description: Handles HID Get_Report and Set_Report SETUP packets.
629 Returns TRUE if the SETUP packet is a Get_Report or Set_Report
630 request; else returns FALSE.
631 ******************************************************************************/
632 {
633 1 // If it is a HID Set_Report request...
634 1 if ((setupPacket.bmRequestType == CLASS_INTERFACE_TO_DEVICE)
635 1 && (setupPacket.bRequest == HID_SET_REPORT))
636 1 {
637 2 rcvIndex = 0; // Prepare to receive report
638 2 return TRUE;
639 2 }
640 1 // Else if it is a HID Get_Report request ...
641 1 else if ((setupPacket.bmRequestType == CLASS_INTERFACE_TO_HOST)
642 1 && (setupPacket.bRequest == HID_GET_REPORT))
643 1 {
644 2 // Transmit first segment of response (should be already prepared)
645 2 UCON0 &= ~uTSEQ0;
646 2 TransmitDataEP0(txReport.u.buffer, EP0_SIZE);
647 2
648 2 txIndex = EP0_SIZE; // Prepare next segment while first one is going out
649 2 PrepareTransmitSegment(txIndex);
650 2 return TRUE;
651 2 }
652 1
653 1 return FALSE;
654 1 }
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
C51 COMPILER V7.06 MAIN 10/15/2004 20:55:29 PAGE 12
676
677
678
679
680 bdata char USB_ISR_FLAGS = 0;
681 sbit GoOnResume = USB_ISR_FLAGS ^ 0;
682 sbit GoOnSuspend = USB_ISR_FLAGS ^ 7;
683
684
685
686 static void OnUSBSuspend()
687 /******************************************************************************
688 Function : static void OnUSBSuspend()
689 Parameters : none
690 Description: service routine for USB Suspend event
691 ******************************************************************************/
692 {
693 1
694 1 data char bie,biea;
695 1
696 1 printfLCD("\n* SUSPEND MODE *\n");
697 1 printfLCD("\rCPU in Idle mode");
698 1
699 1
700 1 bie = IE;
701 1 biea = IEA;
702 1
703 1 IEA = 1; // disable all INTs except USB
704 1 IE = 128; // disable all INTs except USB
705 1
706 1 SUSPND = 1; //Enter suspend mode for uPSD
707 1 GoOnSuspend = 0; //clear global Suspend flag
708 1 // entering SUSPEND or setting SUSPNDF causes to top the clocks to the USB
709 1 // and causes the USB module to enter Suspend Mode.
710 1 UIEN |= uRESUMIE; // enable resume INT
711 1 PCON |= 1; //Enter Idle mode
712 1
713 1 // here the uPSD sleeps and waits for the next INT
714 1 SUSPND = 0; //clear the flag
715 1
716 1 IE = bie;
717 1 IEA = biea;
718 1
719 1 UIEN &= ~uRESUMIE; // disable resume INT
720 1 RESUMF = 0; //clear the flag
721 1 printfLCD("\r \n"); //clear display
722 1 printfLCD("\r \r"); //clear display
723 1 printfLCD("\r*USB DEMO V.2.1*\n"); //dislay the string
724 1 }
725
726
727 void main() using 0
728 /******************************************************************************
729 Function : void main()
730 Parameters : none
731 Description: Main routine, start of your program
732 ******************************************************************************/
733 {
734 1 data char c;
735 1
736 1 // Initialize globals
737 1 // The following two lines can be deleted if no USB Disconnect feature is implemented
C51 COMPILER V7.06 MAIN 10/15/2004 20:55:29 PAGE 13
738 1 #ifdef DisconnectOnDemand
UPSD_xreg.DIRECTION_B |= 0x03; // set PSD-PB0,1 DDR high
UPSD_xreg.DATAOUT_B = 0x03; // disable LED2, low level active /01/02
#endif
742 1
743 1 memset((uchar*)&status, 0, sizeof(status));
744 1 memset((uchar*)¤tCmd, 0, sizeof(currentCmd));
745 1 counter = 0;
746 1
747 1 // We are not currently transmitting or receiving feature/input reports
748 1 rcvIndex = CMD_SIZE;
749 1 txIndex = CMD_SIZE;
750 1
751 1 // Disable watchdog
752 1 WDKEY=WD_OFF;
753 1
754 1 initXREG(); // init extended regs in xdata
755 1 initLCD();
756 1 UsbInitialize(); // Initialize USB,
757 1
758 1
759 1
760 1 /* ONLY USB must have the highest priority to assure good respose
761 1 and proper processing of all requests.
762 1 */
763 1 IP = 0; // USB must have the highest priority !!!
764 1 IPA = 1; // USB must have the highest priority !!!
765 1 EA = 0;
766 1
767 1 IEA |= 0x80; // Enable DDC Interrupt - Priority is user TBD
768 1
769 1 EA = 1; // Enable INTs
770 1
771 1 printfLCD("\r*USB DEMO V.2.1*\n"); //dislay the string
772 1
773 1
774 1 #ifdef DisconnectOnDemand
ReConnectUSB(); // Enable when DisconnectOnDemand feature is implemented
#endif
777 1
778 1 LCD_delay_ms(1000); //wait
779 1
780 1
781 1 while (1)
782 1 {
783 2 // Indicate which flash we are running out of: main (M) or boot (B)
784 2 c = ((UPSD_xreg.VM == 0x92) ? 'B' : 'M');
785 2 printfLCD("\r%B %x %x%c %W\r", g_debugTimer2_INT_CNT, USB_ISR_FLAGS, currentCmd.u.cmd,c, g_debugUSB_IN
-T_CNT);
786 2
787 2 // Enable the following lines if you plan to use the DisconnectOnDemand feature
788 2 // and if you have the HW modifications on your DK3200 kit (see appnote).
789 2
790 2 #ifdef DisconnectOnDemand
// DisconnectOnDemand feature
if ((UPSD_xreg.DATAIN_B & 0x04)==0) // check Swith ONE
{
ReConnectUSB(); // Disconnect USB when pressed
}
#endif
797 2
798 2 }
C51 COMPILER V7.06 MAIN 10/15/2004 20:55:29 PAGE 14
799 1 }
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821 static void UsbIsr() interrupt 6 using 3
822 /******************************************************************************
823 Function : static void UsbIsr()
824 Parameters : none
825 Description: USB interrupt service routine.
826 Note: Do not modify this routine !!!
827 ******************************************************************************/
828 {
829 1
830 1
831 1
832 1
833 1
834 1
835 1
836 1
837 1 data uchar cb;
838 1 data uchar i;
839 1
840 1
841 1
842 1
843 1
844 1
845 1
846 1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -