📄 combi.lst
字号:
847 USB_DEVICE_A = 0x80; // enable endpoint zero response at address 0
848 EP_A0_MODE = USB_MODE_STALL_IN_OUT;
849 //and make the leap to the main loop
850 #asm(jmp usbmain)
*** ERROR C315 IN LINE 850 OF ..\..\..\Usb-Mouse\src\combi.c: unknown #directive 'asm'
851 }
852
853
854 /*
855 **
856 ** FUNCTION: WAKEUP_ISR
857 **
858 ** PURPOSE: ISR for wakeup interrupt.
859 **
860 ** PARAMETERS: none
861 **
862 ** DESCRIPTION: The wakeup ISR increments a global counter which is used to "tune" the
863 ** frequency of the occurrence of the ISR itself (See routine TuneWakeup).
864 **
865 */
866
867 void WAKEUP_ISR(void)
868 {
869 bWakeupCount++;
870 }
871
872
873 /*
874 **
875 ** FUNCTION: GPIO_ISR
876 **
877 ** PURPOSE: ISR for wakeup interrupt. does nothing except returns
878 **
879 ** PARAMETERS: none
880 **
881 ** DESCRIPTION:
882 **
883 */
884
885 void GPIO_ISR(void)
886 {
887
888 }
889
890
891 /*
892 **
893 ** FUNCTION: USB_A_EP0_ISR
C51 COMPILER V7.01 COMBI 04/14/2008 22:57:43 PAGE 16
894 **
895 ** PURPOSE: Endpoint 0 Interrupt Service Routine.
896 **
897 ** PARAMETERS: none
898 **
899 ** DESCRIPTION:
900 ** this routine is entered upon receiving an endpoint 0 interrupt.
901 ** EP0 interrupts occur during the Setup, data , and status phases of a
902 ** setup transaction. This ISR dispatches the proper routine to handle
903 ** one of these phases. The interrupt will remain active until the
904 ** phase in question is completely handled.
905 */
906
907 void USB_A_EP0_ISR(void)
908 {
909 PUSHA(); //save A and X,they'll get wasted
910 PUSHX();
911 if (EP_A0_MODE & (1 << ACKNOWLEDGE)) //if this packet was acknowledged,
912 {
913 if (EP_A0_MODE & SETUP_RECEIVED_MASK) //if a setup was received,
914 {
915 DeviceStatus.bAddress &= ~0x80; //clear the address flag
916 HandleSetup(); //and handle it
917 }
918 else if (EP_A0_MODE & IN_RECEIVED_MASK) //if an in was received,
919 {
920 HandleIn(); //handle it
921 if (DeviceStatus.bAddress & 0x80) //if the address flag was set during the setup
922 //phase preceding this IN,
923 USB_DEVICE_A = DeviceStatus.bAddress; //enable the new address
924 DeviceStatus.bAddress &= ~0x80; //and clear the new address flag
925 }
926 }
927 POPX();
928 POPA();
929 return;
930 }
931
932
933 /*
934 **
935 ** FUNCTION: USB_A_EP1_ISR
936 **
937 ** PURPOSE: Endpoint 1 ISR.
938 **
939 ** PARAMETERS: none
940 **
941 ** DESCRIPTION:
942 ** this routine is entered upon receiving an endpoint 1 interrupt.
943 ** If the ACK bit is sent, indicating that a valid mouse packet was just
944 ** transmitted to the host, the SIE is set to NAK ins, and the
945 ** datatoggle bit is flipped for the next transaction.
946 */
947
948 void USB_A_EP1_ISR(void)
949 {
950 PUSHA();
951 if (EP_A1_MODE & ( 1 << ACKNOWLEDGE))
952 {
953 EP_A1_MODE = USB_MODE_NAK_IN;
954 EP_A1_COUNTER ^= DATATOGGLE;
955 }
C51 COMPILER V7.01 COMBI 04/14/2008 22:57:43 PAGE 17
956 POPA();
957 return;
958 }
959
960
961 /*
962 **
963 ** FUNCTION: TuneWakeup
964 **
965 ** PURPOSE: to tune the wakeup ISR
966 **
967 ** PARAMETERS: none
968 **
969 ** DESCRIPTION: The wakeup interrupt period is variable by a factor of 5 due to operating and process
970 ** conditions. The period has a prescaler which adjusts the period by a factor of two.
971 ** This routine is called at regular intervals to tune the wakeup ISR to occur at the
972 ** rate at which this routine is called, to within a factor of 2. In other words, if
973 ** this routine is called every 256 msec, it will tune the wakeup ISR to occur at a rate
974 ** between 128-256 msec.
975 **
976 **
977
978 */
979
980 void TuneWakeup(void)
981 {
982 char temp;
983 temp = CLOCK_CONFIGURATION & TWAKEUP_MASK; //get the current wakeup prescale value
984 if ((bWakeupCount > 2) && (temp != TWAKEUP_MAX)) //if more than two wakeup ISRs occurred since
985 //the last time this routine was called, and we
986 //are not at the maximum prescale value already,
987 //increment the prescaler to slow down the ISR interval
988 temp += TWAKEUP_2;
989 if ((!bWakeupCount) && (temp)) //if no wakeup ISRs occurred, and we are not
990 //at the minimum prescale value,
991 //decrement the prescaler to speed up the ISR interval
992 temp -= TWAKEUP_2;
993 CLOCK_CONFIGURATION = PRECISION_USB_CLOCKING | temp;
994 bWakeupCount = 0;
995 }
996
997
998 /*
999 **
1000 ** FUNCTION: usbmain
1001 **
1002 ** PURPOSE: USB main processing loop
1003 **
1004 ** PARAMETERS: none
1005 **
1006 ** DESCRIPTION:
1007 ** main spins in an infinite loop waiting for an event that needs servicing.
1008 ** Main is entered from either the power-on reset or the usb bus reset. Both
1009 ** of these reset routines insures that all USB variables have been initialized
1010 ** prior to calling usbmain.
1011 */
1012
1013 void usbmain(void)
1014
1015 {
1016 EI();
1017 while (1)
C51 COMPILER V7.01 COMBI 04/14/2008 22:57:43 PAGE 18
1018 {
1019 //clear watchdog timer
1020 RESET_COP();
1021 ProcessOptics(); //empty the optics queue
1022 if (MsecStatus.b1msFlags & ONE_MSEC_FLAG) //if 1 msec has elapsed
1023 {
1024 if (!MsecStatus.b1msCounter) //every 256 msec tune the wakeup ISR
1025 TuneWakeup();
1026 if (DeviceStatus.bConfiguration &&
1027 (!(MsecStatus.b1msCounter & 3))) //if we're configured, and if 4 msec has elapsed....
1028 MouseTask(); //go handle mouse stuff
1029 if (BusInactive()) //if the bus has gone inactive
1030 Suspend(); //suspend us
1031 MsecStatus.b1msFlags &= ~ONE_MSEC_FLAG;
1032 }
1033 }
1034 }
1035
1036
1037 /*
1038 **
1039 ** FUNCTION: Reinitialize
1040 **
1041 ** PURPOSE: Reinitializes system RAM and USB engine
1042 **
1043 ** PARAMETERS: none
1044 **
1045 ** DESCRIPTION:
1046 ** This routine initializes all USB variables to their
1047 ** default states, and resets USB engine controls to their initial values. RAM
1048 ** has been cleared prior to entry.
1049 */
1050
1051 void UsbReInitialize(void)
1052 {
1053 DI(); //disable ints
1054 RESET_COP(); //reset watchdog
1055 CLOCK_CONFIGURATION = PRECISION_USB_CLOCKING | TWAKEUP_64 ; //set up precision clocking, /64 wakeup pr
-escaler
1056 //this will set the initial wakeup time anywhere
1057 //from 64 - 5*64 msec.
1058 OpticsQueue.headP = bOpticsArray; //initialize queue pointers
1059 OpticsQueue.tailP = bOpticsArray;
1060 DeviceStatus.bProtocol = REPORT_PROTOCOL; //start in report protocol
1061 USB_STATUS = VREG_ENABLE_MASK | NOT_FORCING;
1062 PROCESSOR_STATUS &= ~(WATCHDOG_RESET_MASK //clear source of reset
1063 | POWER_ON_RESET_M
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -