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

📄 fw.lst

📁 基于MSP430的CYpress USB芯片68013的开发
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.50   FW                                                                    03/02/2008 15:20:03 PAGE 1   


C51 COMPILER V7.50, COMPILATION OF MODULE FW
OBJECT MODULE PLACED IN fw.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE fw.c DEBUG OBJECTEXTEND

line level    source

   1          //-----------------------------------------------------------------------------
   2          //   File:      fw.c
   3          //   Contents:  Firmware frameworks task dispatcher and device request parser
   4          //
   5          // $Archive: /USB/Examples/FX2LP/bulkext/fw.c $
   6          // $Date: 3/23/05 2:53p $
   7          // $Revision: 8 $
   8          //
   9          //
  10          //-----------------------------------------------------------------------------
  11          // Copyright 2003, Cypress Semiconductor Corporation
  12          //-----------------------------------------------------------------------------
  13          #include "fx2.h"
  14          #include "fx2regs.h"
  15          #include "syncdly.h"            // SYNCDELAY macro
  16          
  17          //-----------------------------------------------------------------------------
  18          // Constants
  19          //-----------------------------------------------------------------------------
  20          #define DELAY_COUNT   0x9248*8L  // Delay for 8 sec at 24Mhz, 4 sec at 48
  21          #define _IFREQ  48000            // IFCLK constant for Synchronization Delay
  22          #define _CFREQ  48000            // CLKOUT constant for Synchronization Delay
  23          
  24          //-----------------------------------------------------------------------------
  25          // Random Macros
  26          //-----------------------------------------------------------------------------
  27          #define   min(a,b) (((a)<(b))?(a):(b))
  28          #define   max(a,b) (((a)>(b))?(a):(b))
  29          
  30          //-----------------------------------------------------------------------------
  31          // Global Variables
  32          //-----------------------------------------------------------------------------
  33          volatile BOOL   GotSUD;
  34          BOOL      Rwuen;
  35          BOOL      Selfpwr;
  36          volatile BOOL   Sleep;                  // Sleep mode enable flag
  37          
  38          WORD   pDeviceDscr;   // Pointer to Device Descriptor; Descriptors may be moved
  39          WORD   pDeviceQualDscr;
  40          WORD   pHighSpeedConfigDscr;
  41          WORD   pFullSpeedConfigDscr;   
  42          WORD   pConfigDscr;
  43          WORD   pOtherConfigDscr;   
  44          WORD   pStringDscr;   
  45          
  46          //-----------------------------------------------------------------------------
  47          // Prototypes
  48          //-----------------------------------------------------------------------------
  49          void SetupCommand(void);
  50          void TD_Init(void);
  51          void TD_Poll(void);
  52          BOOL TD_Suspend(void);
  53          BOOL TD_Resume(void);
  54          
  55          BOOL DR_GetDescriptor(void);
C51 COMPILER V7.50   FW                                                                    03/02/2008 15:20:03 PAGE 2   

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

 118   1         if ((WORD)&DeviceDscr & 0xC000)
 119   1         {
 120   2            // first, relocate the descriptors
 121   2            IntDescrAddr = INTERNAL_DSCR_ADDR;
 122   2            ExtDescrAddr = (WORD)&DeviceDscr;
 123   2            DevDescrLen = (WORD)&UserDscr - (WORD)&DeviceDscr + 2;
 124   2            for (i = 0; i < DevDescrLen; i++)
 125   2               *((BYTE xdata *)IntDescrAddr+i) = *((BYTE xdata *)ExtDescrAddr+i);
 126   2      
 127   2            // update all of the descriptor pointers
 128   2            pDeviceDscr = IntDescrAddr;
 129   2            offset = (WORD)&DeviceDscr - INTERNAL_DSCR_ADDR;
 130   2            pDeviceQualDscr -= offset;
 131   2            pConfigDscr -= offset;
 132   2            pOtherConfigDscr -= offset;
 133   2            pHighSpeedConfigDscr -= offset;
 134   2            pFullSpeedConfigDscr -= offset;
 135   2            pStringDscr -= offset;
 136   2         }
 137   1      
 138   1         EZUSB_IRQ_ENABLE();            // Enable USB interrupt (INT2)
 139   1         EZUSB_ENABLE_RSMIRQ();            // Wake-up interrupt
 140   1      
 141   1         INTSETUP |= (bmAV2EN | bmAV4EN);     // Enable INT 2 & 4 autovectoring
 142   1      
 143   1         USBIE |= bmSUDAV | bmSUTOK | bmSUSP | bmURES | bmHSGRANT;   // Enable selected interrupts
 144   1         EA = 1;                  // Enable 8051 interrupts
 145   1      
 146   1      #ifndef NO_RENUM
 147   1         // Renumerate if necessary.  Do this by checking the renum bit.  If it
 148   1         // is already set, there is no need to renumerate.  The renum bit will
 149   1         // already be set if this firmware was loaded from an eeprom.
 150   1         if(!(USBCS & bmRENUM))
 151   1         {
 152   2             EZUSB_Discon(TRUE);   // renumerate
 153   2         }
 154   1      #endif
 155   1      
 156   1         // unconditionally re-connect.  If we loaded from eeprom we are
 157   1         // disconnected and need to connect.  If we just renumerated this
 158   1         // is not necessary but doesn't hurt anything
 159   1         USBCS &=~bmDISCON;
 160   1      
 161   1         CKCON = (CKCON&(~bmSTRETCH)) | FW_STRETCH_VALUE; // Set stretch
 162   1      
 163   1         // clear the Sleep flag.
 164   1         Sleep = FALSE;
 165   1      
 166   1         // Task Dispatcher
 167   1         while(TRUE)               // Main Loop
 168   1         {
 169   2            // Poll User Device
 170   2            TD_Poll();
 171   2      
 172   2            // Check for pending SETUP
 173   2            if(GotSUD)
 174   2            {
 175   3               SetupCommand();          // Implement setup command
 176   3               GotSUD = FALSE;          // Clear SETUP flag
 177   3            }
 178   2      
 179   2            // check for and handle suspend.
C51 COMPILER V7.50   FW                                                                    03/02/2008 15:20:03 PAGE 4   

 180   2            // NOTE: Idle mode stops the processor clock.  There are only two
 181   2            // ways out of idle mode, the WAKEUP pin, and detection of the USB
 182   2            // resume state on the USB bus.  The timers will stop and the
 183   2            // processor will not wake up on any other interrupts.
 184   2            if (Sleep)
 185   2            {
 186   3               if(TD_Suspend())

⌨️ 快捷键说明

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