📄 fw.lst
字号:
C51 COMPILER V7.50 FW 09/24/2007 17:04:29 PAGE 1
C51 COMPILER V7.50, COMPILATION OF MODULE FW
OBJECT MODULE PLACED IN fw.OBJ
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE fw.c BROWSE INCDIR(c:\cypress\usb\target\inc) 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 09/24/2007 17:04: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
65 // this table is used by the epcs macro
66 const char code EPCS_Offset_Lookup_Table[] =
67 {
68 0, // EP1OUT
69 1, // EP1IN
70 2, // EP2OUT
71 2, // EP2IN
72 3, // EP4OUT
73 3, // EP4IN
74 4, // EP6OUT
75 4, // EP6IN
76 5, // EP8OUT
77 5, // EP8IN
78 };
79
80 // macro for generating the address of an endpoint's control and status register (EPnCS)
81 #define epcs(EP) (EPCS_Offset_Lookup_Table[(EP & 0x7E) | (EP > 128)] + 0xE6A1)
82
83 //-----------------------------------------------------------------------------
84 // Code
85 //-----------------------------------------------------------------------------
86
87 // Task dispatcher
88 void main(void)
89 {
90 1 DWORD i;
91 1 WORD offset;
92 1 DWORD DevDescrLen;
93 1 DWORD j=0;
94 1 WORD IntDescrAddr;
95 1 WORD ExtDescrAddr;
96 1
97 1 // Initialize Global States
98 1 Sleep = FALSE; // Disable sleep mode
99 1 Rwuen = FALSE; // Disable remote wakeup
100 1 Selfpwr = FALSE; // Disable self powered
101 1 GotSUD = FALSE; // Clear "Got setup data" flag
102 1
103 1 // Initialize user device
104 1 TD_Init();
105 1
106 1 // The following section of code is used to relocate the descriptor table.
107 1 // The frameworks uses SUDPTRH and SUDPTRL to automate the SETUP requests
108 1 // for descriptors. These registers only work with memory locations
109 1 // in the EZ-USB internal RAM. Therefore, if the descriptors are located
110 1 // in external RAM, they must be copied to in internal RAM.
111 1 // The descriptor table is relocated by the frameworks ONLY if it is found
112 1 // to be located in external memory.
113 1 pDeviceDscr = (WORD)&DeviceDscr;
114 1 pDeviceQualDscr = (WORD)&DeviceQualDscr;
115 1 pHighSpeedConfigDscr = (WORD)&HighSpeedConfigDscr;
116 1 pFullSpeedConfigDscr = (WORD)&FullSpeedConfigDscr;
117 1 pStringDscr = (WORD)&StringDscr;
C51 COMPILER V7.50 FW 09/24/2007 17:04:29 PAGE 3
118 1
119 1 // Is the descriptor table in external RAM (> 16Kbytes)? If yes,
120 1 // then relocate.
121 1 // Note that this code only checks if the descriptors START in
122 1 // external RAM. It will not work if the descriptor table spans
123 1 // internal and external RAM.
124 1 if ((WORD)&DeviceDscr & 0xC000)
125 1 {
126 2 // first, relocate the descriptors
127 2 IntDescrAddr = INTERNAL_DSCR_ADDR;
128 2 ExtDescrAddr = (WORD)&DeviceDscr;
129 2 DevDescrLen = (WORD)&UserDscr - (WORD)&DeviceDscr + 2;
130 2 for (i = 0; i < DevDescrLen; i++)
131 2 *((BYTE xdata *)IntDescrAddr+i) = *((BYTE xdata *)ExtDescrAddr+i);
132 2
133 2 // update all of the descriptor pointers
134 2 pDeviceDscr = IntDescrAddr;
135 2 offset = (WORD)&DeviceDscr - INTERNAL_DSCR_ADDR;
136 2 pDeviceQualDscr -= offset;
137 2 pConfigDscr -= offset;
138 2 pOtherConfigDscr -= offset;
139 2 pHighSpeedConfigDscr -= offset;
140 2 pFullSpeedConfigDscr -= offset;
141 2 pStringDscr -= offset;
142 2 }
143 1
144 1 EZUSB_IRQ_ENABLE(); // Enable USB interrupt (INT2)
145 1 EZUSB_ENABLE_RSMIRQ(); // Wake-up interrupt
146 1
147 1 INTSETUP |= (bmAV2EN | bmAV4EN); // Enable INT 2 & 4 autovectoring
148 1
149 1 USBIE |= bmSUDAV | bmSUTOK | bmSUSP | bmURES | bmHSGRANT; // Enable selected interrupts
150 1 EA = 1; // Enable 8051 interrupts
151 1
152 1 #ifndef NO_RENUM
153 1 // Renumerate if necessary. Do this by checking the renum bit. If it
154 1 // is already set, there is no need to renumerate. The renum bit will
155 1 // already be set if this firmware was loaded from an eeprom.
156 1 if(!(USBCS & bmRENUM))
157 1 {
158 2 EZUSB_Discon(TRUE); // renumerate
159 2 }
160 1 #endif
161 1
162 1 // unconditionally re-connect. If we loaded from eeprom we are
163 1 // disconnected and need to connect. If we just renumerated this
164 1 // is not necessary but doesn't hurt anything
165 1 USBCS &=~bmDISCON;
166 1
167 1 CKCON = (CKCON&(~bmSTRETCH)) | FW_STRETCH_VALUE; // Set stretch
168 1
169 1 // clear the Sleep flag.
170 1 Sleep = FALSE;
171 1
172 1 // Task Dispatcher
173 1 while(TRUE) // Main Loop
174 1 {
175 2 // Poll User Device
176 2 TD_Poll();
177 2
178 2 // Check for pending SETUP
179 2 if(GotSUD)
C51 COMPILER V7.50 FW 09/24/2007 17:04:29 PAGE 4
180 2 {
181 3 SetupCommand(); // Implement setup command
182 3 GotSUD = FALSE; // Clear SETUP flag
183 3 }
184 2
185 2 // check for and handle suspend.
186 2 // NOTE: Idle mode stops the processor clock. There are only two
187 2 // ways out of idle mode, the WAKEUP pin, and detection of the USB
188 2 // resume state on the USB bus. The timers will stop and the
189 2 // processor will not wake up on any other interrupts.
190 2 if (Sleep)
191 2 {
192 3 if(TD_Suspend())
193 3 {
194 4 Sleep = FALSE; // Clear the "go to sleep" flag. Do it here to prevent any race condition
-between wakeup and the next sleep.
195 4 do
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -