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

📄 fw.lst

📁 cypress 68013a-56pvxc usb2.0
💻 LST
📖 第 1 页 / 共 4 页
字号:
C51 COMPILER V7.10   FW                                                                    05/28/2007 19:12:28 PAGE 1   


C51 COMPILER V7.10, COMPILATION OF MODULE FW
OBJECT MODULE PLACED IN .\_Oput\fw.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE source\fw.c ROM(COMPACT) OPTIMIZE(9,SPEED) BROWSE ORDER DEFINE(GPIF=0,FLASH
                    -=0,DEVICE_TYPE_IS_SCSI=1,DEVICE_TYPE_IS_IDE=1,VBUS_DETECT=1) DEBUG OBJECTEXTEND CODE PRINT(.\_List\fw.lst) OBJECT(.\_Opu
                    -t\fw.obj)

line 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) 2001 Cypress Semiconductor
   9          //
  10          // $Archive: /USB/atapifx2/software/fw.c $
  11          // $Date: 1/15/02 10:12a $
  12          // $Revision: 45 $
  13          //-----------------------------------------------------------------------------
  14          #include "fx2.h"
  15          #include "fx2regs.h"
  16          #include "gpif.h"
  17          #include "atapi.h"
  18          
  19          //-----------------------------------------------------------------------------
  20          // Constants
  21          //-----------------------------------------------------------------------------
  22          #define DELAY_COUNT   0x9248*8L      // Delay for 8 sec at 24Mhz, 4 sec at 48
  23          // USB constants
  24          // Class specific setup commands
  25          #define SC_BOMS_RESET           (0x21)      // Hard/soft depends on wValue field 0 = hard
  26          
  27          //-----------------------------------------------------------------------------
  28          // Global Variables
  29          //-----------------------------------------------------------------------------
  30          BOOL      Rwuen;
  31          BOOL      Selfpwr;
  32          volatile BOOL   Sleep;                  // Sleep mode enable flag
  33          BYTE   AlternateSetting;   // Alternate settings
  34          BYTE   Configuration;      // Current configuration
  35          
  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          BYTE intrfcSubClass;
  46          
  47          //-----------------------------------------------------------------------------
  48          // Prototypes
  49          //-----------------------------------------------------------------------------
  50          void SetupCommand(void);
  51          void TD_Init(void);
  52          void TD_Poll(void);
  53          //BOOL TD_Suspend(void);
C51 COMPILER V7.10   FW                                                                    05/28/2007 19:12:28 PAGE 2   

  54          //BOOL TD_Resume(void);
  55          void DisconAndWaitForVbus();
  56          
  57          WORD wPacketSize;
  58          
  59          
  60          //-----------------------------------------------------------------------------
  61          // Code
  62          //-----------------------------------------------------------------------------
  63          
  64          // Task dispatcher
  65          
  66          void main(void)
  67          {
  68   1         BYTE     i;
  69   1         // Init globals
  70   1         MaxPIO = 0;                // reset MaxPIO value
  71   1         Sleep = FALSE;             // Reset suspend flag
  72   1         Rwuen = FALSE;             // Disable remote wakeup
  73   1         Selfpwr = FALSE;           // Disable self powered
  74   1      
  75   1         // if we are hung up in a GPIF transfer, abort it.  How could this happen?  If
  76   1         // we ended up here after a USB Reset or a MSC Reset, it is possible that the
  77   1         // GPIF is hung waiting for a transfer that will never complete.
  78   1         abortGPIF(); // TPM: Unconditionally abort
  79   1      
  80   1         TD_Init();
  81   1      
  82   1         // The following section of code is used to relocate the descriptor table from
  83   1         // ROM to RAM.  It is done here because we are done with the halfKBuffer at this point.
  84   1         // Although it looks wierd, the only way to get the proper values for the offsets
  85   1         // is to tell the compiler that we want the address of the variable, not the variable itself.
  86   1         mymemmovexx(halfKBuffer, (char xdata *) &DeviceDscr, (WORD)&DscrEndOffset);
  87   1      //   pDeviceDscr = (WORD)(halfKBuffer + (WORD)&DeviceDscrOffset);
  88   1      //   pDeviceQualDscr = (WORD)(halfKBuffer + (WORD)&DeviceQualDscrOffset);
  89   1      //   pHighSpeedConfigDscr = (WORD)(halfKBuffer + (WORD)&HighSpeedConfigDscrOffset);
  90   1      //   pFullSpeedConfigDscr = (WORD)(halfKBuffer + (WORD)&FullSpeedConfigDscrOffset);
  91   1      //   pStringDscr = (WORD)(halfKBuffer + (WORD)&StringDscrOffset);
  92   1      
  93   1         halfKBuffer[(WORD) &IntrfcSubClassHighSpeedOffset] = 
  94   1            halfKBuffer[(WORD) &IntrfcSubClassFullSpeedOffset] = intrfcSubClass;
  95   1      
  96   1      
  97   1         for (i = 0; i < ATAPI_INQUIRY_SERIAL_LEN *2; i++)
  98   1            halfKBuffer[i+(WORD)&SerialNumberOffset] = localSerialNumber[i];
  99   1        
 100   1         EZUSB_IRQ_ENABLE();            // Enable USB interrupt (INT2)
 101   1         EZUSB_ENABLE_RSMIRQ();            // Wake-up interrupt
 102   1      
 103   1         INTSETUP |= (bmAV2EN);     // Enable INT 2 autovectoring
 104   1      
 105   1         USBIE |= bmSUDAV | bmSUSP | bmURES | bmHSGRANT;   // Enable selected interrupts
 106   1         EA = 1;                  // Enable 8051 interrupts
 107   1      
 108   1         // Renumerate if necessary.  Do this by checking the renum bit.  If it
 109   1         // is already set, there is no need to renumerate.  The renum bit will
 110   1         // already be set if this firmware was loaded from an eeprom or if we
 111   1         // have already been through this code once and we are here again
 112   1         // because of a USB Reset.
 113   1         if(!(USBCS & bmRENUM))
 114   1         {
 115   2             EZUSB_Discon(TRUE);   // renumerate
C51 COMPILER V7.10   FW                                                                    05/28/2007 19:12:28 PAGE 3   

 116   2         }
 117   1      
 118   1      #ifdef VBUS_DETECT
 119   1         // check for the presence of VBus and re-connect.  If we loaded from eeprom
 120   1         // we are disconnected and need to connect.  If we just renumerated this
 121   1         // is not necessary but doesn't hurt anything.  VBus on the Rev *B 4611 boards
 122   1         // is tied to port A.6.
 123   1         if (IOA & bmBIT6)
 124   1         {
 125   2            USBCS &=~bmDISCON;
 126   2         }
 127   1         else
 128   1         {
 129   2            DisconAndWaitForVbus();
 130   2         }
 131   1      #else
                 // unconditionally re-connect.  If we loaded from eeprom we are
                 // disconnected and need to connect.  If we just renumerated this
                 // is not necessary but doesn't hurt anything
                 USBCS &=~bmDISCON;
              #endif
 137   1      
 138   1         CKCON = (CKCON&(~bmSTRETCH)) | FW_STRETCH_VALUE; // Set stretch to 0 (after renumeration)
 139   1      
 140   1         // complete the handshake phase of any pending SETUP transfer.
 141   1         // The only time this should happen is after a MSC Reset.  We want
 142   1         // to go through all of the EP init code before handshaking the status
 143   1         // phase of the MSC Reset.
 144   1         EP0CS |= bmHSNAK;
 145   1      
 146   1         // Task Dispatcher
 147   1         while(TRUE)                     // Main Loop
 148   1         {
 149   2      #ifdef VBUS_DETECT
 150   2            // we need to constantly monitor VBus (tied to Port A.6) and disconnect if
 151   2            // it isn't there.  This is to avoid driving D+ (a spec violation) when the
 152   2            // host isn't there.
 153   2            if (!(IOA & bmBIT6))
 154   2               DisconAndWaitForVbus();
 155   2      #endif
 156   2      
 157   2            TD_Poll();
 158   2         }
 159   1      }
 160          
 161          #ifdef VBUS_DETECT
 162          // This function monitors VBus from the host and stays disconnected until VBus is
 163          // is present.  VBus is tied to Port A.6 on the new FX2 ATAPI tailgate boards.
 164          // (4611 Rev *B)
 165          void DisconAndWaitForVbus()
 166          {
 167   1         USBCS |= bmDISCON;
 168   1         while (!(IOA & bmBIT6));
 169   1         USBCS &= ~bmDISCON;
 170   1      }
 171          #endif
 172             
 173          
 174          // Device request parser
 175          void SetupCommand(void)
 176          {
 177   1         void   *dscr_ptr;
C51 COMPILER V7.10   FW                                                                    05/28/2007 19:12:28 PAGE 4   

 178   1      
 179   1         switch(SETUPDAT[1])
 180   1         {
 181   2            case SC_GET_DESCRIPTOR:                      // *** Get Descriptor
 182   2               switch(SETUPDAT[3])         
 183   2                  {
 184   3                     case GD_DEVICE:                     // Device
 185   3                        SUDPTRH = MSB(pDeviceDscr);
 186   3                        SUDPTRL = LSB(pDeviceDscr);
 187   3                        break;
 188   3                     case GD_DEVICE_QUALIFIER:            // Device Qualifier
 189   3                        SUDPTRH = MSB(pDeviceQualDscr);
 190   3                        SUDPTRL = LSB(pDeviceQualDscr);
 191   3                        break;
 192   3                     case GD_CONFIGURATION:              // Configuration
 193   3                        SUDPTRH = MSB(pConfigDscr);
 194   3                        SUDPTRL = LSB(pConfigDscr);
 195   3                        break;
 196   3                     case GD_OTHER_SPEED_CONFIGURATION:  // Other Speed Configuration
 197   3                        // fx2bug - need to support multi other configs
 198   3                        SUDPTRH = MSB(pOtherConfigDscr);
 199   3                        SUDPTRL = LSB(pOtherConfigDscr);
 200   3                        break;
 201   3                     case GD_STRING:            // String
 202   3                        if(dscr_ptr = (void *)EZUSB_GetStringDscr(SETUPDAT[2]))
 203   3                        {
 204   4                           SUDPTRH = MSB(dscr_ptr);
 205   4                           SUDPTRL = LSB(dscr_ptr);
 206   4                        }
 207   3                        else 
 208   3                           EZUSB_STALL_EP0();   // Stall End Point 0
 209   3                        break;
 210   3                     default:                   // Invalid request
 211   3                        EZUSB_STALL_EP0();      // Stall End Point 0
 212   3                  }  // switch
 213   2               break;
 214   2            case SC_GET_INTERFACE:                  // *** Get Interface
 215   2               EP0BUF[0] = AlternateSetting;
 216   2               EP0BCH = 0;
 217   2               EP0BCL = 1;
 218   2               break;
 219   2            case SC_SET_INTERFACE:                  // *** Set Interface
 220   2               AlternateSetting = SETUPDAT[2];
 221   2               break;
 222   2            case SC_SET_CONFIGURATION:               // *** Set Configuration
 223   2            // BUGBUG -- Add delay for the CATC
 224   2               Configuration = SETUPDAT[2];
 225   2               break;
 226   2            case SC_GET_CONFIGURATION:               // *** Get Configuration
 227   2               EP0BUF[0] = Configuration;
 228   2               EP0BCH = 0;
 229   2               EP0BCL = 1;
 230   2               break;
 231   2            case SC_GET_STATUS:                 // *** Get Status
 232   2                  switch(SETUPDAT[0])
 233   2                  {
 234   3                     case GS_DEVICE:            // Device
 235   3                        EP0BUF[0] = ((BYTE)Rwuen << 1) | (BYTE)Selfpwr;
 236   3                        EP0BUF[1] = 0;
 237   3                        EP0BCH = 0;
 238   3                        EP0BCL = 2;
 239   3                        break;
C51 COMPILER V7.10   FW                                                                    05/28/2007 19:12:28 PAGE 5   

 240   3                     case GS_INTERFACE:         // Interface
 241   3                        EP0BUF[0] = 0;
 242   3                        EP0BUF[1] = 0;
 243   3                        EP0BCH = 0;
 244   3                        EP0BCL = 2;
 245   3                        break;
 246   3                     case GS_ENDPOINT:         // End Point
 247   3                        if (SETUPDAT[4] == 0x2)
 248   3                        {
 249   4                           EP0BUF[0] = (EP2CS & bmEPSTALL);
 250   4                        }
 251   3                        else if (SETUPDAT[4] == 0x88)
 252   3                        {
 253   4                           EP0BUF[0] = (EP8CS & bmEPSTALL);
 254   4                        }
 255   3                        else
 256   3                        {
 257   4                           EZUSB_STALL_EP0();   // Stall End Point 0
 258   4                           break;
 259   4                        }
 260   3      
 261   3                        EP0BUF[1] = 0;
 262   3                        EP0BCH = 0;
 263   3                        EP0BCL = 2;
 264   3                        break;
 265   3                     default:                   // Invalid Command
 266   3                        EZUSB_STALL_EP0();      // Stall End Point 0
 267   3                  }

⌨️ 快捷键说明

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