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

📄 fw.lst

📁 呵呵
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.07   FW                                                                    12/25/2006 14:02:13 PAGE 1   


C51 COMPILER V7.07, COMPILATION OF MODULE FW
OBJECT MODULE PLACED IN fw.OBJ
COMPILER INVOKED BY: D:\Keil\C51\BIN\C51.EXE fw.c OPTIMIZE(4,SPEED) BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          //-----------------------------------------------------------------------------
   2          //   File:      fw.c
   3          //   Contents:   Firmware frameworks task dispatcher and device request parser
   4          //            source.
   5          //
   6          // indent 3.  NO TABS!
   7          //
   8          // $Revision: 18 $
   9          // $Date: 12/04/01 5:33p $
  10          //
  11          //   Copyright (c) 1997 AnchorChips, Inc. All rights reserved
  12          //-----------------------------------------------------------------------------
  13          #include "fx2.h"
  14          #include "fx2regs.h"
  15          //#include "io.h"
  16          //#include "led.h"
  17          //#include "serial.h"
  18             // sbit IOD_IN   =  0xB0+0;
  19            //   sbit IOD_OUT  =  0xB0+6;
  20           //sbit IOD_OUT=0xB8+3;
  21          //  sbit AD_Cfg_Pin=0xB0+6;
  22          
  23          //-----------------------------------------------------------------------------
  24          // Constants
  25          //-----------------------------------------------------------------------------
  26          #define DELAY_COUNT   0x9248*8L  // Delay for 8 sec at 24Mhz, 4 sec at 48
  27          #define _IFREQ  48000            // IFCLK constant for Synchronization Delay
  28          #define _CFREQ  48000            // CLKOUT constant for Synchronization Delay
  29          
  30          //-----------------------------------------------------------------------------
  31          // Random Macros
  32          //-----------------------------------------------------------------------------
  33          #define   min(a,b) (((a)<(b))?(a):(b))
  34          #define   max(a,b) (((a)>(b))?(a):(b))
  35          
  36            // Registers which require a synchronization delay, see section 15.14
  37            // FIFORESET        FIFOPINPOLAR
  38            // INPKTEND         OUTPKTEND
  39            // EPxBCH:L         REVCTL
  40            // GPIFTCB3         GPIFTCB2
  41            // GPIFTCB1         GPIFTCB0
  42            // EPxFIFOPFH:L     EPxAUTOINLENH:L
  43            // EPxFIFOCFG       EPxGPIFFLGSEL
  44            // PINFLAGSxx       EPxFIFOIRQ
  45            // EPxFIFOIE        GPIFIRQ
  46            // GPIFIE           GPIFADRH:L
  47            // UDMACRCH:L       EPxGPIFTRIG
  48            // GPIFTRIG
  49            
  50            // Note: The pre-REVE EPxGPIFTCH/L register are affected, as well...
  51            //      ...these have been replaced by GPIFTC[B3:B0] registers
  52            
  53          #include "fx2sdly.h"             // Define _IFREQ and _CFREQ above this #include
  54          
  55          //-----------------------------------------------------------------------------
C51 COMPILER V7.07   FW                                                                    12/25/2006 14:02:13 PAGE 2   

  56          // Global Variables
  57          //-----------------------------------------------------------------------------
  58          volatile BOOL   GotSUD;
  59          BOOL      Rwuen;
  60          BOOL      Selfpwr;
  61          volatile BOOL   Sleep;                  // Sleep mode enable flag
  62          
  63          WORD   pDeviceDscr;   // Pointer to Device Descriptor; Descriptors may be moved
  64          WORD   pDeviceQualDscr;
  65          WORD   pHighSpeedConfigDscr;
  66          WORD   pFullSpeedConfigDscr;   
  67          WORD   pConfigDscr;
  68          WORD   pOtherConfigDscr;   
  69          WORD   pStringDscr; 
  70          
  71                  //定义用到的全局变量
  72          //BYTE N=1,M=1,W1=1,W2=1;
  73          BYTE AD_State;    // 1 send command ;    2   recive AD data
  74          BYTE AD_Cfg_State;  //0-7 send 0-7 commnad bits
  75          BYTE AD_Rec_State;  //0-11 recive 12 bits AD data
  76          BYTE AD_CLK_Rising,AD_CLK_Falling;
  77          BYTE AD_Cfg_Byte;    //AD config byte
  78          BYTE AD_Rec_Data;    // recived data form AD data out pin
  79          BYTE AD_Channel;     //Ad channel form 0 to 3
  80          WORD tmp_data;       //
  81          WORD ChannelNum;
  82          //BYTE i,a,b,c;
  83          BYTE CON[4];
  84          WORD AD_Result;
  85          BYTE data_enable;//enable usb flag
  86          
  87          BYTE Channel_Cha;
  88            
  89          //-----------------------------------------------------------------------------
  90          // Prototypes
  91          //-----------------------------------------------------------------------------
  92          void SetupCommand(void);
  93          void TD_Init(void);
  94          void TD_Poll(void);
  95          BOOL TD_Suspend(void);
  96          BOOL TD_Resume(void);
  97          
  98          BOOL DR_GetDescriptor(void);
  99          BOOL DR_SetConfiguration(void);
 100          BOOL DR_GetConfiguration(void);
 101          BOOL DR_SetInterface(void);
 102          BOOL DR_GetInterface(void);
 103          BOOL DR_GetStatus(void);
 104          BOOL DR_ClearFeature(void);
 105          BOOL DR_SetFeature(void);
 106          BOOL DR_VendorCmnd(void);
 107          
 108          // this table is used by the epcs macro 
 109          const char code  EPCS_Offset_Lookup_Table[] =
 110          {
 111             0,    // EP1OUT
 112             1,    // EP1IN
 113             2,    // EP2OUT
 114             2,    // EP2IN
 115             3,    // EP4OUT
 116             3,    // EP4IN
 117             4,    // EP6OUT
C51 COMPILER V7.07   FW                                                                    12/25/2006 14:02:13 PAGE 3   

 118             4,    // EP6IN
 119             5,    // EP8OUT
 120             5,    // EP8IN
 121          };
 122          
 123          // macro for generating the address of an endpoint's control and status register (EPnCS)
 124          #define epcs(EP) (EPCS_Offset_Lookup_Table[(EP & 0x7E) | (EP > 128)] + 0xE6A1)
 125          
 126          //-----------------------------------------------------------------------------
 127          // Code
 128          //-----------------------------------------------------------------------------
 129          
 130          // Task dispatcher
 131          void main(void)
 132          {
 133   1         DWORD   i;
 134   1         WORD   offset;
 135   1         DWORD   DevDescrLen;
 136   1         DWORD   j=0;
 137   1         WORD   IntDescrAddr;
 138   1         WORD   ExtDescrAddr;
 139   1         //BYTE temp_data=0;
 140   1        //BYTE BL,BH;              convert 12bits to two 8 bits
 141   1        //WORD sineWave=0x1f2f;
 142   1        //BL=sineWave&0x00ff;
 143   1        //BH=(sineWave&0x0f00>>8);
 144   1              
 145   1         // Initialize Global States
 146   1         Sleep = FALSE;               // Disable sleep mode
 147   1         Rwuen = FALSE;               // Disable remote wakeup
 148   1         Selfpwr = FALSE;            // Disable self powered
 149   1         GotSUD = FALSE;               // Clear "Got setup data" flag
 150   1      
 151   1         // Initialize user device
 152   1         TD_Init();
 153   1      
 154   1         // The following section of code is used to relocate the descriptor table. 
 155   1         // Since the SUDPTRH and SUDPTRL are assigned the address of the descriptor 
 156   1         // table, the descriptor table must be located in on-part memory.
 157   1         // The 4K demo tools locate all code sections in external memory.
 158   1         // The descriptor table is relocated by the frameworks ONLY if it is found 
 159   1         // to be located in external memory.
 160   1         pDeviceDscr = (WORD)&DeviceDscr;
 161   1         pDeviceQualDscr = (WORD)&DeviceQualDscr;
 162   1         pHighSpeedConfigDscr = (WORD)&HighSpeedConfigDscr;
 163   1         pFullSpeedConfigDscr = (WORD)&FullSpeedConfigDscr;
 164   1         pStringDscr = (WORD)&StringDscr;
 165   1      
 166   1         if ((WORD)&DeviceDscr & 0xe000)
 167   1         {
 168   2            IntDescrAddr = INTERNAL_DSCR_ADDR;
 169   2            ExtDescrAddr = (WORD)&DeviceDscr;
 170   2            DevDescrLen = (WORD)&UserDscr - (WORD)&DeviceDscr + 2;
 171   2            for (i = 0; i < DevDescrLen; i++)
 172   2               *((BYTE xdata *)IntDescrAddr+i) = 0xCD;
 173   2            for (i = 0; i < DevDescrLen; i++)
 174   2               *((BYTE xdata *)IntDescrAddr+i) = *((BYTE xdata *)ExtDescrAddr+i);
 175   2            pDeviceDscr = IntDescrAddr;
 176   2            offset = (WORD)&DeviceDscr - INTERNAL_DSCR_ADDR;
 177   2            pDeviceQualDscr -= offset;
 178   2            pConfigDscr -= offset;
 179   2            pOtherConfigDscr -= offset;
C51 COMPILER V7.07   FW                                                                    12/25/2006 14:02:13 PAGE 4   

 180   2            pHighSpeedConfigDscr -= offset;
 181   2            pFullSpeedConfigDscr -= offset;
 182   2            pStringDscr -= offset;
 183   2         }
 184   1      
 185   1         EZUSB_IRQ_ENABLE();            // Enable USB interrupt (INT2)
 186   1         EZUSB_ENABLE_RSMIRQ();            // Wake-up interrupt
 187   1      
 188   1         INTSETUP |= (bmAV2EN | bmAV4EN);     // Enable INT 2 & 4 autovectoring
 189   1      
 190   1         USBIE |= bmSUDAV | bmSUTOK | bmSUSP | bmURES | bmHSGRANT;   // Enable selected interrupts
 191   1              
 192   1         //SerialPort_Init();
 193   1         EA = 1;                  // Enable 8051 interrupts
 194   1      
 195   1      #ifndef NO_RENUM
 196   1         // Renumerate if necessary.  Do this by checking the renum bit.  If it
 197   1         // is already set, there is no need to renumerate.  The renum bit will
 198   1         // already be set if this firmware was loaded from an eeprom.
 199   1         if(!(USBCS & bmRENUM))
 200   1         {
 201   2             EZUSB_Discon(TRUE);   // renumerate
 202   2         }
 203   1      #endif
 204   1      
 205   1         // unconditionally re-connect.  If we loaded from eeprom we are
 206   1         // disconnected and need to connect.  If we just renumerated this
 207   1         // is not necessary but doesn't hurt anything
 208   1         USBCS &=~bmDISCON;
 209   1      
 210   1         CKCON = (CKCON&(~bmSTRETCH)) | FW_STRETCH_VALUE; // Set stretch to 0 (after renumeration)
 211   1      
 212   1         // clear the Sleep flag.
 213   1         Sleep = FALSE;
 214   1      
 215   1         // Task Dispatcher
 216   1         while(TRUE)               // Main Loop
 217   1         {
 218   2            if(GotSUD)            // Wait for SUDAV
 219   2            {
 220   3               SetupCommand();          // Implement setup command
 221   3                 GotSUD = FALSE;            // Clear SUDAV flag
 222   3            }
 223   2      
 224   2            // Poll User Device
 225   2            // NOTE: Idle mode stops the processor clock.  There are only two
 226   2            // ways out of idle mode, the WAKEUP pin, and detection of the USB
 227   2            // resume state on the USB bus.  The timers will stop and the
 228   2            // processor will not wake up on any other interrupts.
 229   2            if (Sleep)

⌨️ 快捷键说明

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