📄 fw.c
字号:
//-----------------------------------------------------------------------------
// File: fw.c
// Contents: Firmware frameworks task dispatcher and device request parser
// source.
// 包含硬件框架任务 调度和设备请求源
// indent 3. NO TABS!
//
// $Revision: 1 $
// $Date: 07/03/26 8:36a $
//
// Copyright (c) 1997 weiyong. All rights reserved
//-----------------------------------------------------------------------------
#include "fx2.h"
#include "fx2regs.h"
#include "string.h"
#include "io.h"
#include "key.h"
#include "led.h"
//#include "serial.h"
#include "eeprom.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变量
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;
//char AD_X;
// int tttttt;
//-----------------------------------------------------------------------------
// Prototypes函数原形
//-----------------------------------------------------------------------------
void SetupCommand(void); //设置命令函数
void TD_Init(void); //初始化函数
void TD_Poll(void); //测量??
//----------------------
void Sys_Timer0_Init ();
void Sys_Timer1_Init ();
void ad0809();
//void tttttt_ioa();
//----------------------
BOOL TD_Suspend(void); //挂起函数,设备进入挂起前调用
BOOL TD_Resume(void); //设备恢复后调用。
BOOL DR_GetDescriptor(void); //得到描述符。BOOL变量
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 宏//里面没有EP0。
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;//外部描述的地址
BYTE temp_data;
// 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
// Initialize user device
TD_Init();
//////user init/////用户函数的初始化,包括IO初始化,寄存器初始化,显示初始化。
IO_Init();
REG_Init();
OKey_RP_Init();
Disp_Init();
EEPROMInit();
//------------------------
Sys_Timer0_Init ();
// Sys_Timer1_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
//因为SUDPTRH and SUDPTRL被分配到描述表的地址,描绘表必须被定位到片内内存中
// table, the descriptor table must be located in on-part memory.
// The 4K demo tools locate all code sections in external memory.
//4K的演示工具把所有的代码定位到片外的内存中
// The descriptor table is relocated by the frameworks ONLY if it is found
//只有描述表被发现被定位到外部内存时,描述表被框架重新定位。
// to be located in external memory.
pDeviceDscr = (WORD)&DeviceDscr;
pDeviceQualDscr = (WORD)&DeviceQualDscr;
pHighSpeedConfigDscr = (WORD)&HighSpeedConfigDscr;
pFullSpeedConfigDscr = (WORD)&FullSpeedConfigDscr;
pStringDscr = (WORD)&StringDscr;
if ((WORD)&DeviceDscr & 0xe000)
{
IntDescrAddr = INTERNAL_DSCR_ADDR;
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)
EZUSB_ENABLE_RSMIRQ(); // Wake-up interrupt
INTSETUP |= (bmAV2EN | bmAV4EN); // Enable INT 2 & 4 autovectoring
USBIE |= bmSUDAV | bmSUTOK | bmSUSP | bmURES | bmHSGRANT; // Enable selected interrupts
/////////user init///////////
// SerialPort_Init();//串口的初始化
//Sys_Timer1and2_Init ();
/////////////////////////////
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
//无条件重新连接,如果我们从EEPROM开始装载,我们断开,需要连接,如果我们重列举,这不是必须的,但不会有
//任何害处
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -