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