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

📄 main.lst

📁 使用Jungo Windriver開發的USB driver 及其firmware,類型為mass storage,應用於FX2(Cypress CY68013A)上.
💻 LST
📖 第 1 页 / 共 4 页
字号:
C51 COMPILER V7.06   MAIN                                                                  02/13/2008 21:37:10 PAGE 1   


C51 COMPILER V7.06, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN main.OBJ
COMPILER INVOKED BY: C:\Keil\c51\bin\c51.exe main.c DB OE CODE MODDP2 DF(FX2LP) DF(FX2LP_NEW)

stmt level    source

   1          /******************************************************************************
   2          *   File:     main.c                                                         
   3          *                                                                             
   4          *   Contents:  Implementation of the firmware's main entry point for
   5          *              l123456 devices, based on the Cypress FX2LP (CY7C68013A)
   6          *              development board.
   7          *
   8          *   Code was generated by DriverWizard v8.02 - http://www.jungo.com
   9          *   Copyright (c) 2008 Jungo Ltd.  http://www.jungo.com
  10          *******************************************************************************/
  11          
  12          #include "wdf_cypress.h"
  13          #include "wdf_cypress_lib.h"
  14          #include "periph.h"
  15          
  16          //-----------------------------------------------------------------------------
  17          // Constants
  18          //-----------------------------------------------------------------------------
  19          #define DELAY_COUNT   0x9248*8L  // Delay for 8 sec at 24Mhz, 4 sec at 48
  20          #define _IFREQ  48000            // IFCLK constant for Synchronization Delay
  21          #define _CFREQ  48000            // CLKOUT constant for Synchronization Delay
  22          
  23          #if defined(FX2LP)
  24              #define INTERNAL_ADDR_HIGH 0x3FFF
  25          #else
                  #define INTERNAL_ADDR_HIGH 0x1FFF 
              #endif
  28          
  29          //-----------------------------------------------------------------------------
  30          // Global Variables
  31          //-----------------------------------------------------------------------------
  32          volatile BOOL   GotSUD;
  33          BOOL      Rwuen;
  34          BOOL      Selfpwr;
  35          volatile BOOL   Sleep;                  // Sleep mode enable flag
  36          
  37          WORD   pDeviceDscr;   // Pointer to Device Descriptor; Descriptors may be moved
  38          WORD   pDeviceQualDscr;
  39          WORD   pHighSpeedConfigDscr;
  40          WORD   pFullSpeedConfigDscr;   
  41          WORD   pConfigDscr;
  42          WORD   pOtherConfigDscr;   
  43          WORD   pStringDscr;   
  44          
  45          void SetupCommand(void);
  46          
  47          // this table is used by the epcs macro 
  48          const char code  EPCS_Offset_Lookup_Table[] =
  49          {
  50              0,    // EP1OUT
  51              1,    // EP1IN
  52              2,    // EP2OUT
  53              2,    // EP2IN
  54              3,    // EP4OUT
  55              3,    // EP4IN
C51 COMPILER V7.06   MAIN                                                                  02/13/2008 21:37:10 PAGE 2   

  56              4,    // EP6OUT
  57              4,    // EP6IN
  58              5,    // EP8OUT
  59              5,    // EP8IN
  60          };
  61          
  62          // macro for generating the address of an endpoint's control and status register (EPnCS)
  63          #define epcs(EP) (EPCS_Offset_Lookup_Table[(EP & 0x7E) | (EP > 128)] + 0xE6A1)
  64          
  65          //-----------------------------------------------------------------------------
  66          // Code
  67          //-----------------------------------------------------------------------------
  68          
  69          // Task dispatcher
  70          void main(void)
  71          {
  72   1          DWORD i;
  73   1          WORD offset;
  74   1          DWORD DevDescrLen;
  75   1          DWORD j=0;
  76   1          WORD IntDescrAddr;
  77   1          WORD ExtDescrAddr;
  78   1          DWORD nSetupRequests = 0;
  79   1      
  80   1          // Initialize Global States
  81   1          Sleep = FALSE;               // Disable sleep mode
  82   1          GotSUD = FALSE;               // Clear "Got setup data" flag
  83   1      
  84   1          // Initialize I2C interface
  85   1          WDF_I2CInit();
  86   1      
  87   1          // Initialize user device
  88   1          WDF_Init();
  89   1      
  90   1          // The following section of code is used to relocate the descriptor table. 
  91   1          // The frameworks uses SUDPTRH and SUDPTRL to automate the SETUP requests
  92   1          // for descriptors.  These registers only work with memory locations
  93   1          // in the EZ-USB internal RAM.  Therefore, if the descriptors are located
  94   1          // in external RAM, they must be copied to in internal RAM.  
  95   1          // The descriptor table is relocated by the frameworks ONLY if it is found 
  96   1          // to be located in external memory.
  97   1          pDeviceDscr = (WORD)&DeviceDscr;
  98   1          pDeviceQualDscr = (WORD)&DeviceQualDscr;
  99   1          pHighSpeedConfigDscr = (WORD)&HighSpeedConfigDscr;
 100   1          pFullSpeedConfigDscr = (WORD)&FullSpeedConfigDscr;
 101   1          pStringDscr = (WORD)&StringDscr;
 102   1      
 103   1          // Is the descriptor table in external RAM (> 16Kbytes)?  If yes,
 104   1          // then relocate.
 105   1          // Note that this code only checks if the descriptors START in 
 106   1          // external RAM.  It will not work if the descriptor table spans
 107   1          // internal and external RAM.
 108   1          DevDescrLen = (WORD)&UserDscr - (WORD)&DeviceDscr + 2;
 109   1          if ((WORD)(&DeviceDscr + DevDescrLen) & ~INTERNAL_ADDR_HIGH)
 110   1          {
 111   2              // first, relocate the descriptors
 112   2              IntDescrAddr = INTERNAL_DSCR_ADDR;
 113   2              ExtDescrAddr = (WORD)&DeviceDscr;
 114   2              for (i = 0; i < DevDescrLen; i++)
 115   2                  *((BYTE xdata *)IntDescrAddr+i) = *((BYTE xdata *)ExtDescrAddr+i);
 116   2      
 117   2              // update all of the descriptor pointers
C51 COMPILER V7.06   MAIN                                                                  02/13/2008 21:37:10 PAGE 3   

 118   2              pDeviceDscr = IntDescrAddr;
 119   2              offset = (WORD)&DeviceDscr - INTERNAL_DSCR_ADDR;
 120   2              pDeviceQualDscr -= offset;
 121   2              pConfigDscr -= offset;
 122   2              pOtherConfigDscr -= offset;
 123   2              pHighSpeedConfigDscr -= offset;
 124   2              pFullSpeedConfigDscr -= offset;
 125   2              pStringDscr -= offset;
 126   2          }
 127   1      
 128   1          EZUSB_IRQ_ENABLE();            // Enable USB interrupt (INT2)
 129   1          EZUSB_ENABLE_RSMIRQ();            // Wake-up interrupt
 130   1      
 131   1          INTSETUP |= (bmAV2EN | bmAV4EN);     // Enable INT 2 & 4 autovectoring
 132   1      
 133   1          USBIE |= bmSUDAV | bmSUTOK | bmSUSP | bmURES | bmHSGRANT;   // Enable selected interrupts
 134   1          EA = 1;                  // Enable 8051 interrupts
 135   1      
 136   1      #ifndef NO_RENUM
 137   1          EZUSB_Discon(TRUE);   // renumerate
 138   1      #endif
 139   1      
 140   1          // unconditionally re-connect.  If we loaded from eeprom we are
 141   1          // disconnected and need to connect.  If we just renumerated this
 142   1          // is not necessary but doesn't hurt anything
 143   1          USBCS &=~bmDISCON;
 144   1      
 145   1          CKCON = (CKCON&(~bmSTRETCH)) | FW_STRETCH_VALUE; // Set stretch
 146   1      
 147   1          // Task Dispatcher
 148   1          while(TRUE)               // Main Loop
 149   1          {
 150   2              // Poll User Device
 151   2              WDF_Poll();
 152   2      
 153   2              // Check for pending SETUP
 154   2              if(GotSUD)
 155   2              {
 156   3                  SetupCommand();          // Implement setup command
 157   3                  GotSUD = FALSE;          // Clear SETUP flag
 158   3              }
 159   2      
 160   2              // check for and handle suspend.
 161   2              // NOTE: Idle mode stops the processor clock.  There are only two
 162   2              // ways out of idle mode, the WAKEUP pin, and detection of the USB
 163   2              // resume state on the USB bus.  The timers will stop and the
 164   2              // processor will not wake up on any other interrupts.
 165   2              if (Sleep)
 166   2              {
 167   3                  if(WDF_Suspend())
 168   3                  { 
 169   4                       Sleep = FALSE;     // Clear the "go to sleep" flag.  Do it here to
 170   4                                          // prevent any race condition between wakeup and the next sleep.
 171   4                       do
 172   4                       {
 173   5                           EZUSB_Susp();         // Place processor in idle mode.
 174   5                       }
 175   4                       while(!Rwuen && EZUSB_EXTWAKEUP());
 176   4                              // above.  Must continue to go back into suspend if the host has disabled remote wakeup
 177   4                       // and the wakeup was caused by the external wakeup pin.
 178   4      
 179   4                       // 8051 activity will resume here due to USB bus or Wakeup# pin activity.
C51 COMPILER V7.06   MAIN                                                                  02/13/2008 21:37:10 PAGE 4   

 180   4                       EZUSB_Resume();   // If source is the Wakeup# pin, signal the host to Resume.
 181   4                       WDF_Resume();
 182   4                  }
 183   3              }
 184   2          }
 185   1      }
 186          
 187          // Device request parser
 188          void SetupCommand(void)
 189          {
 190   1          void   *dscr_ptr;
 191   1      
 192   1          switch(SETUPDAT[1])
 193   1          {
 194   2          case SC_GET_DESCRIPTOR:                  // *** Get Descriptor
 195   2              if(WDF_GetDescriptor())
 196   2                  switch(SETUPDAT[3])         
 197   2                  {
 198   3                  case GD_DEVICE:            // Device
 199   3                      SUDPTRH = MSB(pDeviceDscr);
 200   3                      SUDPTRL = LSB(pDeviceDscr);
 201   3                      break;
 202   3                  case GD_DEVICE_QUALIFIER:            // Device Qualifier
 203   3                      SUDPTRH = MSB(pDeviceQualDscr);
 204   3                      SUDPTRL = LSB(pDeviceQualDscr);
 205   3                      break;
 206   3                  case GD_CONFIGURATION:         // Configuration
 207   3                      SUDPTRH = MSB(pConfigDscr);
 208   3                      SUDPTRL = LSB(pConfigDscr);
 209   3                      break;
 210   3                  case GD_OTHER_SPEED_CONFIGURATION:  // Other Speed Configuration
 211   3                      SUDPTRH = MSB(pOtherConfigDscr);
 212   3                      SUDPTRL = LSB(pOtherConfigDscr);
 213   3                      break;
 214   3                  case GD_STRING:            // String
 215   3                      if(dscr_ptr = (void *)EZUSB_GetStringDscr(SETUPDAT[2]))
 216   3                      {
 217   4                          SUDPTRH = MSB(dscr_ptr);
 218   4                          SUDPTRL = LSB(dscr_ptr);
 219   4                      }
 220   3                      else 
 221   3                          EZUSB_STALL_EP0();   // Stall End Point 0
 222   3                      break;
 223   3                  default:            // Invalid request
 224   3                      EZUSB_STALL_EP0();      // Stall End Point 0
 225   3                  }
 226   2              break;
 227   2          case SC_GET_INTERFACE:                  // *** Get Interface
 228   2              WDF_GetInterface(SETUPDAT[3]);
 229   2              break;
 230   2          case SC_SET_INTERFACE:                  // *** Set Interface
 231   2              WDF_SetInterface(SETUPDAT[3], SETUPDAT[2]);
 232   2              break;
 233   2          case SC_SET_CONFIGURATION:               // *** Set Configuration
 234   2              WDF_SetConfiguration(SETUPDAT[2]);
 235   2              break;
 236   2          case SC_GET_CONFIGURATION:               // *** Get Configuration
 237   2              WDF_GetConfiguration();
 238   2              break;
 239   2          case SC_GET_STATUS:                  // *** Get Status
 240   2              if(WDF_GetStatus())
 241   2              {
C51 COMPILER V7.06   MAIN                                                                  02/13/2008 21:37:10 PAGE 5   

 242   3                  switch(SETUPDAT[0])
 243   3                  {
 244   4                  case GS_DEVICE:            // Device
 245   4                      EP0BUF[0] = ((BYTE)Rwuen << 1) | (BYTE)Selfpwr;
 246   4                      EP0BUF[1] = 0;
 247   4                      EP0BCH = 0;
 248   4                      EP0BCL = 2;
 249   4                      break;
 250   4                  case GS_INTERFACE:         // Interface
 251   4                      EP0BUF[0] = 0;
 252   4                      EP0BUF[1] = 0;
 253   4                      EP0BCH = 0;
 254   4                      EP0BCL = 2;
 255   4                      break;
 256   4                  case GS_ENDPOINT:         // End Point
 257   4                      EP0BUF[0] = *(BYTE xdata *) epcs(SETUPDAT[4]) & bmEPSTALL;
 258   4                      EP0BUF[1] = 0;
 259   4                      EP0BCH = 0;
 260   4                      EP0BCL = 2;
 261   4                      break;
 262   4                  default:            // Invalid Command
 263   4                      EZUSB_STALL_EP0();      // Stall End Point 0
 264   4                  }
 265   3              }
 266   2              break;
 267   2          case SC_CLEAR_FEATURE:                  // *** Clear Feature
 268   2              if(WDF_ClearFeature())
 269   2              {
 270   3                  switch(SETUPDAT[0])
 271   3                  {
 272   4                  case FT_DEVICE:            // Device
 273   4                      if(SETUPDAT[2] == 1)

⌨️ 快捷键说明

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