📄 f3xx_usb0_standard_requests.lst
字号:
C51 COMPILER V8.17 F3XX_USB0_STANDARD_REQUESTS 03/18/2009 09:55:18 PAGE 1
C51 COMPILER V8.17, COMPILATION OF MODULE F3XX_USB0_STANDARD_REQUESTS
OBJECT MODULE PLACED IN F3xx_USB0_Standard_Requests.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE F3xx_USB0_Standard_Requests.c BROWSE DEBUG OBJECTEXTEND
line level source
1 //-----------------------------------------------------------------------------
2 // F3xx_USB0_Standard_Requests.c
3 //-----------------------------------------------------------------------------
4 // Copyright 2008 Silicon Laboratories, Inc.
5 // http://www.silabs.com
6 //
7 // Program Description:
8 //
9 // Stub file for Firmware Template.
10 //
11 //
12 // How To Test: See Readme.txt
13 //
14 //
15 // FID
16 // Target: C8051F32x/C8051F340
17 // Tool chain: Keil C51 7.50 / Keil EVAL C51
18 // Silicon Laboratories IDE version 2.6
19 // Command Line: See Readme.txt
20 // Project Name: HIDtoUART
21 //
22 // Release 1.0
23 // -Initial Revision (PD)
24 // -04 JUN 2008
25 //
26 //-----------------------------------------------------------------------------
27 // Header Files
28 //-----------------------------------------------------------------------------
29 #include "c8051f3xx.h"
30 #include "F3xx_USB0_Register.h"
31 #include "F3xx_USB0_InterruptServiceRoutine.h"
32 #include "F3xx_USB0_Descriptor.h"
33 #include "F3xx_USB0_ReportHandler.h"
34
35 //-----------------------------------------------------------------------------
36 // Variables
37 //-----------------------------------------------------------------------------
38 extern code device_descriptor DEVICEDESC; // These are created in F3xx_USB0_Descriptor.h
39 extern unsigned char* STRINGDESCTABLE[];
40
41 // Additional declarations for HID:
42 extern code hid_configuration_descriptor HIDCONFIGDESC;
43 extern code hid_report_descriptor HIDREPORTDESC;
44
45 extern setup_buffer SETUP; // Buffer for current device request
46 // information
47 extern unsigned int DATASIZE;
48 extern unsigned int DATASENT;
49 extern unsigned char* DATAPTR;
50
51 // These are response packets used for
52 code unsigned char ONES_PACKET[2] = {0x01, 0x00};
53 // Communication with host
54 code unsigned char ZERO_PACKET[2] = {0x00, 0x00};
55
C51 COMPILER V8.17 F3XX_USB0_STANDARD_REQUESTS 03/18/2009 09:55:18 PAGE 2
56 extern unsigned char USB0_STATE; // Determines current usb device state
57
58 //-----------------------------------------------------------------------------
59 // Definitions
60 //-----------------------------------------------------------------------------
61 // Redefine existing variable names to refer to the descriptors within the
62 // HID configuration descriptor.
63 // This minimizes the impact on the existing source code.
64 #define ConfigDesc (HIDCONFIGDESC.hid_configuration_descriptor)
65 #define InterfaceDesc (HIDCONFIGDESC.hid_interface_descriptor)
66 #define HidDesc (HIDCONFIGDESC.hid_descriptor)
67 #define Endpoint1Desc (HIDCONFIGDESC.hid_endpoint_in_descriptor)
68 #define Endpoint2Desc (HIDCONFIGDESC.hid_endpoint_out_descriptor)
69
70 //-----------------------------------------------------------------------------
71 // Get_Status
72 //-----------------------------------------------------------------------------
73 //
74 // Return Value - None
75 // Parameters - None
76 //
77 // Standard request that should not change for custom HID designs.
78 //
79 // ----------------------------------------------------------------------------
80 void Get_Status (void) // This routine returns a two byte
81 { // status packet to the host
82 1
83 1 if (SETUP.wValue.c[MSB] || SETUP.wValue.c[LSB] ||
84 1 // If non-zero return length or data
85 1 // length not
86 1 SETUP.wLength.c[MSB] || (SETUP.wLength.c[LSB] != 2))
87 1 // Equal to 2 then send a stall
88 1 { // indicating invalid request
89 2 Force_Stall ();
90 2 }
91 1
92 1 switch(SETUP.bmRequestType) // Determine if recipient was device,
93 1 { // interface, or EP
94 2 case OUT_DEVICE: // If recipient was device
95 2 if (SETUP.wIndex.c[MSB] || SETUP.wIndex.c[LSB])
96 2 {
97 3 Force_Stall (); // Send stall if request is invalid
98 3 }
99 2 else
100 2 {
101 3 // Otherwise send 0x00, indicating bus power and no
102 3 // remote wake-up supported
103 3 DATAPTR = (unsigned char*)&ZERO_PACKET;
104 3 DATASIZE = 2;
105 3 }
106 2 break;
107 2
108 2 case OUT_INTERFACE: // See if recipient was interface
109 2 if ((USB0_STATE != DEV_CONFIGURED) ||
110 2 SETUP.wIndex.c[MSB] || SETUP.wIndex.c[LSB])
111 2 // Only valid if device is configured
112 2 // and non-zero index
113 2 {
114 3 Force_Stall (); // Otherwise send stall to host
115 3 }
116 2 else
117 2 {
C51 COMPILER V8.17 F3XX_USB0_STANDARD_REQUESTS 03/18/2009 09:55:18 PAGE 3
118 3 // Status packet always returns 0x00
119 3 DATAPTR = (unsigned char*)&ZERO_PACKET;
120 3 DATASIZE = 2;
121 3 }
122 2 break;
123 2
124 2 case OUT_ENDPOINT: // See if recipient was an endpoint
125 2 if ((USB0_STATE != DEV_CONFIGURED) ||
126 2 SETUP.wIndex.c[MSB]) // Make sure device is configured
127 2 // and index msb = 0x00
128 2 { // otherwise return stall to host
129 3 Force_Stall();
130 3 }
131 2 else
132 2 {
133 3 // Handle case if request is directed to EP 2
134 3 if (SETUP.wIndex.c[LSB] == IN_EP2)
135 3 {
136 4 if (EP_STATUS[2] == EP_HALT)
137 4 { // If endpoint is halted,
138 5 // return 0x01,0x00
139 5 DATAPTR = (unsigned char*)&ONES_PACKET;
140 5 DATASIZE = 2;
141 5 }
142 4 else
143 4 {
144 5 // Otherwise return 0x00,0x00 to indicate endpoint active
145 5 DATAPTR = (unsigned char*)&ZERO_PACKET;
146 5 DATASIZE = 2;
147 5 }
148 4 }
149 3 else
150 3 {
151 4 Force_Stall (); // Send stall if unexpected data
152 4 // encountered
153 4 }
154 3 }
155 2 break;
156 2
157 2 default:
158 2 Force_Stall ();
159 2 break;
160 2 }
161 1 if (EP_STATUS[0] != EP_STALL)
162 1 {
163 2 // Set serviced SETUP Packet, Endpoint 0 in transmit mode, and
164 2 // reset DATASENT counter
165 2 POLL_WRITE_BYTE (E0CSR, rbSOPRDY);
166 2 EP_STATUS[0] = EP_TX;
167 2 DATASENT = 0;
168 2 }
169 1 }
170
171 //-----------------------------------------------------------------------------
172 // Clear_Feature
173 //-----------------------------------------------------------------------------
174 //
175 // Return Value - None
176 // Parameters - None
177 //
178 // Standard request that should not change in custom HID designs.
179 //
C51 COMPILER V8.17 F3XX_USB0_STANDARD_REQUESTS 03/18/2009 09:55:18 PAGE 4
180 //-----------------------------------------------------------------------------
181 void Clear_Feature () // This routine can clear Halt Endpoint
182 { // features on endpoint 1
183 1
184 1 // Send procedural stall if device isn't configured
185 1 if ( (USB0_STATE != DEV_CONFIGURED) ||
186 1 // Or request is made to host(remote wakeup not supported)
187 1 (SETUP.bmRequestType == IN_DEVICE) ||
188 1 // Or request is made to interface
189 1 (SETUP.bmRequestType == IN_INTERFACE) ||
190 1 // Or msbs of value or index set to non-zero value
191 1 SETUP.wValue.c[MSB] || SETUP.wIndex.c[MSB] ||
192 1 // Or data length set to non-zero.
193 1 SETUP.wLength.c[MSB] || SETUP.wLength.c[LSB])
194 1 {
195 2 Force_Stall ();
196 2 }
197 1
198 1 else
199 1 {
200 2 // Verify that packet was directed at an endpoint
201 2 if ( (SETUP.bmRequestType == IN_ENDPOINT)&&
202 2 // The feature selected was HALT_ENDPOINT
203 2 (SETUP.wValue.c[LSB] == ENDPOINT_HALT) &&
204 2 // And that the request was directed at EP 2 in
205 2 ((SETUP.wIndex.c[LSB] == IN_EP2) ) )
206 2 {
207 3 if (SETUP.wIndex.c[LSB] == IN_EP2)
208 3 {
209 4 POLL_WRITE_BYTE (INDEX, 2);// Clear feature endpoint 2 halt
210 4 POLL_WRITE_BYTE (EINCSR1, rbInCLRDT);
211 4 EP_STATUS[2] = EP_IDLE; // Set endpoint 2 status back to idle
212 4 }
213 3 }
214 2 else
215 2 {
216 3 Force_Stall (); // Send procedural stall
217 3 }
218 2 }
219 1 POLL_WRITE_BYTE (INDEX, 0); // Reset Index to 0
220 1 if (EP_STATUS[0] != EP_STALL)
221 1 {
222 2 POLL_WRITE_BYTE (E0CSR, (rbSOPRDY | rbDATAEND));
223 2 // Set Serviced Out packet ready and
224 2 // data end to indicate transaction
225 2 // is over
226 2 }
227 1 }
228
229 //-----------------------------------------------------------------------------
230 // Set_Feature
231 //-----------------------------------------------------------------------------
232 //
233 // Return Value - None
234 // Parameters - None
235 //
236 // Standard request that should not change in custom HID designs.
237 //
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -