📄 fw.lst
字号:
C51 COMPILER V7.50 FW 04/23/2009 15:18:27 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 BROWSE DEBUG OBJECTEXTEND
line level source
1 //-----------------------------------------------------------------------------
2 // 文件: fw.c
3 // 内容: 固件框架任务分配器和设备求求分析
4 //-----------------------------------------------------------------------------
5 #include "fx2.h"
6 #include "fx2regs.h"
7
8
9 //-----------------------------------------------------------------------------
10 // 常量
11 //-----------------------------------------------------------------------------
12 #define DELAY_COUNT 0x9248*8L // Delay for 8 sec at 24Mhz, 4 sec at 48
13 #define _IFREQ 48000 // IFCLK constant for Synchronization Delay
14 #define _CFREQ 48000 // CLKOUT constant for Synchronization Delay
15
16 //-----------------------------------------------------------------------------
17 // 宏定义
18 //-----------------------------------------------------------------------------
19 #define min(a,b) (((a)<(b))?(a):(b))
20 #define max(a,b) (((a)>(b))?(a):(b))
21
22 // Registers which require a synchronization delay, see section 15.14
23 // FIFORESET FIFOPINPOLAR
24 // INPKTEND OUTPKTEND
25 // EPxBCH:L REVCTL
26 // GPIFTCB3 GPIFTCB2
27 // GPIFTCB1 GPIFTCB0
28 // EPxFIFOPFH:L EPxAUTOINLENH:L
29 // EPxFIFOCFG EPxGPIFFLGSEL
30 // PINFLAGSxx EPxFIFOIRQ
31 // EPxFIFOIE GPIFIRQ
32 // GPIFIE GPIFADRH:L
33 // UDMACRCH:L EPxGPIFTRIG
34 // GPIFTRIG
35
36 // Note: The pre-REVE EPxGPIFTCH/L register are affected, as well...
37 // ...these have been replaced by GPIFTC[B3:B0] registers
38
39 #include "fx2sdly.h" // Define _IFREQ and _CFREQ above this #include
40
41 //-----------------------------------------------------------------------------
42 // Global Variables
43 //-----------------------------------------------------------------------------
44 volatile BOOL GotSUD;
45 BOOL Rwuen;
46 BOOL Selfpwr;
47 volatile BOOL Sleep; // Sleep mode enable flag
48
49 WORD pDeviceDscr; // Pointer to Device Descriptor; Descriptors may be moved
50 WORD pDeviceQualDscr;
51 WORD pHighSpeedConfigDscr;
52 WORD pFullSpeedConfigDscr;
53 WORD pConfigDscr;
54 WORD pOtherConfigDscr;
55 WORD pStringDscr;
C51 COMPILER V7.50 FW 04/23/2009 15:18:27 PAGE 2
56
57 //-----------------------------------------------------------------------------
58 // Prototypes
59 //-----------------------------------------------------------------------------
60 void SetupCommand(void);
61 void TD_Init(void);
62 void TD_Poll(void);
63 BOOL TD_Suspend(void);
64 BOOL TD_Resume(void);
65
66 BOOL DR_GetDescriptor(void);
67 BOOL DR_SetConfiguration(void);
68 BOOL DR_GetConfiguration(void);
69 BOOL DR_SetInterface(void);
70 BOOL DR_GetInterface(void);
71 BOOL DR_GetStatus(void);
72 BOOL DR_ClearFeature(void);
73 BOOL DR_SetFeature(void);
74 BOOL DR_VendorCmnd(void);
75
76 // this table is used by the epcs macro
77 const char code EPCS_Offset_Lookup_Table[] =
78 {
79 0, // EP1OUT
80 1, // EP1IN
81 2, // EP2OUT
82 2, // EP2IN
83 3, // EP4OUT
84 3, // EP4IN
85 4, // EP6OUT
86 4, // EP6IN
87 5, // EP8OUT
88 5, // EP8IN
89 };
90
91 // macro for generating the address of an endpoint's control and status register (EPnCS)
92 #define epcs(EP) (EPCS_Offset_Lookup_Table[(EP & 0x7E) | (EP > 128)] + 0xE6A1)
93
94 //-----------------------------------------------------------------------------
95 // Code
96 //-----------------------------------------------------------------------------
97
98 // Task dispatcher
99 void main(void)
100 {
101 1 DWORD i;
102 1 WORD offset;
103 1 DWORD DevDescrLen;
104 1 DWORD j=0;
105 1 WORD IntDescrAddr;
106 1 WORD ExtDescrAddr;
107 1
108 1 // Initialize Global States
109 1 Sleep = FALSE; // Disable sleep mode
110 1 Rwuen = FALSE; // Disable remote wakeup
111 1 Selfpwr = FALSE; // Disable self powered
112 1 GotSUD = FALSE; // Clear "Got setup data" flag
113 1
114 1 // Initialize user device
115 1 TD_Init();
116 1
117 1 // The following section of code is used to relocate the descriptor table.
C51 COMPILER V7.50 FW 04/23/2009 15:18:27 PAGE 3
118 1 // Since the SUDPTRH and SUDPTRL are assigned the address of the descriptor
119 1 // table, the descriptor table must be located in on-part memory.
120 1 // The 4K demo tools locate all code sections in external memory.
121 1 // The descriptor table is relocated by the frameworks ONLY if it is found
122 1 // to be located in external memory.
123 1 pDeviceDscr = (WORD)&DeviceDscr;
124 1 pDeviceQualDscr = (WORD)&DeviceQualDscr;
125 1 pHighSpeedConfigDscr = (WORD)&HighSpeedConfigDscr;
126 1 pFullSpeedConfigDscr = (WORD)&FullSpeedConfigDscr;
127 1 pStringDscr = (WORD)&StringDscr;
128 1
129 1 if ((WORD)&DeviceDscr & 0xe000)
130 1 {
131 2 IntDescrAddr = INTERNAL_DSCR_ADDR;
132 2 ExtDescrAddr = (WORD)&DeviceDscr;
133 2 DevDescrLen = (WORD)&UserDscr - (WORD)&DeviceDscr + 2;
134 2 for (i = 0; i < DevDescrLen; i++)
135 2 *((BYTE xdata *)IntDescrAddr+i) = 0xCD;
136 2 for (i = 0; i < DevDescrLen; i++)
137 2 *((BYTE xdata *)IntDescrAddr+i) = *((BYTE xdata *)ExtDescrAddr+i);
138 2 pDeviceDscr = IntDescrAddr;
139 2 offset = (WORD)&DeviceDscr - INTERNAL_DSCR_ADDR;
140 2 pDeviceQualDscr -= offset;
141 2 pConfigDscr -= offset;
142 2 pOtherConfigDscr -= offset;
143 2 pHighSpeedConfigDscr -= offset;
144 2 pFullSpeedConfigDscr -= offset;
145 2 pStringDscr -= offset;
146 2 }
147 1
148 1 EZUSB_IRQ_ENABLE(); // Enable USB interrupt (INT2)
149 1 EZUSB_ENABLE_RSMIRQ(); // Wake-up interrupt
150 1
151 1 INTSETUP |= (bmAV2EN | bmAV4EN); // Enable INT 2 & 4 autovectoring
152 1
153 1 USBIE |= bmSUDAV | bmSUTOK | bmSUSP | bmURES | bmHSGRANT; // Enable selected interrupts
154 1
155 1 //SerialPort_Init();
156 1
157 1 EA = 1; // Enable 8051 interrupts
158 1
159 1 #ifndef NO_RENUM
160 1 // Renumerate if necessary. Do this by checking the renum bit. If it
161 1 // is already set, there is no need to renumerate. The renum bit will
162 1 // already be set if this firmware was loaded from an eeprom.
163 1 if(!(USBCS & bmRENUM))
164 1 {
165 2 EZUSB_Discon(TRUE); // renumerate
166 2 }
167 1 #endif
168 1
169 1 // unconditionally re-connect. If we loaded from eeprom we are
170 1 // disconnected and need to connect. If we just renumerated this
171 1 // is not necessary but doesn't hurt anything
172 1 USBCS &=~bmDISCON;
173 1
174 1 CKCON = (CKCON&(~bmSTRETCH)) | FW_STRETCH_VALUE; // Set stretch to 0 (after renumeration)
175 1
176 1 // clear the Sleep flag.
177 1 Sleep = FALSE;
178 1
179 1
C51 COMPILER V7.50 FW 04/23/2009 15:18:27 PAGE 4
180 1
181 1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -