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