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

📄 fw_net.c

📁 usb通信Firmware frameworks task dispatcher and device request parser
💻 C
📖 第 1 页 / 共 2 页
字号:
//-----------------------------------------------------------------------------    
//   File:      fw.c    
//   Contents:   Firmware frameworks task dispatcher and device request parser    
//            source.    
//    
// indent 3.  NO TABS!    
//    
// $Revision: 17 $    
// $Date: 11/15/01 5:45p $    
//    
//   Copyright (c) 1997 AnchorChips, Inc. All rights reserved    
//-----------------------------------------------------------------------------    
//-----------------------------------------------------------------------------    
//   File:      fw.c    
//   Contents:  Firmware frameworks task dispatcher and device request parser    
//              source.    
//-----------------------------------------------------------------------------    
#include "fx2.h"    
#include "fx2regs.h"    
//-----------------------------------------------------------------------------    
// Constants    
//-----------------------------------------------------------------------------    
#define DELAY_COUNT   0x9248*8L  // Delay for 8 sec at 24Mhz, 4 sec at 48    
#define _IFREQ  48000            // IFCLK constant for Synchronization Delay    
#define _CFREQ  48000            // CLKOUT constant for Synchronization Delay    
   
//-----------------------------------------------------------------------------    
// Random Macros    
//-----------------------------------------------------------------------------    
#define   min(a,b) (((a)<(b))?(a):(b))    
#define   max(a,b) (((a)>(b))?(a):(b))    
   
  // Registers which require a synchronization delay, see section 15.14    
  // FIFORESET        FIFOPINPOLAR    
  // INPKTEND         OUTPKTEND    
  // EPxBCH:L         REVCTL    
  // GPIFTCB3         GPIFTCB2    
  // GPIFTCB1         GPIFTCB0    
  // EPxFIFOPFH:L     EPxAUTOINLENH:L    
  // EPxFIFOCFG       EPxGPIFFLGSEL    
  // PINFLAGSxx       EPxFIFOIRQ    
  // EPxFIFOIE        GPIFIRQ    
  // GPIFIE           GPIFADRH:L    
  // UDMACRCH:L       EPxGPIFTRIG    
  // GPIFTRIG    
   
  // Note: The pre-REVE EPxGPIFTCH/L register are affected, as well...    
  //      ...these have been replaced by GPIFTC[B3:B0] registers    
   
#include "fx2sdly.h"             // Define _IFREQ and _CFREQ above this #include    
   
//-----------------------------------------------------------------------------    
// Global Variables    
//-----------------------------------------------------------------------------    
volatile BOOL   GotSUD;   
BOOL      Rwuen;   
BOOL      Selfpwr;   
volatile BOOL   Sleep;                  // Sleep mode enable flag    
   
WORD   pDeviceDscr;   // Pointer to Device Descriptor; Descriptors may be moved    
WORD   pDeviceQualDscr;   
WORD   pHighSpeedConfigDscr;   
WORD   pFullSpeedConfigDscr;      
WORD   pConfigDscr;   
WORD   pOtherConfigDscr;      
WORD   pStringDscr;      
   
//-----------------------------------------------------------------------------    
// Function Prototypes    
//-----------------------------------------------------------------------------    
void SetupCommand(void); // 设备请求分析    
// 任务分配    
void TD_Init(void);   
void TD_Poll(void);   
BOOL TD_Suspend(void);   
BOOL TD_Resume(void);   
   
BOOL DR_GetDescriptor(void);   
BOOL DR_SetConfiguration(void);   
BOOL DR_GetConfiguration(void);   
BOOL DR_SetInterface(void);   
BOOL DR_GetInterface(void);   
BOOL DR_GetStatus(void);   
BOOL DR_ClearFeature(void);   
BOOL DR_SetFeature(void);   
BOOL DR_VendorCmnd(void);   
   
// this table is used by the epcs macro (Endpoint Control and Status)    
const char code  EPCS_Offset_Lookup_Table[] =   
{   
   0,    // EP1OUT    
   1,    // EP1IN    
   2,    // EP2OUT    
   2,    // EP2IN    
   3,    // EP4OUT    
   3,    // EP4IN    
   4,    // EP6OUT    
   4,    // EP6IN    
   5,    // EP8OUT    
   5,    // EP8IN    
};   
   
// macro for generating the address of an endpoint's control and status register (EPnCS)    
#define epcs(EP) (EPCS_Offset_Lookup_Table[(EP & 0x7E) | (EP > 128)] + 0xE6A1)    
   
//-----------------------------------------------------------------------------    
// Code    
//-----------------------------------------------------------------------------    
   
// Task dispatcher 任务调度    
void main(void)   
{   
   DWORD   i;   
   WORD   offset;   
   DWORD   DevDescrLen;   
   DWORD   j=0;   
   WORD   IntDescrAddr;   
   WORD   ExtDescrAddr;   
   
   // Initialize Global States 初始化全局变量    
   Sleep = FALSE;               // Disable sleep mode 禁止睡眠方式    
   Rwuen = FALSE;               // Disable remote wakeup 禁止远程唤醒    
   Selfpwr = FALSE;            // Disable self powered 禁止自上电    
   GotSUD = FALSE;               // Clear "Got setup data" flag 清除已有的 setup data 标志    
   
   // Initialize user device 初始化用户 USB 外设    
   TD_Init();   
   
   // The following section of code is used to relocate the descriptor table.     
   // Since the SUDPTRH and SUDPTRL are assigned the address of the descriptor     
   // table, the descriptor table must be located in on-part memory.    
   // The 4K demo tools locate all code sections in external memory.    
   // The descriptor table is relocated by the frameworks ONLY if it is found     
   // to be located in external memory.    
   // 下面的程序用于重定位描述符表,因为SUDPTRH和SUDPTRL被用于描述符表的地址,    
   // 所以描述符表必须放置在片内存储器XRAM中。仅当描述符表放置在片外存储器中时才使用固件进行重定位。    
   pDeviceDscr = (WORD)&DeviceDscr;   
   pDeviceQualDscr = (WORD)&DeviceQualDscr;   
   pHighSpeedConfigDscr = (WORD)&HighSpeedConfigDscr;   
   pFullSpeedConfigDscr = (WORD)&FullSpeedConfigDscr;   
   pStringDscr = (WORD)&StringDscr;   
   
   if (EZUSB_HIGHSPEED())   
   {   
      pConfigDscr = pHighSpeedConfigDscr;   
      pOtherConfigDscr = pFullSpeedConfigDscr;   
   }   
   else   
   {   
      pConfigDscr = pFullSpeedConfigDscr;   
      pOtherConfigDscr = pHighSpeedConfigDscr;   
   }   
   
   if ((WORD)&DeviceDscr & 0xe000)   
   {   
      IntDescrAddr = INTERNAL_DSCR_ADDR;    //0x0080    
      ExtDescrAddr = (WORD)&DeviceDscr;   
      DevDescrLen = (WORD)&UserDscr - (WORD)&DeviceDscr + 2;   
      for (i = 0; i < DevDescrLen; i++)   
         *((BYTE xdata *)IntDescrAddr+i) = 0xCD;   
      for (i = 0; i < DevDescrLen; i++)   
         *((BYTE xdata *)IntDescrAddr+i) = *((BYTE xdata *)ExtDescrAddr+i);   
      pDeviceDscr = IntDescrAddr;   
      offset = (WORD)&DeviceDscr - INTERNAL_DSCR_ADDR;   
      pDeviceQualDscr -= offset;   
      pConfigDscr -= offset;   
      pOtherConfigDscr -= offset;   
      pHighSpeedConfigDscr -= offset;   
      pFullSpeedConfigDscr -= offset;   
      pStringDscr -= offset;   
   }   
   
   EZUSB_IRQ_ENABLE();            // Enable USB interrupt (INT2) 使能USB中断2    
   EZUSB_ENABLE_RSMIRQ();            // Enable Wake-up interrupt 使能唤醒中断    
   
   INTSETUP |= (bmAV2EN | bmAV4EN);     // Enable INT 2 & 4 autovectoring    
   
   USBIE |= bmSUDAV | bmSUTOK | bmSUSP | bmURES | bmHSGRANT;   // Enable selected interrupts    
   EA = 1;                  // Enable 8051 interrupts    
   
#ifndef NO_RENUM    
   // Renumerate if necessary.  Do this by checking the renum bit.  If it    
   // is already set, there is no need to renumerate.  The renum bit will    
   // already be set if this firmware was loaded from an eeprom.    
   if(!(USBCS & bmRENUM))   
   {   
       EZUSB_Discon(TRUE);   // renumerate 重枚举    
   }   
#endif    
   
   // unconditionally re-connect.  If we loaded from eeprom we are    
   // disconnected and need to connect.  If we just renumerated this    

⌨️ 快捷键说明

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