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

📄 fw.lst

📁 EZ-USB FX2的一个单字读和单字写的程序
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V6.10  FW                                                                     06/22/2006 16:02:23 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 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          //   Copyright (c) 1997 AnchorChips, Inc. All rights reserved
   9          //-----------------------------------------------------------------------------
  10          #include "fx2.h"
  11          #include "fx2regs.h"
  12          
  13          //-----------------------------------------------------------------------------
  14          // Constants
  15          //-----------------------------------------------------------------------------
  16          #define DELAY_COUNT   0x9248*8L  // Delay for 8 sec at 24Mhz, 4 sec at 48
  17          #define _IFREQ  48000            // IFCLK constant for Synchronization Delay
  18          #define _CFREQ  48000            // CLKOUT constant for Synchronization Delay
  19          
  20          //-----------------------------------------------------------------------------
  21          // Random Macros
  22          //-----------------------------------------------------------------------------
  23          #define   min(a,b) (((a)<(b))?(a):(b))
  24          #define   max(a,b) (((a)>(b))?(a):(b))
  25          
  26            // Register which require a synchronization delay, see section 15.14
  27            // FIFORESET        FIFOPINPOLAR
  28            // INPKTEND         EPxBCH:L
  29            // EPxFIFOPFH:L     EPxAUTOINLENH:L
  30            // EPxFIFOCFG       EPxGPIFFLGSEL
  31            // PINFLAGSxx       EPxFIFOIRQ
  32            // EPxFIFOIE        GPIFIRQ
  33            // GPIFIE           GPIFADRH:L
  34            // UDMACRCH:L       EPxGPIFTRIG
  35            // GPIFTRIG
  36            //
  37            // Remember that read-modify-write instructions like:
  38            //	GPIFIE |= 0x02;
  39            // ...must be avoided for these registers...
  40            //	Instead we recommend:
  41            //	tmp = GPIFIE;
  42            //  SYNCDELAY;
  43            //  GPIFIE = tmp|0x02;
  44            
  45          #include "fx2sdly.h"             // Define _IFREQ and _CFREQ above this #include
  46          
  47          //-----------------------------------------------------------------------------
  48          // Global Variables
  49          //-----------------------------------------------------------------------------
  50          volatile BOOL   GotSUD;
  51          BOOL      Rwuen;
  52          BOOL      Selfpwr;
  53          volatile BOOL   Sleep;                  // Sleep mode enable flag
  54          
  55          WORD   pDeviceDscr;   // Pointer to Device Descriptor; Descriptors may be moved
C51 COMPILER V6.10  FW                                                                     06/22/2006 16:02:23 PAGE 2   

  56          WORD   pDeviceQualDscr;
  57          WORD   pHighSpeedConfigDscr;
  58          WORD   pFullSpeedConfigDscr;   
  59          WORD   pConfigDscr;
  60          WORD   pOtherConfigDscr;   
  61          WORD   pStringDscr;   
  62          
  63          //-----------------------------------------------------------------------------
  64          // Prototypes
  65          //-----------------------------------------------------------------------------
  66          void SetupCommand(void);
  67          void TD_Init(void);
  68          void TD_Poll(void);
  69          BOOL TD_Suspend(void);
  70          BOOL TD_Resume(void);
  71          
  72          BOOL DR_GetDescriptor(void);
  73          BOOL DR_SetConfiguration(void);
  74          BOOL DR_GetConfiguration(void);
  75          BOOL DR_SetInterface(void);
  76          BOOL DR_GetInterface(void);
  77          BOOL DR_GetStatus(void);
  78          BOOL DR_ClearFeature(void);
  79          BOOL DR_SetFeature(void);
  80          BOOL DR_VendorCmnd(void);
  81          
  82          //-----------------------------------------------------------------------------
  83          // Code
  84          //-----------------------------------------------------------------------------
  85          
  86          // Task dispatcher
  87          void main(void)
  88          {
  89   1         DWORD   i;
  90   1         WORD   offset;
  91   1         DWORD   DevDescrLen;
  92   1         DWORD   j=0;
  93   1         WORD   IntDescrAddr;
  94   1         WORD   ExtDescrAddr;
  95   1      
  96   1         // Initialize Global States
  97   1         Sleep = FALSE;               // Disable sleep mode
  98   1         Rwuen = FALSE;               // Disable remote wakeup
  99   1         Selfpwr = FALSE;            // Disable self powered
 100   1         GotSUD = FALSE;               // Clear "Got setup data" flag
 101   1      
 102   1         // Initialize user device
 103   1         TD_Init();
 104   1      
 105   1         // The following section of code is used to relocate the descriptor table. 
 106   1         // Since the SUDPTRH and SUDPTRL are assigned the address of the descriptor 
 107   1         // table, the descriptor table must be located in on-part memory.
 108   1         // The 4K demo tools locate all code sections in external memory.
 109   1         // The descriptor table is relocated by the frameworks ONLY if it is found 
 110   1         // to be located in external memory.
 111   1         pDeviceDscr = (WORD)&DeviceDscr;
 112   1         pDeviceQualDscr = (WORD)&DeviceQualDscr;
 113   1         pHighSpeedConfigDscr = (WORD)&HighSpeedConfigDscr;
 114   1         pFullSpeedConfigDscr = (WORD)&FullSpeedConfigDscr;
 115   1         pStringDscr = (WORD)&StringDscr;
 116   1      
 117   1         if (EZUSB_HIGHSPEED())
C51 COMPILER V6.10  FW                                                                     06/22/2006 16:02:23 PAGE 3   

 118   1         {
 119   2            pConfigDscr = pHighSpeedConfigDscr;
 120   2            pOtherConfigDscr = pFullSpeedConfigDscr;
 121   2         }
 122   1         else
 123   1         {
 124   2            pConfigDscr = pFullSpeedConfigDscr;
 125   2            pOtherConfigDscr = pHighSpeedConfigDscr;
 126   2         }
 127   1      
 128   1         if ((WORD)&DeviceDscr & 0xe000)
 129   1         {
 130   2            IntDescrAddr = INTERNAL_DSCR_ADDR;
 131   2            ExtDescrAddr = (WORD)&DeviceDscr;
 132   2            DevDescrLen = (WORD)&UserDscr - (WORD)&DeviceDscr + 2;
 133   2            for (i = 0; i < DevDescrLen; i++)
 134   2               *((BYTE xdata *)IntDescrAddr+i) = 0xCD;
 135   2            for (i = 0; i < DevDescrLen; i++)
 136   2               *((BYTE xdata *)IntDescrAddr+i) = *((BYTE xdata *)ExtDescrAddr+i);
 137   2            pDeviceDscr = IntDescrAddr;
 138   2            offset = (WORD)&DeviceDscr - INTERNAL_DSCR_ADDR;
 139   2            pDeviceQualDscr -= offset;
 140   2            pConfigDscr -= offset;
 141   2            pOtherConfigDscr -= offset;
 142   2            pHighSpeedConfigDscr -= offset;
 143   2            pFullSpeedConfigDscr -= offset;
 144   2            pStringDscr -= offset;
 145   2         }
 146   1      
 147   1         EZUSB_IRQ_ENABLE();            // Enable USB interrupt (INT2)
 148   1         EZUSB_ENABLE_RSMIRQ();            // Wake-up interrupt
 149   1      
 150   1         INTSETUP |= (bmAV2EN | bmAV4EN);     // Enable INT 2 & 4 autovectoring
 151   1      
 152   1         USBIE |= bmSUDAV | bmSUTOK | bmSUSP | bmURES | bmHSGRANT;   // Enable selected interrupts
 153   1         EA = 1;                  // Enable 8051 interrupts
 154   1      
 155   1         #ifndef NO_RENUM
 156   1         // Note: at full speed, high speed hosts may take 5 sec to detect device
 157   1         EZUSB_Discon(TRUE); // Renumerate
 158   1         #endif
 159   1      
 160   1         CKCON = (CKCON&(~bmSTRETCH)) | FW_STRETCH_VALUE; // Set stretch to 0 (after renumeration)
 161   1      
 162   1         // clear the Sleep flag.
 163   1         Sleep = FALSE;
 164   1      
 165   1         // Task Dispatcher
 166   1         while(TRUE)               // Main Loop
 167   1         {
 168   2            if(GotSUD)            // Wait for SUDAV
 169   2            {
 170   3               SetupCommand();          // Implement setup command
 171   3                 GotSUD = FALSE;            // Clear SUDAV flag
 172   3            }

⌨️ 快捷键说明

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