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