⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fw.lst

📁 本人自己编的usb数据采集固件,对四路信号进行采集
💻 LST
📖 第 1 页 / 共 5 页
字号:
C51 COMPILER V6.10  FW                             07/07/2005 13:31:07 PAGE 1   


C51 COMPILER V6.10, COMPILATION OF MODULE FW
OBJECT MODULE PLACED IN .\FW.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE .\FW.C OPTIMIZE(6,SPEED) DEBUG OBJE
                    -CTEXTEND CODE SYMBOLS PAGEWIDTH(80) 

stmt level    source

   1          //----------------------------------------------------------------
             --------------
   2          //   File:      fw.c
   3          //   Contents:   Firmware frameworks task dispatcher and device re
             -quest parser
   4          //            source.
   5          //
   6          // indent 3.  NO TABS!
   7          //
   8          // $Revision: 17 $
   9          // $Date: 11/15/01 5:45p $
  10          //
  11          //   Copyright (c) 1997 AnchorChips, Inc. All rights reserved
  12          //----------------------------------------------------------------
             --------------
  13          #include "fx2.h"
  14          #include "fx2regs.h"
  15          
  16          //----------------------------------------------------------------
             --------------
  17          // Constants
  18          //----------------------------------------------------------------
             --------------
  19          #define DELAY_COUNT   0x9248*8L  // Delay for 8 sec at 24Mhz, 4 se
             -c at 48
  20          #define _IFREQ  48000            // IFCLK constant for Synchroniza
             -tion Delay
  21          #define _CFREQ  48000            // CLKOUT constant for Synchroniz
             -ation Delay
  22          
  23          //----------------------------------------------------------------
             --------------
  24          // Random Macros
  25          //----------------------------------------------------------------
             --------------
  26          #define   min(a,b) (((a)<(b))?(a):(b))
  27          #define   max(a,b) (((a)>(b))?(a):(b))
  28          
  29            // Registers which require a synchronization delay, see section 
             -15.14
  30            // FIFORESET        FIFOPINPOLAR
  31            // INPKTEND         OUTPKTEND
  32            // EPxBCH:L         REVCTL
  33            // GPIFTCB3         GPIFTCB2
  34            // GPIFTCB1         GPIFTCB0
  35            // EPxFIFOPFH:L     EPxAUTOINLENH:L
  36            // EPxFIFOCFG       EPxGPIFFLGSEL
  37            // PINFLAGSxx       EPxFIFOIRQ
  38            // EPxFIFOIE        GPIFIRQ
  39            // GPIFIE           GPIFADRH:L
  40            // UDMACRCH:L       EPxGPIFTRIG
  41            // GPIFTRIG
  42            
  43            // Note: The pre-REVE EPxGPIFTCH/L register are affected, as wel
C51 COMPILER V6.10  FW                             07/07/2005 13:31:07 PAGE 2   

             -l...
  44            //      ...these have been replaced by GPIFTC[B3:B0] registers
  45            
  46          #include "fx2sdly.h"             // Define _IFREQ and _CFREQ above
             - this #include
  47          
  48          //----------------------------------------------------------------
             --------------
  49          // Global Variables
  50          //----------------------------------------------------------------
             --------------
  51          volatile BOOL   GotSUD;
  52          BOOL      Rwuen;
  53          BOOL      Selfpwr;
  54          volatile BOOL   Sleep;                  // Sleep mode enable flag
  55          
  56          WORD   pDeviceDscr;   // Pointer to Device Descriptor; Descriptors
             - may be moved
  57          WORD   pDeviceQualDscr;
  58          WORD   pHighSpeedConfigDscr;
  59          WORD   pFullSpeedConfigDscr;   
  60          WORD   pConfigDscr;
  61          WORD   pOtherConfigDscr;   
  62          WORD   pStringDscr;   
  63          
  64          //----------------------------------------------------------------
             --------------
  65          // Prototypes
  66          //----------------------------------------------------------------
             --------------
  67          void SetupCommand(void);
  68          void TD_Init(void);
  69          void TD_Poll(void);
  70          BOOL TD_Suspend(void);
  71          BOOL TD_Resume(void);
  72          
  73          BOOL DR_GetDescriptor(void);
  74          BOOL DR_SetConfiguration(void);
  75          BOOL DR_GetConfiguration(void);
  76          BOOL DR_SetInterface(void);
  77          BOOL DR_GetInterface(void);
  78          BOOL DR_GetStatus(void);
  79          BOOL DR_ClearFeature(void);
  80          BOOL DR_SetFeature(void);
  81          BOOL DR_VendorCmnd(void);
  82          
  83          // this table is used by the epcs macro 
  84          const char code  EPCS_Offset_Lookup_Table[] =
  85          {
  86             0,    // EP1OUT
  87             1,    // EP1IN
  88             2,    // EP2OUT
  89             2,    // EP2IN
  90             3,    // EP4OUT
  91             3,    // EP4IN
  92             4,    // EP6OUT
  93             4,    // EP6IN
  94             5,    // EP8OUT
  95             5,    // EP8IN
  96          };
  97          
  98          // macro for generating the address of an endpoint's control and s
C51 COMPILER V6.10  FW                             07/07/2005 13:31:07 PAGE 3   

             -tatus register (EPnCS)
  99          #define epcs(EP) (EPCS_Offset_Lookup_Table[(EP & 0x7E) | (EP > 128
             -)] + 0xE6A1)
 100          
 101          //----------------------------------------------------------------
             --------------
 102          // Code
 103          //----------------------------------------------------------------
             --------------
 104          
 105          // Task dispatcher
 106          void main(void)
 107          {
 108   1         DWORD   i;
 109   1         WORD   offset;
 110   1         DWORD   DevDescrLen;
 111   1         DWORD   j=0;
 112   1         WORD   IntDescrAddr;
 113   1         WORD   ExtDescrAddr;
 114   1      
 115   1         // Initialize Global States
 116   1         Sleep = FALSE;               // Disable sleep mode
 117   1         Rwuen = FALSE;               // Disable remote wakeup
 118   1         Selfpwr = FALSE;            // Disable self powered
 119   1         GotSUD = FALSE;               // Clear "Got setup data" flag
 120   1      
 121   1         // Initialize user device
 122   1         TD_Init();
 123   1      
 124   1         // The following section of code is used to relocate the descri
             -ptor table. 
 125   1         // Since the SUDPTRH and SUDPTRL are assigned the address of th
             -e descriptor 
 126   1         // table, the descriptor table must be located in on-part memor
             -y.
 127   1         // The 4K demo tools locate all code sections in external memor
             -y.
 128   1         // The descriptor table is relocated by the frameworks ONLY if 
             -it is found 
 129   1         // to be located in external memory.
 130   1         pDeviceDscr = (WORD)&DeviceDscr;
 131   1         pDeviceQualDscr = (WORD)&DeviceQualDscr;
 132   1         pHighSpeedConfigDscr = (WORD)&HighSpeedConfigDscr;
 133   1         pFullSpeedConfigDscr = (WORD)&FullSpeedConfigDscr;
 134   1         pStringDscr = (WORD)&StringDscr;
 135   1      
 136   1         if (EZUSB_HIGHSPEED())
 137   1         {
 138   2            pConfigDscr = pHighSpeedConfigDscr;
 139   2            pOtherConfigDscr = pFullSpeedConfigDscr;
 140   2         }
 141   1         else
 142   1         {
 143   2            pConfigDscr = pFullSpeedConfigDscr;
 144   2            pOtherConfigDscr = pHighSpeedConfigDscr;
 145   2         }
 146   1      
 147   1         if ((WORD)&DeviceDscr & 0xe000)
 148   1         {
 149   2            IntDescrAddr = INTERNAL_DSCR_ADDR;
 150   2            ExtDescrAddr = (WORD)&DeviceDscr;
 151   2            DevDescrLen = (WORD)&UserDscr - (WORD)&DeviceDscr + 2;
C51 COMPILER V6.10  FW                             07/07/2005 13:31:07 PAGE 4   

 152   2            for (i = 0; i < DevDescrLen; i++)
 153   2               *((BYTE xdata *)IntDescrAddr+i) = 0xCD;
 154   2            for (i = 0; i < DevDescrLen; i++)
 155   2               *((BYTE xdata *)IntDescrAddr+i) = *((BYTE xdata *)ExtDesc
             -rAddr+i);
 156   2            pDeviceDscr = IntDescrAddr;
 157   2            offset = (WORD)&DeviceDscr - INTERNAL_DSCR_ADDR;
 158   2            pDeviceQualDscr -= offset;
 159   2            pConfigDscr -= offset;
 160   2            pOtherConfigDscr -= offset;
 161   2            pHighSpeedConfigDscr -= offset;
 162   2            pFullSpeedConfigDscr -= offset;
 163   2            pStringDscr -= offset;
 164   2         }
 165   1      
 166   1         EZUSB_IRQ_ENABLE();            // Enable USB interrupt (INT2)
 167   1         EZUSB_ENABLE_RSMIRQ();            // Wake-up interrupt
 168   1      
 169   1         INTSETUP |= (bmAV2EN | bmAV4EN);     // Enable INT 2 & 4 autove
             -ctoring
 170   1      
 171   1         USBIE |= bmSUDAV | bmSUTOK | bmSUSP | bmURES | bmHSGRANT;   // 
             -Enable selected interrupts
 172   1         EA = 1;                  // Enable 8051 interrupts
 173   1      
 174   1      #ifndef NO_RENUM
 175   1         // Renumerate if necessary.  Do this by checking the renum bit.
             -  If it
 176   1         // is already set, there is no need to renumerate.  The renum b
             -it will
 177   1         // already be set if this firmware was loaded from an eeprom.
 178   1         if(!(USBCS & bmRENUM))
 179   1         {
 180   2             EZUSB_Discon(TRUE);   // renumerate
 181   2         }
 182   1      #endif
 183   1      
 184   1         // unconditionally re-connect.  If we loaded from eeprom we are
 185   1         // disconnected and need to connect.  If we just renumerated th
             -is
 186   1         // is not necessary but doesn't hurt anything
 187   1         USBCS &=~bmDISCON;
 188   1      
 189   1         CKCON = (CKCON&(~bmSTRETCH)) | FW_STRETCH_VALUE; // Set stretch
             - to 0 (after renumeration)
 190   1      
 191   1         // clear the Sleep flag.
 192   1         Sleep = FALSE;
 193   1      
 194   1         // Task Dispatcher
 195   1         while(TRUE)               // Main Loop
 196   1         {
 197   2            if(GotSUD)            // Wait for SUDAV
 198   2            {
 199   3               SetupCommand();          // Implement setup command
 200   3                 GotSUD = FALSE;            // Clear SUDAV flag
 201   3            }
 202   2      
 203   2            // Poll User Device
 204   2            // NOTE: Idle mode stops the processor clock.  There are onl
             -y two
 205   2            // ways out of idle mode, the WAKEUP pin, and detection of t
C51 COMPILER V6.10  FW                             07/07/2005 13:31:07 PAGE 5   

             -he USB
 206   2            // resume state on the USB bus.  The timers will stop and th
             -e
 207   2            // processor will not wake up on any other interrupts.
 208   2            if (Sleep)
 209   2                {
 210   3                if(TD_Suspend())
 211   3                    { 
 212   4                    Sleep = FALSE;            // Clear the "go to sleep"
             - flag.  Do it here to prevent any race condition between wakeup and the next sle
             -ep.
 213   4                    do
 214   4                        {
 215   5                          EZUSB_Susp();         // Place processor in id
             -le mode.
 216   5                        }
 217   4                      while(!Rwuen && EZUSB_EXTWAKEUP());
 218   4                      // Must continue to go back into suspend if the ho
             -st has disabled remote wakeup
 219   4                      // *and* the wakeup was caused by the external wak
             -eup pin.
 220   4                      
 221   4                   // 8051 activity will resume here due to USB bus or W

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -