📄 fw.lst
字号:
C51 COMPILER V7.50 FW 04/23/2008 16:45:29 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 // File: fw.c
3 // Contents: Firmware frameworks task dispatcher and device request parser
4 //
5 // $Archive: /USB/Examples/FX2LP/hid_kb/fw.c $
6 // $Date: 5/25/04 4:32p $
7 // $Revision: 6 $
8 //
9 //
10 //-----------------------------------------------------------------------------
11 // Copyright 2003, Cypress Semiconductor Corporation
12 //-----------------------------------------------------------------------------
13 #include "lp.h"
14 #include "lpregs.h"
15 #include "syncdly.h" // SYNCDELAY macro
16
17 //-----------------------------------------------------------------------------
18 // Constants
19 //-----------------------------------------------------------------------------
20 #define DELAY_COUNT 0x9248*8L // Delay for 8 sec at 24Mhz, 4 sec at 48
21 #define _IFREQ 48000 // IFCLK constant for Synchronization Delay
22 #define _CFREQ 48000 // CLKOUT constant for Synchronization Delay
23
24 //-----------------------------------------------------------------------------
25 // Random Macros
26 //-----------------------------------------------------------------------------
27 #define min(a,b) (((a)<(b))?(a):(b))
28 #define max(a,b) (((a)>(b))?(a):(b))
29
30 //-----------------------------------------------------------------------------
31 // Global Variables
32 //-----------------------------------------------------------------------------
33 volatile BOOL GotSUD;
34 BOOL Rwuen;
35 BOOL Selfpwr;
36 volatile BOOL Sleep; // Sleep mode enable flag
37
38 WORD pDeviceDscr; // Pointer to Device Descriptor; Descriptors may be moved
39 WORD pDeviceQualDscr;
40 WORD pHighSpeedConfigDscr;
41 WORD pFullSpeedConfigDscr;
42 WORD pConfigDscr;
43 WORD pOtherConfigDscr;
44 WORD pStringDscr;
45
46 //-----------------------------------------------------------------------------
47 // Prototypes
48 //-----------------------------------------------------------------------------
49 void SetupCommand(void);
50 void TD_Init(void);
51 void TD_Poll(void);
52 BOOL TD_Suspend(void);
53 BOOL TD_Resume(void);
54
55 BOOL DR_GetDescriptor(void);
C51 COMPILER V7.50 FW 04/23/2008 16:45:29 PAGE 2
56 BOOL DR_SetConfiguration(void);
57 BOOL DR_GetConfiguration(void);
58 BOOL DR_SetInterface(void);
59 BOOL DR_GetInterface(void);
60 BOOL DR_GetStatus(void);
61 BOOL DR_ClearFeature(void);
62 BOOL DR_SetFeature(void);
63 BOOL DR_VendorCmnd(void);
64 void DR_SetData(void);
65
66 // this table is used by the epcs macro
67 const char code EPCS_Offset_Lookup_Table[] =
68 {
69 0, // EP1OUT
70 1, // EP1IN
71 2, // EP2OUT
72 2, // EP2IN
73 3, // EP4OUT
74 3, // EP4IN
75 4, // EP6OUT
76 4, // EP6IN
77 5, // EP8OUT
78 5, // EP8IN
79 };
80
81 // macro for generating the address of an endpoint's control and status register (EPnCS)
82 #define epcs(EP) (EPCS_Offset_Lookup_Table[(EP & 0x7E) | (EP > 128)] + 0xE6A1)
83
84 //-----------------------------------------------------------------------------
85 // Code
86 //-----------------------------------------------------------------------------
87
88 // Task dispatcher
89 void main(void)
90 {
91 1 DWORD i;
92 1 WORD offset;
93 1 DWORD DevDescrLen;
94 1 DWORD j=0;
95 1 WORD IntDescrAddr;
96 1 WORD ExtDescrAddr;
97 1
98 1 // Initialize Global States
99 1 Sleep = FALSE; // Disable sleep mode
100 1 Rwuen = FALSE; // Disable remote wakeup
101 1 Selfpwr = FALSE; // Disable self powered
102 1 GotSUD = FALSE; // Clear "Got setup data" flag
103 1
104 1 // Initialize user device
105 1 TD_Init();
106 1
107 1 // The following section of code is used to relocate the descriptor table.
108 1 // The frameworks uses SUDPTRH and SUDPTRL to automate the SETUP requests
109 1 // for descriptors. These registers only work with memory locations
110 1 // in the EZ-USB internal RAM. Therefore, if the descriptors are located
111 1 // in external RAM, they must be copied to in internal RAM.
112 1 // The descriptor table is relocated by the frameworks ONLY if it is found
113 1 // to be located in external memory.
114 1 pDeviceDscr = (WORD)&DeviceDscr;
115 1 pDeviceQualDscr = (WORD)&DeviceQualDscr;
116 1 pHighSpeedConfigDscr = (WORD)&HighSpeedConfigDscr;
117 1 pFullSpeedConfigDscr = (WORD)&FullSpeedConfigDscr;
C51 COMPILER V7.50 FW 04/23/2008 16:45:29 PAGE 3
118 1 pStringDscr = (WORD)&StringDscr;
119 1
120 1 // Is the descriptor table in external RAM (> 16Kbytes)? If yes,
121 1 // then relocate.
122 1 // Note that this code only checks if the descriptors START in
123 1 // external RAM. It will not work if the descriptor table spans
124 1 // internal and external RAM.
125 1 if ((WORD)&DeviceDscr & 0xC000)
126 1 {
127 2 // first, relocate the descriptors
128 2 IntDescrAddr = INTERNAL_DSCR_ADDR;
129 2 ExtDescrAddr = (WORD)&DeviceDscr;
130 2 DevDescrLen = (WORD)&UserDscr - (WORD)&DeviceDscr + 2;
131 2 for (i = 0; i < DevDescrLen; i++)
132 2 *((BYTE xdata *)IntDescrAddr+i) = *((BYTE xdata *)ExtDescrAddr+i);
133 2
134 2 // update all of the descriptor pointers
135 2 pDeviceDscr = IntDescrAddr;
136 2 offset = (WORD)&DeviceDscr - INTERNAL_DSCR_ADDR;
137 2 pDeviceQualDscr -= offset;
138 2 pConfigDscr -= offset;
139 2 pOtherConfigDscr -= offset;
140 2 pHighSpeedConfigDscr -= offset;
141 2 pFullSpeedConfigDscr -= offset;
142 2 pStringDscr -= offset;
143 2 }
144 1
145 1 EZUSB_IRQ_ENABLE(); // Enable USB interrupt (INT2)
146 1 EZUSB_ENABLE_RSMIRQ(); // Wake-up interrupt
147 1
148 1 INTSETUP |= (bmAV2EN | bmAV4EN); // Enable INT 2 & 4 autovectoring
149 1
150 1 USBIE |= bmSUDAV | bmSUTOK | bmSUSP | bmURES | bmHSGRANT; // Enable selected interrupts
151 1 EA = 1; // Enable 8051 interrupts
152 1
153 1 #ifndef NO_RENUM
154 1 // Renumerate if necessary. Do this by checking the renum bit. If it
155 1 // is already set, there is no need to renumerate. The renum bit will
156 1 // already be set if this firmware was loaded from an eeprom.
157 1 if(!(USBCS & bmRENUM))
158 1 {
159 2 EZUSB_Discon(TRUE); // renumerate
160 2 }
161 1 #endif
162 1
163 1 // unconditionally re-connect. If we loaded from eeprom we are
164 1 // disconnected and need to connect. If we just renumerated this
165 1 // is not necessary but doesn't hurt anything
166 1 USBCS &=~bmDISCON;
167 1
168 1 CKCON = (CKCON&(~bmSTRETCH)) | FW_STRETCH_VALUE; // Set stretch
169 1
170 1 // clear the Sleep flag.
171 1 Sleep = FALSE;
172 1
173 1 // Task Dispatcher
174 1 while(TRUE) // Main Loop
175 1 {
176 2 // Poll User Device
177 2 TD_Poll();
178 2
179 2 // Check for pending SETUP
C51 COMPILER V7.50 FW 04/23/2008 16:45:29 PAGE 4
180 2 if(GotSUD)
181 2 {
182 3 SetupCommand(); // Implement setup command
183 3 GotSUD = FALSE; // Clear SETUP flag
184 3 }
185 2
186 2 // check for and handle suspend.
187 2 // NOTE: Idle mode stops the processor clock. There are only two
188 2 // ways out of idle mode, the WAKEUP pin, and detection of the USB
189 2 // resume state on the USB bus. The timers will stop and the
190 2 // processor will not wake up on any other interrupts.
191 2 if (Sleep)
192 2 {
193 3 if(TD_Suspend())
194 3 {
195 4 Sleep = FALSE; // Clear the "go to sleep" flag. Do it here to prevent any race condition
-between wakeup and the next sleep.
196 4 do
197 4 {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -