📄 f32x_usb_standard_requests.lst
字号:
C51 COMPILER V7.06 F32X_USB_STANDARD_REQUESTS 07/16/2008 15:35:21 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE F32X_USB_STANDARD_REQUESTS
OBJECT MODULE PLACED IN F32x_USB_Standard_Requests.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\c51.exe F32x_USB_Standard_Requests.c DB OE
stmt level source
1 //-----------------------------------------------------------------------------
2 // F32x_USB_Standard_Requests.c
3 //-----------------------------------------------------------------------------
4 // Copyright 2005 Silicon Laboratories, Inc.
5 // http://www.silabs.com
6 //
7 // Program Description:
8 //
9 // Source file for USB firmware. Includes service routine
10 // for usb standard device requests.
11 //
12 //
13 // How To Test: See Readme.txt
14 //
15 //
16 // FID: 32X000018
17 // Target: C8051F32x
18 // Tool chain: Keil C51 7.50 / Keil EVAL C51
19 // Silicon Laboratories IDE version 2.6
20 // Command Line: See Readme.txt
21 // Project Name: F32x_USB_Bulk
22 //
23 //
24 // Release 1.3
25 // -All changes by GP
26 // -21 NOV 2005
27 // -Changed revision number to match project revision
28 // No content changes to this file
29 // -Modified file to fit new formatting guidelines
30 // -Changed file name from usb_stdreq.c
31 //
32 //
33 // Release 1.2
34 // -Initial Revision (JS)
35 // -XX AUG 2003
36 //
37
38 //-----------------------------------------------------------------------------
39 // Includes
40 //-----------------------------------------------------------------------------
41
42 #include "c8051F320.h"
43 #include "F32x_USB_Registers.h"
44 #include "F32x_USB_Structs.h"
45 #include "F32x_USB_Main.h"
46 #include "F32x_USB_Descriptors.h"
47 #include "F32x_USB_Config.h"
48 #include "F32x_USB_Request.h"
49
50 //-----------------------------------------------------------------------------
51 // Extern Global Variables
52 //-----------------------------------------------------------------------------
53
54 extern code DESCRIPTORS gDescriptorMap;
55 extern DEVICE_STATUS gDeviceStatus;
C51 COMPILER V7.06 F32X_USB_STANDARD_REQUESTS 07/16/2008 15:35:21 PAGE 2
56 extern EP_STATUS gEp0Status;
57 extern EP_STATUS gEp2OutStatus;
58 extern EP_STATUS gEp1InStatus;
59 extern EP0_COMMAND gEp0Command;
60
61 //-----------------------------------------------------------------------------
62 // Global Variables
63 //-----------------------------------------------------------------------------
64
65 BYTE bEpState;
66 UINT uNumBytes;
67 PIF_STATUS pIfStatus;
68
69 //------------------------------------------------------------------------
70 // Standard Request Routines
71 //------------------------------------------------------------------------
72 //
73 // These functions should be called when an endpoint0 command has
74 // been received with a corresponding "bRequest" field.
75 //
76 // - Each routine performs all command field checking, and
77 // modifies fields of the Ep0Status structure accordingly
78 //
79 // After a call to a standard request routine, the calling routine
80 // should check Ep0Status.bEpState to determine the required action
81 // (i.e., send a STALL for EP_ERROR, load the FIFO for EP_TX).
82 // For transmit status, the data pointer (Ep0Status.pData),
83 // and data length (Ep0Status.uNumBytes) are prepared before the
84 // standard request routine returns. The calling routine must write
85 // the data to the FIFO and handle all data transfer
86
87 //-----------------------------------------------------------------------------
88 // SetAddressRequest
89 //-----------------------------------------------------------------------------
90 //
91 // Return Value : None
92 // Parameters : None
93 //
94 //-----------------------------------------------------------------------------
95 void SetAddressRequest ()
96 {
97 1 // Index and Length fields must be zero
98 1 // Device state must be default or addressed
99 1 if ((gEp0Command.wIndex.i) || (gEp0Command.wLength.i) ||
100 1 (gDeviceStatus.bDevState == DEV_CONFIG))
101 1 {
102 2 bEpState = EP_ERROR;
103 2 }
104 1
105 1 else
106 1 {
107 2 // Assign new function address
108 2 UWRITE_BYTE(FADDR, gEp0Command.wValue.c[1]);
109 2 if (gDeviceStatus.bDevState == DEV_DEFAULT &&
110 2 gEp0Command.wValue.c[1] != 0)
111 2 {
112 3 gDeviceStatus.bDevState = DEV_ADDRESS;
113 3 }
114 2 if (gDeviceStatus.bDevState == DEV_ADDRESS &&
115 2 gEp0Command.wValue.c[1] == 0)
116 2 {
117 3 gDeviceStatus.bDevState = DEV_ADDRESS;
C51 COMPILER V7.06 F32X_USB_STANDARD_REQUESTS 07/16/2008 15:35:21 PAGE 3
118 3 }
119 2 bEpState = EP_IDLE;
120 2 }
121 1 gEp0Status.bEpState = bEpState;
122 1 }
123
124 //-----------------------------------------------------------------------------
125 // SetFeatureRequest
126 //-----------------------------------------------------------------------------
127 //
128 // Return Value : None
129 // Parameters : None
130 //
131 //-----------------------------------------------------------------------------
132 void SetFeatureRequest ()
133 {
134 1 // Length field must be zero
135 1 // Device state must be configured, or addressed with Command Index
136 1 // field == 0
137 1 if ((gEp0Command.wLength.i != 0) ||
138 1 (gDeviceStatus.bDevState == DEV_DEFAULT) ||
139 1 (gDeviceStatus.bDevState == DEV_ADDRESS && gEp0Command.wIndex.i != 0))
140 1 {
141 2 bEpState = EP_ERROR;
142 2 }
143 1
144 1 // Handle based on recipient
145 1 switch(gEp0Command.bmRequestType & CMD_MASK_RECIP)
146 1 {
147 2 // Device Request - Return error as remote wakeup is not supported
148 2 case CMD_RECIP_DEV:
149 2 bEpState = EP_ERROR;
150 2 break;
151 2
152 2 // Endpoint Request
153 2 case CMD_RECIP_EP:
154 2 if (gEp0Command.wValue.i == ENDPOINT_HALT)
155 2 {
156 3 bEpState = HaltEndpoint(gEp0Command.wIndex.i);
157 3 break;
158 3 }
159 2 else
160 2 {
161 3 bEpState = EP_ERROR;
162 3 break;
163 3 }
164 2 default:
165 2 bEpState = EP_ERROR;
166 2 break;
167 2 }
168 1 gEp0Status.bEpState = bEpState;
169 1 }
170
171 //-----------------------------------------------------------------------------
172 // ClearFeatureRequest
173 //-----------------------------------------------------------------------------
174 //
175 // Return Value : None
176 // Parameters : None
177 //
178 //-----------------------------------------------------------------------------
179 void ClearFeatureRequest ()
C51 COMPILER V7.06 F32X_USB_STANDARD_REQUESTS 07/16/2008 15:35:21 PAGE 4
180 {
181 1 // Length field must be zero
182 1 // Device state must be configured, or addressed with Command Index
183 1 // field == 0
184 1 if ((gEp0Command.wLength.i != 0) || (gDeviceStatus.bDevState == DEV_DEFAULT) ||
185 1 (gDeviceStatus.bDevState == DEV_ADDRESS && gEp0Command.wIndex.i != 0))
186 1 {
187 2 bEpState = EP_ERROR;
188 2 }
189 1
190 1 // Handle based on recipient
191 1 switch(gEp0Command.bmRequestType & CMD_MASK_RECIP)
192 1 {
193 2 // Device Request
194 2 case CMD_RECIP_DEV:
195 2 // Remote wakeup not supported
196 2 bEpState = EP_ERROR;
197 2 break;
198 2
199 2 // Endpoint Request
200 2 case CMD_RECIP_EP:
201 2 if (gEp0Command.wValue.i == ENDPOINT_HALT)
202 2 {
203 3 // Enable the selected endpoint.
204 3 bEpState = EnableEndpoint(gEp0Command.wIndex.i);
205 3 break;
206 3 }
207 2 else
208 2 {
209 3 bEpState = EP_ERROR;
210 3 break;
211 3 }
212 2 default:
213 2 bEpState = EP_ERROR;
214 2 break;
215 2 }
216 1 gEp0Status.bEpState = bEpState;
217 1 }
218
219 //-----------------------------------------------------------------------------
220 // SetConfigurationRequest
221 //-----------------------------------------------------------------------------
222 //
223 // Return Value : None
224 // Parameters : None
225 //
226 //-----------------------------------------------------------------------------
227 void SetConfigurationRequest ()
228 {
229 1 // Index and Length fields must be zero
230 1 // Device state must be addressed or configured
231 1 if ((gEp0Command.wIndex.i) || (gEp0Command.wLength.i) ||
232 1 (gDeviceStatus.bDevState == DEV_DEFAULT))
233 1 {
234 2 bEpState = EP_ERROR;
235 2 }
236 1
237 1 else
238 1 {
239 2 // Make sure assigned configuration exists
240 2 if (gEp0Command.wValue.c[1] >
241 2 gDescriptorMap.bStdDevDsc[std_bNumConfigurations])
C51 COMPILER V7.06 F32X_USB_STANDARD_REQUESTS 07/16/2008 15:35:21 PAGE 5
242 2 {
243 3 bEpState = EP_ERROR;
244 3 }
245 2
246 2 // Handle zero configuration assignment
247 2 else if (gEp0Command.wValue.c[1] == 0)
248 2 gDeviceStatus.bDevState = DEV_ADDRESS;
249 2
250 2 // Select the assigned configuration
251 2 else
252 2 bEpState = SetConfiguration(gEp0Command.wValue.c[1]);
253 2 }
254 1 gEp0Status.bEpState = bEpState;
255 1 }
256
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -