📄 fw.lst
字号:
C51 COMPILER V7.50 FW 11/07/2006 14:52:08 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 ROM(COMPACT) OPTIMIZE(9,SPEED) REGFILE(.\fx2_ata.ORC) BROWSE ORDER INC
-DIR(c:\cypress\usb\target\inc) DEFINE(GPIF=0,FLASH=0,DEVICE_TYPE_IS_SCSI=1,DEVICE_TYPE_IS_IDE=1,VBUS_DETECT=1) DEBUG OBJ
-ECTEXTEND CODE
line 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 // Copyright (c) 2001 Cypress Semiconductor
9 //
10 // $Archive: /USB/atapifx2/software/fw.c $
11 // $Date: 1/15/02 10:12a $
12 // $Revision: 45 $
13 //-----------------------------------------------------------------------------
14 #include "fx2.h"
15 #include "fx2regs.h"
16 #include "gpif.h"
17 #include "atapi.h"
18
19 //-----------------------------------------------------------------------------
20 // Constants
21 //-----------------------------------------------------------------------------
22 #define DELAY_COUNT 0x9248*8L // Delay for 8 sec at 24Mhz, 4 sec at 48
23 // USB constants
24 // Class specific setup commands
25 #define SC_BOMS_RESET (0x21) // Hard/soft depends on wValue field 0 = hard
26
27 //-----------------------------------------------------------------------------
28 // Global Variables
29 //-----------------------------------------------------------------------------
30 BOOL Rwuen;
31 BOOL Selfpwr;
32 volatile BOOL Sleep; // Sleep mode enable flag
33 BYTE AlternateSetting; // Alternate settings
34 BYTE Configuration; // Current configuration
35
36
37 //WORD pDeviceDscr; // Pointer to Device Descriptor; Descriptors may be moved
38 //WORD pDeviceQualDscr;
39 //WORD pHighSpeedConfigDscr;
40 //WORD pFullSpeedConfigDscr;
41 WORD pConfigDscr;
42 WORD pOtherConfigDscr;
43 //WORD pStringDscr;
44
45 BYTE intrfcSubClass;
46
47 //-----------------------------------------------------------------------------
48 // Prototypes
49 //-----------------------------------------------------------------------------
50 void SetupCommand(void);
51 void TD_Init(void);
52 void TD_Poll(void);
53 //BOOL TD_Suspend(void);
C51 COMPILER V7.50 FW 11/07/2006 14:52:08 PAGE 2
54 //BOOL TD_Resume(void);
55 void DisconAndWaitForVbus();
56
57 WORD wPacketSize;
58
59
60 //-----------------------------------------------------------------------------
61 // Code
62 //-----------------------------------------------------------------------------
63
64 // Task dispatcher
65
66 void main(void)
67 {
68 1 BYTE i;
69 1
70 1 // Init globals
71 1 MaxPIO = 0; // reset MaxPIO value
72 1 Sleep = FALSE; // Reset suspend flag
73 1 Rwuen = FALSE; // Disable remote wakeup
74 1 Selfpwr = FALSE; // Disable self powered
75 1
76 1 // if we are hung up in a GPIF transfer, abort it. How could this happen? If
77 1 // we ended up here after a USB Reset or a MSC Reset, it is possible that the
78 1 // GPIF is hung waiting for a transfer that will never complete.
79 1 abortGPIF(); // TPM: Unconditionally abort
80 1
81 1 TD_Init();
82 1
83 1 // The following section of code is used to relocate the descriptor table from
84 1 // ROM to RAM. It is done here because we are done with the halfKBuffer at this point.
85 1 // Although it looks wierd, the only way to get the proper values for the offsets
86 1 // is to tell the compiler that we want the address of the variable, not the variable itself.
87 1 mymemmovexx(halfKBuffer, (char xdata *) &DeviceDscr, (WORD)&DscrEndOffset);
88 1 // pDeviceDscr = (WORD)(halfKBuffer + (WORD)&DeviceDscrOffset);
89 1 // pDeviceQualDscr = (WORD)(halfKBuffer + (WORD)&DeviceQualDscrOffset);
90 1 // pHighSpeedConfigDscr = (WORD)(halfKBuffer + (WORD)&HighSpeedConfigDscrOffset);
91 1 // pFullSpeedConfigDscr = (WORD)(halfKBuffer + (WORD)&FullSpeedConfigDscrOffset);
92 1 // pStringDscr = (WORD)(halfKBuffer + (WORD)&StringDscrOffset);
93 1
94 1 halfKBuffer[(WORD) &IntrfcSubClassHighSpeedOffset] =
95 1 halfKBuffer[(WORD) &IntrfcSubClassFullSpeedOffset] = intrfcSubClass;
96 1
97 1
98 1 for (i = 0; i < ATAPI_INQUIRY_SERIAL_LEN *2; i++)
99 1 halfKBuffer[i+(WORD)&SerialNumberOffset] = localSerialNumber[i];
100 1
101 1 EZUSB_IRQ_ENABLE(); // Enable USB interrupt (INT2)
102 1 EZUSB_ENABLE_RSMIRQ(); // Wake-up interrupt
103 1
104 1 INTSETUP |= (bmAV2EN); // Enable INT 2 autovectoring
105 1
106 1 USBIE |= bmSUDAV | bmSUSP | bmURES | bmHSGRANT; // Enable selected interrupts
107 1 EA = 1; // Enable 8051 interrupts
108 1
109 1 // Renumerate if necessary. Do this by checking the renum bit. If it
110 1 // is already set, there is no need to renumerate. The renum bit will
111 1 // already be set if this firmware was loaded from an eeprom or if we
112 1 // have already been through this code once and we are here again
113 1 // because of a USB Reset.
114 1 if(!(USBCS & bmRENUM))
115 1 {
C51 COMPILER V7.50 FW 11/07/2006 14:52:08 PAGE 3
116 2 EZUSB_Discon(TRUE); // renumerate
117 2 }
118 1
119 1 #ifdef VBUS_DETECT
120 1 // check for the presence of VBus and re-connect. If we loaded from eeprom
121 1 // we are disconnected and need to connect. If we just renumerated this
122 1 // is not necessary but doesn't hurt anything. VBus on the Rev *B 4611 boards
123 1 // is tied to port A.6.
124 1 if (IOA & bmBIT6)
125 1 {
126 2 USBCS &=~bmDISCON;
127 2 }
128 1 else
129 1 {
130 2 DisconAndWaitForVbus();
131 2 }
132 1 #else
// unconditionally re-connect. If we loaded from eeprom we are
// disconnected and need to connect. If we just renumerated this
// is not necessary but doesn't hurt anything
USBCS &=~bmDISCON;
#endif
138 1
139 1 CKCON = (CKCON&(~bmSTRETCH)) | FW_STRETCH_VALUE; // Set stretch to 0 (after renumeration)
140 1
141 1 // complete the handshake phase of any pending SETUP transfer.
142 1 // The only time this should happen is after a MSC Reset. We want
143 1 // to go through all of the EP init code before handshaking the status
144 1 // phase of the MSC Reset.
145 1 EP0CS |= bmHSNAK;
146 1
147 1 // Task Dispatcher
148 1 while(TRUE) // Main Loop
149 1 {
150 2 #ifdef VBUS_DETECT
151 2 // we need to constantly monitor VBus (tied to Port A.6) and disconnect if
152 2 // it isn't there. This is to avoid driving D+ (a spec violation) when the
153 2 // host isn't there.
154 2 if (!(IOA & bmBIT6))
155 2 DisconAndWaitForVbus();
156 2 #endif
157 2
158 2 TD_Poll();
159 2 }
160 1 }
161
162 #ifdef VBUS_DETECT
163 // This function monitors VBus from the host and stays disconnected until VBus is
164 // is present. VBus is tied to Port A.6 on the new FX2 ATAPI tailgate boards.
165 // (4611 Rev *B)
166 void DisconAndWaitForVbus()
167 {
168 1 USBCS |= bmDISCON;
169 1 while (!(IOA & bmBIT6));
170 1 USBCS &= ~bmDISCON;
171 1 }
172 #endif
173
174
175 // Device request parser
176 void SetupCommand(void)
177 {
C51 COMPILER V7.50 FW 11/07/2006 14:52:08 PAGE 4
178 1 void *dscr_ptr;
179 1
180 1 switch(SETUPDAT[1])
181 1 {
182 2 case SC_GET_DESCRIPTOR: // *** Get Descriptor
183 2 switch(SETUPDAT[3])
184 2 {
185 3 case GD_DEVICE: // Device
186 3 SUDPTRH = MSB(pDeviceDscr);
187 3 SUDPTRL = LSB(pDeviceDscr);
188 3 break;
189 3 case GD_DEVICE_QUALIFIER: // Device Qualifier
190 3 SUDPTRH = MSB(pDeviceQualDscr);
191 3 SUDPTRL = LSB(pDeviceQualDscr);
192 3 break;
193 3 case GD_CONFIGURATION: // Configuration
194 3 SUDPTRH = MSB(pConfigDscr);
195 3 SUDPTRL = LSB(pConfigDscr);
196 3 break;
197 3 case GD_OTHER_SPEED_CONFIGURATION: // Other Speed Configuration
198 3 // fx2bug - need to support multi other configs
199 3 SUDPTRH = MSB(pOtherConfigDscr);
200 3 SUDPTRL = LSB(pOtherConfigDscr);
201 3 break;
202 3 case GD_STRING: // String
203 3 if(dscr_ptr = (void *)EZUSB_GetStringDscr(SETUPDAT[2]))
204 3 {
205 4 SUDPTRH = MSB(dscr_ptr);
206 4 SUDPTRL = LSB(dscr_ptr);
207 4 }
208 3 else
209 3 EZUSB_STALL_EP0(); // Stall End Point 0
210 3 break;
211 3 default: // Invalid request
212 3 EZUSB_STALL_EP0(); // Stall End Point 0
213 3 } // switch
214 2 break;
215 2 case SC_GET_INTERFACE: // *** Get Interface
216 2 EP0BUF[0] = AlternateSetting;
217 2 EP0BCH = 0;
218 2 EP0BCL = 1;
219 2 break;
220 2 case SC_SET_INTERFACE: // *** Set Interface
221 2 AlternateSetting = SETUPDAT[2];
222 2 break;
223 2 case SC_SET_CONFIGURATION: // *** Set Configuration
224 2 // BUGBUG -- Add delay for the CATC
225 2 Configuration = SETUPDAT[2];
226 2 break;
227 2 case SC_GET_CONFIGURATION: // *** Get Configuration
228 2 EP0BUF[0] = Configuration;
229 2 EP0BCH = 0;
230 2 EP0BCL = 1;
231 2 break;
232 2 case SC_GET_STATUS: // *** Get Status
233 2 switch(SETUPDAT[0])
234 2 {
235 3 case GS_DEVICE: // Device
236 3 EP0BUF[0] = ((BYTE)Rwuen << 1) | (BYTE)Selfpwr;
237 3 EP0BUF[1] = 0;
238 3 EP0BCH = 0;
239 3 EP0BCL = 2;
C51 COMPILER V7.50 FW 11/07/2006 14:52:08 PAGE 5
240 3 break;
241 3 case GS_INTERFACE: // Interface
242 3 EP0BUF[0] = 0;
243 3 EP0BUF[1] = 0;
244 3 EP0BCH = 0;
245 3 EP0BCL = 2;
246 3 break;
247 3 case GS_ENDPOINT: // End Point
248 3 if (SETUPDAT[4] == 0x2)
249 3 {
250 4 EP0BUF[0] = (EP2CS & bmEPSTALL);
251 4 }
252 3 else if (SETUPDAT[4] == 0x88)
253 3 {
254 4 EP0BUF[0] = (EP8CS & bmEPSTALL);
255 4 }
256 3 else
257 3 {
258 4 EZUSB_STALL_EP0(); // Stall End Point 0
259 4 break;
260 4 }
261 3
262 3 EP0BUF[1] = 0;
263 3 EP0BCH = 0;
264 3 EP0BCL = 2;
265 3 break;
266 3 default: // Invalid Command
267 3 EZUSB_STALL_EP0(); // Stall End Point 0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -