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

📄 fw.lst

📁 部分USB学习资料
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.00  FW                                                                     09/27/2002 10:11:22 PAGE 1   


C51 COMPILER V7.00, COMPILATION OF MODULE FW
OBJECT MODULE PLACED IN FW.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE FW.C OPTIMIZE(9,SIZE) DEBUG OBJECTEXTEND

stmt level    source

   1          //-----------------------------------------------------------------------------
   2          //      File:           fw.c
   3          //      Contents:       Firmware frameworks task dispatcher and device request parser
   4          //                              source.
   5          //
   6          //      Copyright (c) 1997 AnchorChips, Inc. All rights reserved
   7          //-----------------------------------------------------------------------------
   8          #include "ezusb.h"
   9          #include "ezregs.h"
  10          
  11          //-----------------------------------------------------------------------------
  12          // Random Macros
  13          //-----------------------------------------------------------------------------
  14          #define min(a,b) (((a)<(b))?(a):(b))
  15          #define max(a,b) (((a)>(b))?(a):(b))
  16          
  17          //-----------------------------------------------------------------------------
  18          // Constants
  19          //-----------------------------------------------------------------------------
  20          
  21          //-----------------------------------------------------------------------------
  22          // Global Variables
  23          //-----------------------------------------------------------------------------
  24          volatile BOOL   GotSUD;
  25          BOOL            Rwuen;
  26          BOOL            Selfpwr;
  27          volatile BOOL   Sleep;                                          // Sleep mode enable flag
  28          
  29          WORD    pDeviceDscr;    // Pointer to Device Descriptor; Descriptors may be moved
  30          WORD    pConfigDscr;    
  31          WORD    pStringDscr;    
  32          
  33          //-----------------------------------------------------------------------------
  34          // Prototypes
  35          //-----------------------------------------------------------------------------
  36          void SetupCommand(void);
  37          void TD_Init(void);
  38          void GpifInit(void);
  39          void TD_Poll(void);
  40          BOOL TD_Suspend(void);
  41          BOOL TD_Resume(void);
  42          
  43          BOOL DR_GetDescriptor(void);
  44          BOOL DR_SetConfiguration(void);
  45          BOOL DR_GetConfiguration(void);
  46          BOOL DR_SetInterface(void);
  47          BOOL DR_GetInterface(void);
  48          BOOL DR_GetStatus(void);
  49          BOOL DR_ClearFeature(void);
  50          BOOL DR_SetFeature(void);
  51          BOOL DR_VendorCmnd(void);
  52          
  53          //-----------------------------------------------------------------------------
  54          // Code
  55          //-----------------------------------------------------------------------------
C51 COMPILER V7.00  FW                                                                     09/27/2002 10:11:22 PAGE 2   

  56          
  57          // Task dispatcher
  58          void main(void)
  59          {
  60   1              DWORD   i;
  61   1              WORD    offset;
  62   1              DWORD   DevDescrLen;
  63   1              DWORD   j=0;
  64   1              WORD    IntDescrAddr;
  65   1              WORD    ExtDescrAddr;
  66   1      
  67   1              // Initialize Global States
  68   1              Sleep = FALSE;                                  // Disable sleep mode
  69   1              Rwuen = FALSE;                                  // Disable remote wakeup
  70   1              Selfpwr = FALSE;                                // Disable self powered
  71   1              GotSUD = FALSE;                                 // Clear "Got setup data" flag
  72   1      
  73   1              // Initialize user device
  74   1              TD_Init();
  75   1          GpifInit();
  76   1      
  77   1              // The following section of code is used to relocate the descriptor table. 
  78   1              // Since the SUDPTRH and SUDPTRL are assigned the address of the descriptor 
  79   1              // table, the descriptor table must be located in on-part memory.
  80   1              // The 4K demo tools locate all code sections in external memory.
  81   1              // The descriptor table is relocated by the frameworks ONLY if it is found 
  82   1              // to be located in external memory.
  83   1              pDeviceDscr = (WORD)&DeviceDscr;
  84   1              pConfigDscr = (WORD)&ConfigDscr;
  85   1              pStringDscr = (WORD)&StringDscr;
  86   1              if ((WORD)&DeviceDscr & 0xe000)
  87   1              {
  88   2                      IntDescrAddr = INTERNAL_DSCR_ADDR;
  89   2                      ExtDescrAddr = (WORD)&DeviceDscr;
  90   2                      DevDescrLen = (WORD)&UserDscr - (WORD)&DeviceDscr + 2;
  91   2                      for (i = 0; i < DevDescrLen; i++)
  92   2                              *((BYTE xdata *)IntDescrAddr+i) = 0xCD;
  93   2                      for (i = 0; i < DevDescrLen; i++)
  94   2                              *((BYTE xdata *)IntDescrAddr+i) = *((BYTE xdata *)ExtDescrAddr+i);
  95   2                      pDeviceDscr = IntDescrAddr;
  96   2                      offset = (WORD)&DeviceDscr - INTERNAL_DSCR_ADDR;
  97   2                      pConfigDscr -= offset;
  98   2                      pStringDscr -= offset;
  99   2              }
 100   1      
 101   1              EZUSB_IRQ_ENABLE();                             // Enable USB interrupt (INT2)
 102   1              EZUSB_ENABLE_RSMIRQ();                          // Wake-up interrupt
 103   1      
 104   1              // The 8051 is responsible for all USB events, even those that have happened
 105   1              // before this point.  We cannot ignore pending USB interrupts.
 106   1              // The chip will come out of reset with the flags all cleared.
 107   1              //      USBIRQ = 0xff;                          // Clear any pending USB interrupt requests
 108   1              PORTCCFG |= 0xc0;                               // Turn on r/w lines for external memory 
 109   1      
 110   1              USBBAV = USBBAV | 1 & ~bmBREAK; // Disable breakpoints and autovectoring
 111   1              USBIEN |= bmSUDAV | bmSUTOK | bmSUSP | bmURES;  // Enable selected interrupts
 112   1              EA = 1;                                         // Enable 8051 interrupts
 113   1      
 114   1         #ifndef NO_RENUM
 115   1         // Note: at full speed, high speed hosts may take 5 sec to detect device
 116   1         EZUSB_Discon(TRUE); // Renumerate
 117   1         #endif
C51 COMPILER V7.00  FW                                                                     09/27/2002 10:11:22 PAGE 3   

 118   1      
 119   1      
 120   1              CKCON = (CKCON&(~bmSTRETCH)) | FW_STRETCH_VALUE; // Set stretch to 0 (after renumeration)
 121   1      
 122   1              // Task Dispatcher
 123   1              while(TRUE)                                     // Main Loop
 124   1              {
 125   2                      if(GotSUD)                              // Wait for SUDAV
 126   2                      {
 127   3                              SetupCommand();                 // Implement setup command
 128   3                              GotSUD = FALSE;                 // Clear SUDAV flag
 129   3                      }
 130   2      
 131   2                      // Poll User Device
 132   2                      // NOTE: Idle mode stops the processor clock.  There are only two
 133   2                      // ways out of idle mode, the WAKEUP pin, and detection of the USB
 134   2                      // resume state on the USB bus.  The timers will stop and the
 135   2                      // processor will not wake up on any other interrupts.
 136   2                      if (Sleep)
 137   2                          {
 138   3                      if(TD_Suspend())
 139   3                          { 
 140   4                          Sleep = FALSE;                      // Clear the "go to sleep" flag.  Do it here to prevent any race condition b
             -etween wakeup and the next sleep.
 141   4                          do
 142   4                              {
 143   5                                  EZUSB_Susp();                       // Place processor in idle mode.
 144   5                              }
 145   4                      while(!Rwuen && EZUSB_EXTWAKEUP());
 146   4                      // Must continue to go back into suspend if the host has disabled remote wakeup
 147   4                      // *and* the wakeup was caused by the external wakeup pin.
 148   4                      
 149   4                              // 8051 activity will resume here due to USB bus or Wakeup# pin activity.
 150   4                              EZUSB_Resume(); // If source is the Wakeup# pin, signal the host to Resume.             
 151   4                              TD_Resume();
 152   4                          }   
 153   3                          }
 154   2                      TD_Poll();
 155   2              }
 156   1      }
 157          
 158          // Device request parser
 159          void SetupCommand(void)
 160          {
 161   1              void    *dscr_ptr;
 162   1              DWORD   i;

⌨️ 快捷键说明

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