Rev 1 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1 | Rev 196 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /******************** (C) COPYRIGHT 2006 STMicroelectronics ******************** |
1 | /******************** (C) COPYRIGHT 2008 STMicroelectronics ******************** |
2 | * File Name : usb_core.c |
2 | * File Name : usb_core.c |
3 | * Author : MCD Application Team |
3 | * Author : MCD Application Team |
- | 4 | * Version : V4.0.0 |
|
4 | * Date First Issued : 10/27/2003 : V1.0 |
5 | * Date : 09/29/2008 |
5 | * Description : Standard protocol processing (USB v2.0) |
6 | * Description : Standard protocol processing (USB v2.0). |
6 | ******************************************************************************** |
7 | ******************************************************************************** |
7 | * History: |
- | |
8 | * 09/18/2006 : V3.0 |
- | |
9 | * 09/01/2006 : V2.0 |
- | |
10 | * 10/27/2003 : V1.0 |
- | |
11 | ******************************************************************************** |
- | |
12 | * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS |
8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS |
13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. |
9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. |
14 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, |
10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, |
15 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE |
11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE |
16 | * CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING |
12 | * CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING |
17 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. |
13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. |
18 | *******************************************************************************/ |
14 | *******************************************************************************/ |
Line 19... | Line 15... | ||
19 | 15 | ||
- | 16 | /* Includes ------------------------------------------------------------------*/ |
|
- | 17 | /* Private typedef -----------------------------------------------------------*/ |
|
- | 18 | /* Private define ------------------------------------------------------------*/ |
|
- | 19 | /* Private macro -------------------------------------------------------------*/ |
|
- | 20 | /* Private variables ---------------------------------------------------------*/ |
|
- | 21 | /* Private function prototypes -----------------------------------------------*/ |
|
- | 22 | /* Private functions ---------------------------------------------------------*/ |
|
- | 23 | ||
20 | /* Includes ------------------------------------------------------------------*/ |
24 | /* Includes ------------------------------------------------------------------*/ |
21 | #include "usb_lib.h" |
25 | #include "usb_lib.h" |
22 | #include "usb_mem.h" |
26 | #include "usb_mem.h" |
- | 27 | #include "usb_conf.h" |
|
23 | #include "usb_conf.h" |
28 | |
24 | /* Private typedef -----------------------------------------------------------*/ |
29 | /* Private typedef -----------------------------------------------------------*/ |
25 | /* Private define ------------------------------------------------------------*/ |
30 | /* Private define ------------------------------------------------------------*/ |
26 | #define ValBit(VAR,Place) (VAR & (1<<Place)) |
31 | #define ValBit(VAR,Place) (VAR & (1<<Place)) |
27 | #define SetBit(VAR,Place) ( VAR |= (1<<Place) ) |
32 | #define SetBit(VAR,Place) (VAR |= (1<<Place)) |
Line 38... | Line 43... | ||
38 | #define USB_StatusIn() Send0LengthData() |
43 | #define USB_StatusIn() Send0LengthData() |
39 | #define USB_StatusOut() vSetEPRxStatus(EP_RX_VALID) |
44 | #define USB_StatusOut() vSetEPRxStatus(EP_RX_VALID) |
Line 40... | Line 45... | ||
40 | 45 | ||
41 | #define StatusInfo0 StatusInfo.bw.bb1 /* Reverse bb0 & bb1 */ |
46 | #define StatusInfo0 StatusInfo.bw.bb1 /* Reverse bb0 & bb1 */ |
- | 47 | #define StatusInfo1 StatusInfo.bw.bb0 |
|
42 | #define StatusInfo1 StatusInfo.bw.bb0 |
48 | |
43 | /* Private macro -------------------------------------------------------------*/ |
49 | /* Private macro -------------------------------------------------------------*/ |
44 | /* Private variables ---------------------------------------------------------*/ |
50 | /* Private variables ---------------------------------------------------------*/ |
- | 51 | u16_u8 StatusInfo; |
|
45 | u16_u8 StatusInfo; |
52 | bool Data_Mul_MaxPacketSize = FALSE; |
- | 53 | /* Private function prototypes -----------------------------------------------*/ |
|
- | 54 | static void DataStageOut(void); |
|
- | 55 | static void DataStageIn(void); |
|
- | 56 | static void NoData_Setup0(void); |
|
46 | /* Private function prototypes -----------------------------------------------*/ |
57 | static void Data_Setup0(void); |
Line 47... | Line 58... | ||
47 | /* Private functions ---------------------------------------------------------*/ |
58 | /* Private functions ---------------------------------------------------------*/ |
48 | 59 | ||
49 | /******************************************************************************* |
60 | /******************************************************************************* |
50 | * Function Name : Standard_GetConfiguration |
61 | * Function Name : Standard_GetConfiguration. |
51 | * Description : Return the current configuration variable address |
62 | * Description : Return the current configuration variable address. |
52 | * Input : Length - How many bytes are needed. |
- | |
53 | * Output : If "Length" is 0, return the length of configuration value |
63 | * Input : Length - How many bytes are needed. |
54 | If "Length" is not 0, return the data buffer address. |
64 | * Output : None. |
55 | * Return : Return 1 , if the request is invalid when "Length" is 0 |
65 | * Return : Return 1 , if the request is invalid when "Length" is 0. |
56 | Return "Buffer" if the "Length" is not 0 |
66 | * Return "Buffer" if the "Length" is not 0. |
57 | *******************************************************************************/ |
67 | *******************************************************************************/ |
58 | u8 *Standard_GetConfiguration(u16 Length) |
68 | u8 *Standard_GetConfiguration(u16 Length) |
- | 69 | { |
|
- | 70 | if (Length == 0) |
|
59 | { |
71 | { |
- | 72 | pInformation->Ctrl_Info.Usb_wLength = |
|
60 | if (Length == 0){ |
73 | sizeof(pInformation->Current_Configuration); |
61 | pInformation->Ctrl_Info.Usb_wLength = sizeof(pInformation->Current_Configuration); |
74 | |
62 | return 0; |
75 | return 0; |
63 | } |
76 | } |
64 | pUser_Standard_Requests->User_GetConfiguration(); |
77 | pUser_Standard_Requests->User_GetConfiguration(); |
- | 78 | return (u8 *)&pInformation->Current_Configuration; |
|
65 | return (u8 *)&pInformation->Current_Configuration; |
79 | } |
66 | } |
80 | |
67 | /******************************************************************************* |
81 | /******************************************************************************* |
68 | * Function Name : Standard_SetConfiguration |
82 | * Function Name : Standard_SetConfiguration. |
69 | * Description : This routine is called to set the configuration value |
83 | * Description : This routine is called to set the configuration value |
70 | Then each class should configure device themself |
84 | * Then each class should configure device themself. |
71 | * Input : |
85 | * Input : None. |
72 | * Output : |
86 | * Output : None. |
73 | * Return : Return USB_SUCCESS, if the request is performed |
87 | * Return : Return USB_SUCCESS, if the request is performed. |
74 | Return USB_UNSUPPORT, if the request is invalid |
88 | * Return USB_UNSUPPORT, if the request is invalid. |
75 | *******************************************************************************/ |
89 | *******************************************************************************/ |
76 | RESULT Standard_SetConfiguration(void) |
- | |
77 | { |
90 | RESULT Standard_SetConfiguration(void) |
78 | 91 | { |
|
- | 92 | if (pInformation->USBwValue0 <= Device_Table.Total_Configuration |
|
79 | if (pInformation->USBwValue0 <= Device_Table.Total_Configuration && pInformation->USBwValue1==0 |
93 | && pInformation->USBwValue1 == 0 && pInformation->USBwIndex == 0) |
80 | && pInformation->USBwIndex==0) /*call Back usb spec 2.0*/ |
94 | /*call Back usb spec 2.0*/ |
81 | { |
95 | { |
82 | pInformation->Current_Configuration = pInformation->USBwValue0; |
96 | pInformation->Current_Configuration = pInformation->USBwValue0; |
83 | pUser_Standard_Requests->User_SetConfiguration(); |
97 | pUser_Standard_Requests->User_SetConfiguration(); |
84 | return USB_SUCCESS; |
98 | return USB_SUCCESS; |
- | 99 | } |
|
85 | } |
100 | else |
86 | else |
101 | { |
- | 102 | return USB_UNSUPPORT; |
|
- | 103 | } |
|
87 | return USB_UNSUPPORT; |
104 | } |
88 | } |
105 | |
89 | /******************************************************************************* |
106 | /******************************************************************************* |
90 | * Function Name : Standard_GetInterface |
107 | * Function Name : Standard_GetInterface. |
91 | * Description : Return the Alternate Setting of the current interface |
108 | * Description : Return the Alternate Setting of the current interface. |
92 | * Input : Length - How many bytes are needed |
- | |
93 | * Output : If "Length" is 0, return the length of interface value |
109 | * Input : Length - How many bytes are needed. |
94 | If "Length" is not 0, return the data buffer address |
110 | * Output : None. |
95 | * Return : Return 0, if the request is invalid when "Length" is 0 |
111 | * Return : Return 0, if the request is invalid when "Length" is 0. |
96 | Return "Buffer" if the "Length" is not 0 |
112 | * Return "Buffer" if the "Length" is not 0. |
97 | *******************************************************************************/ |
113 | *******************************************************************************/ |
98 | u8 *Standard_GetInterface(u16 Length) |
114 | u8 *Standard_GetInterface(u16 Length) |
- | 115 | { |
|
- | 116 | if (Length == 0) |
|
99 | { |
117 | { |
100 | if (Length == 0){ |
118 | pInformation->Ctrl_Info.Usb_wLength = |
101 | pInformation->Ctrl_Info.Usb_wLength = sizeof(pInformation->Current_AlternateSetting); |
119 | sizeof(pInformation->Current_AlternateSetting); |
102 | return 0; |
120 | return 0; |
103 | } |
121 | } |
104 | pUser_Standard_Requests->User_GetInterface(); |
122 | pUser_Standard_Requests->User_GetInterface(); |
- | 123 | return (u8 *)&pInformation->Current_AlternateSetting; |
|
105 | return (u8 *)&pInformation->Current_AlternateSetting; |
124 | } |
106 | } |
125 | |
107 | /******************************************************************************* |
126 | /******************************************************************************* |
108 | * Function Name : Standard_SetInterface |
127 | * Function Name : Standard_SetInterface. |
109 | * Description : This routine is called to set the interface |
128 | * Description : This routine is called to set the interface. |
110 | Then each class should configure the interface them self |
129 | * Then each class should configure the interface them self. |
111 | * Input : |
130 | * Input : None. |
112 | * Output : |
131 | * Output : None. |
113 | * Return : Return USB_SUCCESS, if the request is performed |
132 | * Return : - Return USB_SUCCESS, if the request is performed. |
114 | Return USB_UNSUPPORT, if the request is invalid |
133 | * - Return USB_UNSUPPORT, if the request is invalid. |
115 | *******************************************************************************/ |
134 | *******************************************************************************/ |
116 | RESULT Standard_SetInterface(void) |
135 | RESULT Standard_SetInterface(void) |
117 | { |
136 | { |
- | 137 | RESULT Re; |
|
118 | RESULT Re; |
138 | /*Test if the specified Interface and Alternate Setting are supported by |
- | 139 | the application Firmware*/ |
|
Line 119... | Line 140... | ||
119 | /*Test if the specified Interface and Alternate Setting are supported by the application Firmware*/ |
140 | Re = (*pProperty->Class_Get_Interface_Setting)(pInformation->USBwIndex0, |
120 | Re = (*pProperty->Class_Get_Interface_Setting)(pInformation->USBwIndex0,pInformation->USBwValue0); |
141 | pInformation->USBwValue0); |
121 | 142 | ||
- | 143 | if (pInformation->Current_Configuration != 0 ) |
|
- | 144 | { |
|
122 | if(pInformation->Current_Configuration!=0 ) |
145 | if (Re != USB_SUCCESS || pInformation->USBwIndex1 != 0 |
- | 146 | || pInformation->USBwValue1 != 0) |
|
123 | { |
147 | { |
124 | if (Re!= USB_SUCCESS || pInformation->USBwIndex1!=0 || pInformation->USBwValue1!=0) |
148 | return USB_UNSUPPORT; |
125 | return USB_UNSUPPORT; |
149 | } |
126 | else if ( Re == USB_SUCCESS) |
150 | else if (Re == USB_SUCCESS) |
127 | { |
151 | { |
128 | pUser_Standard_Requests->User_SetInterface(); |
152 | pUser_Standard_Requests->User_SetInterface(); |
129 | pInformation->Current_Interface = pInformation->USBwIndex0; |
153 | pInformation->Current_Interface = pInformation->USBwIndex0; |
130 | pInformation->Current_AlternateSetting = pInformation->USBwValue0; |
- | |
131 | return USB_SUCCESS; |
154 | pInformation->Current_AlternateSetting = pInformation->USBwValue0; |
132 | } |
- | |
133 | 155 | return USB_SUCCESS; |
|
134 | } |
156 | } |
- | 157 | } |
|
135 | 158 | return USB_UNSUPPORT; |
|
136 | return USB_UNSUPPORT; |
159 | } |
137 | } |
160 | |
138 | /******************************************************************************* |
161 | /******************************************************************************* |
139 | * Function Name : Standard_GetStatus |
162 | * Function Name : Standard_GetStatus. |
140 | * Description : Copy the device request data to "StatusInfo buffer" |
- | |
141 | * Input : Length - How many bytes are needed |
163 | * Description : Copy the device request data to "StatusInfo buffer". |
142 | * Output : If "Length" is 0, return the length of status data |
164 | * Input : - Length - How many bytes are needed. |
143 | If "Length" is not 0, return number of bytes have been copied |
165 | * Output : None. |
144 | * Return : Return 0, if the request is at end of data block, |
166 | * Return : Return 0, if the request is at end of data block, |
145 | or is invalid when "Length" is 0 |
167 | * or is invalid when "Length" is 0. |
146 | *******************************************************************************/ |
168 | *******************************************************************************/ |
- | 169 | u8 *Standard_GetStatus(u16 Length) |
|
147 | u8 *Standard_GetStatus(u16 Length) |
170 | { |
148 | { |
171 | if (Length == 0) |
149 | if (Length == 0){ |
172 | { |
Line 150... | Line 173... | ||
150 | pInformation->Ctrl_Info.Usb_wLength =2; |
173 | pInformation->Ctrl_Info.Usb_wLength = 2; |
151 | return 0; |
174 | return 0; |
Line 152... | Line 175... | ||
152 | } |
175 | } |
- | 176 | ||
- | 177 | StatusInfo.w = 0; |
|
153 | 178 | /* Reset Status Information */ |
|
Line -... | Line 179... | ||
- | 179 | ||
154 | StatusInfo.w = 0; |
180 | if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT)) |
- | 181 | { |
|
155 | /* Reset Status Information */ |
182 | /*Get Device Status */ |
156 | 183 | u8 Feature = pInformation->Current_Feature; |
|
Line -... | Line 184... | ||
- | 184 | ||
157 | if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT)) {/*Get Device Status */ |
185 | /* Remote Wakeup enabled */ |
158 | u8 Feature = pInformation->Current_Feature; |
- | |
159 | 186 | if (ValBit(Feature, 5)) |
|
160 | if (ValBit(Feature, 5)) |
187 | { |
161 | SetBit(StatusInfo0, 1); /* Remote Wakeup enabled */ |
188 | SetBit(StatusInfo0, 1); |
- | 189 | } |
|
- | 190 | ||
- | 191 | /* Bus-powered */ |
|
- | 192 | if (ValBit(Feature, 6)) |
|
- | 193 | { |
|
- | 194 | ClrBit(StatusInfo0, 0); |
|
162 | 195 | } |
|
- | 196 | else /* Self-powered */ |
|
163 | 197 | { |
|
164 | if (ValBit(Feature, 6)) |
198 | SetBit(StatusInfo0, 0); |
- | 199 | } |
|
165 | SetBit(StatusInfo0, 0); /* Self-powered */ |
200 | } |
- | 201 | /*Interface Status*/ |
|
166 | else |
202 | else if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT)) |
167 | ClrBit(StatusInfo0, 0); /* Bus-powered */ |
203 | { |
Line 168... | Line 204... | ||
168 | } |
204 | return (u8 *)&StatusInfo; |
169 | else if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT))/*Interface Status*/ |
205 | } |
- | 206 | /*Get EndPoint Status*/ |
|
170 | return (u8 *)&StatusInfo; |
207 | else if (Type_Recipient == (STANDARD_REQUEST | ENDPOINT_RECIPIENT)) |
171 | 208 | { |
|
- | 209 | u8 Related_Endpoint; |
|
172 | else if (Type_Recipient == (STANDARD_REQUEST | ENDPOINT_RECIPIENT)) {/*Get EndPoint Status*/ |
210 | u8 wIndex0 = pInformation->USBwIndex0; |
173 | u8 Related_Endpoint; |
211 | |
- | 212 | Related_Endpoint = (wIndex0 & 0x0f); |
|
174 | u8 wIndex0 = pInformation->USBwIndex0; |
213 | if (ValBit(wIndex0, 7)) |
- | 214 | { |
|
175 | 215 | /* IN endpoint */ |
|
176 | Related_Endpoint = (wIndex0 & 0x0f); |
216 | if (_GetTxStallStatus(Related_Endpoint)) |
- | 217 | { |
|
177 | if (ValBit(wIndex0, 7)) { |
218 | SetBit(StatusInfo0, 0); /* IN Endpoint stalled */ |
178 | /* IN endpoint */ |
219 | } |
- | 220 | } |
|
Line 179... | Line 221... | ||
179 | if (_GetTxStallStatus( Related_Endpoint )) |
221 | else |
180 | SetBit(StatusInfo0, 0); /* IN Endpoint stalled */ |
222 | { |
- | 223 | /* OUT endpoint */ |
|
181 | } |
224 | if (_GetRxStallStatus(Related_Endpoint)) |
- | 225 | { |
|
182 | else { |
226 | SetBit(StatusInfo0, 0); /* OUT Endpoint stalled */ |
183 | /* OUT endpoint */ |
227 | } |
184 | if (_GetRxStallStatus( Related_Endpoint )) |
228 | } |
- | 229 | ||
185 | SetBit(StatusInfo0, 0); /* OUT Endpoint stalled */ |
230 | } |
186 | } |
231 | else |
187 | 232 | { |
|
188 | } |
233 | return NULL; |
189 | else |
234 | } |
190 | return NULL; |
235 | pUser_Standard_Requests->User_GetStatus(); |
- | 236 | return (u8 *)&StatusInfo; |
|
191 | pUser_Standard_Requests->User_GetStatus(); |
237 | } |
192 | return (u8 *)&StatusInfo; |
238 | |
193 | } |
239 | /******************************************************************************* |
Line 194... | Line 240... | ||
194 | /******************************************************************************* |
240 | * Function Name : Standard_ClearFeature. |
195 | * Function Name : Standard_ClearFeature |
241 | * Description : Clear or disable a specific feature. |
Line 196... | Line 242... | ||
196 | * Description : Clear or disable a specific feature |
242 | * Input : None. |
- | 243 | * Output : None. |
|
197 | * Input : |
244 | * Return : - Return USB_SUCCESS, if the request is performed. |
- | 245 | * - Return USB_UNSUPPORT, if the request is invalid. |
|
198 | * Output : |
246 | *******************************************************************************/ |
199 | * Return : |
247 | RESULT Standard_ClearFeature(void) |
200 | *******************************************************************************/ |
248 | { |
- | 249 | ||
201 | RESULT Standard_ClearFeature(void) |
250 | u32 Type_Rec = Type_Recipient; |
202 | { |
251 | u32 Status; |
203 | 252 | ||
204 | u32 Type_Rec = Type_Recipient; |
253 | |
Line 205... | Line 254... | ||
205 | u32 Status; |
254 | if (Type_Rec == (STANDARD_REQUEST | DEVICE_RECIPIENT)) |
- | 255 | {/*Device Clear Feature*/ |
|
- | 256 | ClrBit(pInformation->Current_Feature, 5); |
|
206 | 257 | pUser_Standard_Requests->User_ClearFeature(); |
|
- | 258 | return USB_SUCCESS; |
|
Line 207... | Line 259... | ||
207 | 259 | } |
|
208 | if ( Type_Rec == (STANDARD_REQUEST | DEVICE_RECIPIENT) ) {/*Device Clear Feature*/ |
260 | else if (Type_Rec == (STANDARD_REQUEST | ENDPOINT_RECIPIENT)) |
209 | ClrBit(pInformation->Current_Feature, 5); |
261 | {/*EndPoint Clear Feature*/ |
210 | return USB_SUCCESS; |
262 | DEVICE* pDev; |
Line -... | Line 263... | ||
- | 263 | u32 Related_Endpoint; |
|
211 | } |
264 | u32 wIndex0; |
- | 265 | u32 rEP; |
|
212 | else if ( Type_Rec == (STANDARD_REQUEST | ENDPOINT_RECIPIENT) ) {/*EndPoint Clear Feature*/ |
266 | |
- | 267 | if (pInformation->USBwValue != ENDPOINT_STALL |
|
- | 268 | || pInformation->USBwIndex1 != 0) |
|
- | 269 | { |
|
213 | DEVICE* pDev; |
270 | return USB_UNSUPPORT; |
- | 271 | } |
|
Line -... | Line 272... | ||
- | 272 | ||
214 | u32 Related_Endpoint; |
273 | pDev = &Device_Table; |
- | 274 | wIndex0 = pInformation->USBwIndex0; |
|
215 | u32 wIndex0; |
275 | rEP = wIndex0 & ~0x80; |
- | 276 | Related_Endpoint = ENDP0 + rEP; |
|
Line -... | Line 277... | ||
- | 277 | ||
216 | u32 rEP; |
278 | if (ValBit(pInformation->USBwIndex0, 7)) |
217 | 279 | { /*Get Status of endpoint & stall the request if the related_ENdpoint is |
|
- | 280 | Disabled*/ |
|
218 | if (pInformation->USBwValue != ENDPOINT_STALL || pInformation->USBwIndex1!=0) |
281 | Status = _GetEPTxStatus(Related_Endpoint); |
219 | return USB_UNSUPPORT; |
282 | } |
220 | 283 | else |
|
221 | pDev = &Device_Table; |
284 | { |
- | 285 | Status = _GetEPRxStatus(Related_Endpoint); |
|
222 | wIndex0 = pInformation->USBwIndex0; |
286 | } |
223 | rEP = wIndex0 & ~0x80; |
287 | |
- | 288 | if (rEP >= pDev->Total_Endpoint || Status == 0 |
|
224 | Related_Endpoint = ENDP0 + rEP; |
289 | || pInformation->Current_Configuration == 0) |
- | 290 | { |
|
225 | 291 | return USB_UNSUPPORT; |
|
226 | if (ValBit(pInformation->USBwIndex0, 7)) Status =_GetEPTxStatus(Related_Endpoint);/*Get Status of endpoint & stall the request if |
292 | } |
227 | the related_ENdpoint is Disabled*/ |
293 | |
228 | else Status =_GetEPRxStatus(Related_Endpoint); |
294 | |
229 | 295 | if (wIndex0 & 0x80) |
|
Line 255... | Line 321... | ||
255 | return USB_SUCCESS; |
321 | return USB_SUCCESS; |
256 | } |
322 | } |
Line 257... | Line 323... | ||
257 | 323 | ||
258 | return USB_UNSUPPORT; |
324 | return USB_UNSUPPORT; |
- | 325 | } |
|
259 | } |
326 | |
260 | /******************************************************************************* |
327 | /******************************************************************************* |
261 | * Function Name : Standard_SetEndPointFeature |
328 | * Function Name : Standard_SetEndPointFeature |
262 | * Description : Set or enable a specific feature of EndPoint |
329 | * Description : Set or enable a specific feature of EndPoint |
263 | * Input : |
330 | * Input : None. |
264 | * Output : |
331 | * Output : None. |
- | 332 | * Return : - Return USB_SUCCESS, if the request is performed. |
|
265 | * Return : |
333 | * - Return USB_UNSUPPORT, if the request is invalid. |
266 | *******************************************************************************/ |
334 | *******************************************************************************/ |
267 | RESULT Standard_SetEndPointFeature(void) |
335 | RESULT Standard_SetEndPointFeature(void) |
268 | { |
336 | { |
269 | u32 wIndex0; |
337 | u32 wIndex0; |
Line 273... | Line 341... | ||
273 | 341 | ||
274 | wIndex0 = pInformation->USBwIndex0; |
342 | wIndex0 = pInformation->USBwIndex0; |
275 | rEP = wIndex0 & ~0x80; |
343 | rEP = wIndex0 & ~0x80; |
Line 276... | Line 344... | ||
276 | Related_Endpoint = ENDP0 + rEP; |
344 | Related_Endpoint = ENDP0 + rEP; |
277 | 345 | ||
- | 346 | if (ValBit(pInformation->USBwIndex0, 7)) |
|
278 | if (ValBit(pInformation->USBwIndex0, 7)) Status =_GetEPTxStatus(Related_Endpoint);/* get Status of endpoint & stall the request if |
347 | { /* get Status of endpoint & stall the request if the related_ENdpoint is |
279 | the related_ENdpoint is Disabled*/ |
348 | Disabled*/ |
- | 349 | Status = _GetEPTxStatus(Related_Endpoint); |
|
280 | else Status =_GetEPRxStatus(Related_Endpoint); |
350 | } |
- | 351 | else |
|
281 | 352 | { |
|
282 | 353 | Status = _GetEPRxStatus(Related_Endpoint); |
|
- | 354 | } |
|
283 | 355 | if (Related_Endpoint >= Device_Table.Total_Endpoint |
|
- | 356 | || pInformation->USBwValue != 0 || Status == 0 |
|
284 | if (Related_Endpoint >= Device_Table.Total_Endpoint || pInformation->USBwValue !=0 || Status==0 || |
357 | || pInformation->Current_Configuration == 0) |
- | 358 | { |
|
285 | pInformation->Current_Configuration==0 /*&& Related_Endpoint!=ENDP0)*/) |
359 | return USB_UNSUPPORT; |
286 | return USB_UNSUPPORT; |
360 | } |
- | 361 | else |
|
287 | else { |
362 | { |
288 | 363 | if (wIndex0 & 0x80) |
|
289 | if (wIndex0 & 0x80) { /* IN endpoint */ |
364 | { /* IN endpoint */ |
Line -... | Line 365... | ||
- | 365 | _SetEPTxStatus(Related_Endpoint, EP_TX_STALL); |
|
290 | _SetEPTxStatus(Related_Endpoint, EP_TX_STALL); |
366 | } |
291 | } |
367 | |
292 | 368 | else |
|
293 | else { /* OUT endpoint */ |
369 | { /* OUT endpoint */ |
294 | _SetEPRxStatus(Related_Endpoint, EP_RX_STALL); |
370 | _SetEPRxStatus(Related_Endpoint, EP_RX_STALL); |
295 | } |
371 | } |
296 | } |
372 | } |
- | 373 | pUser_Standard_Requests->User_SetEndPointFeature(); |
|
297 | pUser_Standard_Requests->User_SetEndPointFeature(); |
374 | return USB_SUCCESS; |
298 | return USB_SUCCESS; |
375 | } |
299 | } |
376 | |
300 | /******************************************************************************* |
377 | /******************************************************************************* |
301 | * Function Name : Standard_SetDeviceFeature |
378 | * Function Name : Standard_SetDeviceFeature. |
302 | * Description : Set or enable a specific feature of Device |
379 | * Description : Set or enable a specific feature of Device. |
- | 380 | * Input : None. |
|
303 | * Input : |
381 | * Output : None. |
304 | * Output : |
382 | * Return : - Return USB_SUCCESS, if the request is performed. |
305 | * Return : |
383 | * - Return USB_UNSUPPORT, if the request is invalid. |
306 | *******************************************************************************/ |
384 | *******************************************************************************/ |
307 | RESULT Standard_SetDeviceFeature(void) |
385 | RESULT Standard_SetDeviceFeature(void) |
308 | { |
386 | { |
Line 309... | Line 387... | ||
309 | SetBit(pInformation->Current_Feature, 5); |
387 | SetBit(pInformation->Current_Feature, 5); |
Line 310... | Line 388... | ||
310 | pUser_Standard_Requests->User_SetDeviceFeature(); |
388 | pUser_Standard_Requests->User_SetDeviceFeature(); |
311 | return USB_SUCCESS; |
389 | return USB_SUCCESS; |
312 | 390 | ||
313 | } |
391 | } |
- | 392 | ||
314 | 393 | /******************************************************************************* |
|
315 | /******************************************************************************* |
394 | * Function Name : Standard_GetDescriptorData. |
316 | * Function Name : Standard_GetDescriptorData |
395 | * Description : Standard_GetDescriptorData is used for descriptors transfer. |
- | 396 | * : This routine is used for the descriptors resident in Flash |
|
317 | * Description : Standard_GetDescriptorData is used for descriptors transfer |
397 | * or RAM |
318 | * : This routine is used for the descriptors resident in Flash or RAM |
398 | * pDesc can be in either Flash or RAM |
319 | pDesc can be in either Flash or RAM |
399 | * The purpose of this routine is to have a versatile way to |
320 | The purpose of this routine is to have a versatile way to response |
400 | * response descriptors request. It allows user to generate |
321 | descriptors request. It allows user to generate certain descriptors |
401 | * certain descriptors with software or read descriptors from |
- | 402 | * external storage part by part. |
|
322 | with software or read descriptors from external storage part by part. |
403 | * Input : - Length - Length of the data in this transfer. |
323 | * Input : Length - Length of the data in this transfer |
404 | * - pDesc - A pointer points to descriptor struct. |
324 | pDesc - A pointer points to descriptor struct. |
405 | * The structure gives the initial address of the descriptor and |
325 | The structure gives the initial address of the |
406 | * its original size. |
326 | descriptor and its original size |
- | |
327 | * Output : Address of a part of the descriptor pointed by the Usb_wOffset |
407 | * Output : None. |
328 | The buffer pointed by this address contains at least Length bytes |
408 | * Return : Address of a part of the descriptor pointed by the Usb_ |
329 | * Return : |
409 | * wOffset The buffer pointed by this address contains at least |
Line 330... | Line 410... | ||
330 | *******************************************************************************/ |
410 | * Length bytes. |
331 | 411 | *******************************************************************************/ |
|
- | 412 | u8 *Standard_GetDescriptorData(u16 Length, ONE_DESCRIPTOR *pDesc) |
|
332 | u8 *Standard_GetDescriptorData(u16 Length, ONE_DESCRIPTOR *pDesc) |
413 | { |
333 | { |
414 | u32 wOffset; |
334 | u32 wOffset; |
415 | |
Line 335... | Line 416... | ||
335 | 416 | wOffset = pInformation->Ctrl_Info.Usb_wOffset; |
|
336 | wOffset = pInformation->Ctrl_Info.Usb_wOffset; |
417 | if (Length == 0) |
- | 418 | { |
|
337 | if (Length == 0) { |
419 | pInformation->Ctrl_Info.Usb_wLength = pDesc->Descriptor_Size - wOffset; |
338 | pInformation->Ctrl_Info.Usb_wLength = pDesc->Descriptor_Size - wOffset; |
420 | return 0; |
339 | return 0; |
421 | } |
340 | } |
422 | |
341 | 423 | return pDesc->Descriptor + wOffset; |
|
342 | return pDesc->Descriptor + wOffset; |
424 | } |
343 | } |
425 | |
344 | /******************************************************************************* |
426 | /******************************************************************************* |
345 | * Function Name : DataStageOut |
427 | * Function Name : DataStageOut. |
346 | * Description : Data stage of a Control Write Transfer |
428 | * Description : Data stage of a Control Write Transfer. |
347 | * Input : |
429 | * Input : None. |
Line 348... | Line 430... | ||
348 | * Output : |
430 | * Output : None. |
Line 349... | Line 431... | ||
349 | * Return : |
431 | * Return : None. |
- | 432 | *******************************************************************************/ |
|
350 | *******************************************************************************/ |
433 | void DataStageOut(void) |
351 | void DataStageOut(void) |
434 | { |
Line 352... | Line 435... | ||
352 | { |
435 | ENDPOINT_INFO *pEPinfo = &pInformation->Ctrl_Info; |
353 | ENDPOINT_INFO *pEPinfo = &pInformation->Ctrl_Info; |
436 | u32 save_rLength; |
- | 437 | ||
354 | u32 save_rLength; |
438 | save_rLength = pEPinfo->Usb_rLength; |
- | 439 | ||
Line 355... | Line 440... | ||
355 | 440 | if (pEPinfo->CopyData && save_rLength) |
|
356 | save_rLength = pEPinfo->Usb_rLength; |
441 | { |
357 | 442 | u8 *Buffer; |
|
Line 358... | Line 443... | ||
358 | if (pEPinfo->CopyData && save_rLength) { |
443 | u32 Length; |
359 | u8 *Buffer; |
444 | |
Line 360... | Line 445... | ||
360 | u32 Length; |
445 | Length = pEPinfo->PacketSize; |
- | 446 | if (Length > save_rLength) |
|
361 | 447 | { |
|
362 | Length = pEPinfo->PacketSize; |
448 | Length = save_rLength; |
363 | if (Length > save_rLength) |
449 | } |
364 | Length = save_rLength; |
450 | |
365 | 451 | Buffer = (*pEPinfo->CopyData)(Length); |
|
366 | Buffer = (*pEPinfo->CopyData)(Length); |
452 | pEPinfo->Usb_rLength -= Length; |
- | 453 | pEPinfo->Usb_rOffset += Length; |
|
367 | pEPinfo->Usb_rLength -= Length; |
454 | |
- | 455 | PMAToUserBufferCopy(Buffer, GetEPRxAddr(ENDP0), Length); |
|
368 | pEPinfo->Usb_rOffset += Length; |
456 | } |
369 | 457 | ||
370 | PMAToUserBufferCopy(Buffer,GetEPRxAddr(ENDP0), Length); |
458 | if (pEPinfo->Usb_rLength != 0) |
- | 459 | { |
|
371 | } |
460 | vSetEPRxStatus(EP_RX_VALID);/* re-enable for next data reception */ |
- | 461 | SetEPTxCount(ENDP0, 0); |
|
372 | 462 | vSetEPTxStatus(EP_TX_VALID);/* Expect the host to abort the data OUT stage */ |
|
373 | if(pEPinfo->Usb_rLength !=0){ |
463 | } |
374 | vSetEPRxStatus(EP_RX_VALID);/* re-enable for next data reception */ |
464 | /* Set the next State*/ |
375 | SetEPTxCount(ENDP0, 0); |
465 | if (pEPinfo->Usb_rLength >= pEPinfo->PacketSize) |
376 | vSetEPTxStatus(EP_TX_VALID);/* Expect the host to abort the data OUT stage */ |
466 | { |
377 | } |
467 | pInformation->ControlState = OUT_DATA; |
378 | /* Set the next State*/ |
- | |
379 | if (pEPinfo->Usb_rLength >= pEPinfo->PacketSize) |
468 | } |
- | 469 | else |
|
380 | pInformation->ControlState = OUT_DATA; |
470 | { |
381 | else |
471 | if (pEPinfo->Usb_rLength > 0) |
382 | { |
472 | { |
383 | if (pEPinfo->Usb_rLength >0) |
473 | pInformation->ControlState = LAST_OUT_DATA; |
384 | pInformation->ControlState = LAST_OUT_DATA; |
474 | } |
385 | else if (pEPinfo->Usb_rLength == 0) |
475 | else if (pEPinfo->Usb_rLength == 0) |
386 | { |
476 | { |
387 | pInformation->ControlState = WAIT_STATUS_IN; |
477 | pInformation->ControlState = WAIT_STATUS_IN; |
388 | USB_StatusIn(); |
478 | USB_StatusIn(); |
389 | } |
479 | } |
390 | } |
480 | } |
Line 405... | Line 495... | ||
405 | 495 | ||
406 | u8 *DataBuffer; |
496 | u8 *DataBuffer; |
Line 407... | Line 497... | ||
407 | u32 Length; |
497 | u32 Length; |
- | 498 | ||
- | 499 | if ((save_wLength == 0) && (ControlState == LAST_IN_DATA)) |
|
- | 500 | { |
|
- | 501 | if(Data_Mul_MaxPacketSize == TRUE) |
|
- | 502 | { |
|
- | 503 | /* No more data to send and empty packet */ |
|
- | 504 | Send0LengthData(); |
|
- | 505 | ControlState = LAST_IN_DATA; |
|
- | 506 | Data_Mul_MaxPacketSize = FALSE; |
|
- | 507 | } |
|
408 | 508 | else |
|
409 | if ((save_wLength == 0) && (ControlState == LAST_IN_DATA)) |
509 | { |
410 | { /* no more data to send so STALL the TX Status*/ |
510 | /* No more data to send so STALL the TX Status*/ |
- | 511 | ControlState = WAIT_STATUS_OUT; |
|
- | 512 | vSetEPTxStatus(EP_TX_STALL); |
|
411 | ControlState = WAIT_STATUS_OUT; |
513 | } |
412 | vSetEPTxStatus(EP_TX_STALL); |
514 | |
Line 413... | Line 515... | ||
413 | goto Expect_Status_Out; |
515 | goto Expect_Status_Out; |
414 | } |
516 | } |
Line 415... | Line 517... | ||
415 | 517 | ||
- | 518 | Length = pEPinfo->PacketSize; |
|
416 | Length = pEPinfo->PacketSize; |
519 | ControlState = (save_wLength <= Length) ? LAST_IN_DATA : IN_DATA; |
- | 520 | ||
Line 417... | Line 521... | ||
417 | ControlState = (save_wLength <= Length) ? LAST_IN_DATA : IN_DATA; |
521 | if (Length > save_wLength) |
Line 418... | Line 522... | ||
418 | 522 | { |
|
Line 429... | Line 533... | ||
429 | pEPinfo->Usb_wOffset += Length; |
533 | pEPinfo->Usb_wOffset += Length; |
430 | vSetEPTxStatus(EP_TX_VALID); |
534 | vSetEPTxStatus(EP_TX_VALID); |
Line 431... | Line 535... | ||
431 | 535 | ||
Line 432... | Line -... | ||
432 | USB_StatusOut();/* Expect the host to abort the data IN stage */ |
- | |
433 | 536 | USB_StatusOut();/* Expect the host to abort the data IN stage */ |
|
434 | 537 | ||
435 | Expect_Status_Out: |
538 | Expect_Status_Out: |
436 | pInformation->ControlState = ControlState; |
539 | pInformation->ControlState = ControlState; |
437 | } |
540 | } |
438 | /******************************************************************************* |
541 | /******************************************************************************* |
439 | * Function Name : NoData_Setup0 |
542 | * Function Name : NoData_Setup0. |
440 | * Description : Proceed the processing of setup request without data stage |
543 | * Description : Proceed the processing of setup request without data stage. |
441 | * Input : None |
544 | * Input : None. |
442 | * Output : None |
545 | * Output : None. |
443 | * Return : None |
546 | * Return : None. |
444 | *******************************************************************************/ |
547 | *******************************************************************************/ |
445 | void NoData_Setup0(void) |
548 | void NoData_Setup0(void) |
446 | { |
549 | { |
447 | RESULT Result = USB_UNSUPPORT; |
550 | RESULT Result = USB_UNSUPPORT; |
Line 448... | Line 551... | ||
448 | u32 RequestNo = pInformation->USBbRequest; |
551 | u32 RequestNo = pInformation->USBbRequest; |
- | 552 | u32 ControlState; |
|
Line 449... | Line 553... | ||
449 | u32 ControlState; |
553 | |
450 | 554 | if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT)) |
|
- | 555 | {/* Device Request*/ |
|
451 | if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT)) {/* Device Request*/ |
556 | |
- | 557 | /* SET_CONFIGURATION*/ |
|
Line 452... | Line 558... | ||
452 | 558 | if (RequestNo == SET_CONFIGURATION) |
|
453 | /* SET_CONFIGURATION*/ |
559 | { |
- | 560 | Result = Standard_SetConfiguration(); |
|
454 | if (RequestNo == SET_CONFIGURATION) |
561 | } |
- | 562 | ||
455 | Result = Standard_SetConfiguration(); |
563 | /*SET ADDRESS*/ |
456 | 564 | else if (RequestNo == SET_ADDRESS) |
|
457 | /*SET ADDRESS*/ |
565 | { |
458 | else if (RequestNo == SET_ADDRESS){ |
566 | if (pInformation->USBwValue0 > 127 || pInformation->USBwValue1 != 0 |
459 | if(pInformation->USBwValue0 > 127 || pInformation->USBwValue1!=0 |
567 | || pInformation->USBwIndex != 0 |
460 | ||pInformation->USBwIndex!=0 || pInformation->Current_Configuration!=0) /* Device Address should be 127 or less*/ |
568 | || pInformation->Current_Configuration != 0) |
- | 569 | /* Device Address should be 127 or less -> call Back spec USB 2.0*/ |
|
- | 570 | { |
|
461 | /*call Beck spec USB 2.0*/ |
571 | ControlState = STALLED; |
- | 572 | goto exit_NoData_Setup0; |
|
462 | { |
573 | } |
463 | ControlState = STALLED; |
574 | else |
464 | goto exit_NoData_Setup0; |
575 | { |
- | 576 | Result = USB_SUCCESS; |
|
- | 577 | } |
|
- | 578 | } |
|
465 | } |
579 | /*SET FEATURE for Device*/ |
- | 580 | else if (RequestNo == SET_FEATURE) |
|
466 | else Result = USB_SUCCESS; |
581 | { |
- | 582 | if (pInformation->USBwValue0 == DEVICE_REMOTE_WAKEUP |
|
467 | } |
583 | && pInformation->USBwIndex == 0 |
- | 584 | && ValBit(pInformation->Current_Feature, 5)) |
|
468 | /*SET FEATURE for Device*/ |
585 | { |
469 | else if (RequestNo == SET_FEATURE){ |
586 | Result = Standard_SetDeviceFeature(); |
- | 587 | } |
|
470 | if (pInformation->USBwValue0==DEVICE_REMOTE_WAKEUP && pInformation->USBwIndex==0 && ValBit(pInformation->Current_Feature, 5)) |
588 | else |
471 | Result = Standard_SetDeviceFeature(); |
589 | { |
- | 590 | Result = USB_UNSUPPORT; |
|
- | 591 | } |
|
- | 592 | } |
|
472 | else |
593 | /*Clear FEATURE for Device */ |
- | 594 | else if (RequestNo == CLEAR_FEATURE) |
|
473 | Result = USB_UNSUPPORT; |
595 | { |
- | 596 | if (pInformation->USBwValue0 == DEVICE_REMOTE_WAKEUP |
|
474 | } |
597 | && pInformation->USBwIndex == 0 |
- | 598 | && ValBit(pInformation->Current_Feature, 5)) |
|
475 | /*Clear FEATURE for Device */ |
599 | { |
476 | else if (RequestNo == CLEAR_FEATURE){ |
600 | Result = Standard_ClearFeature(); |
- | 601 | } |
|
Line 477... | Line 602... | ||
477 | if (pInformation->USBwValue0==DEVICE_REMOTE_WAKEUP && pInformation->USBwIndex==0 && ValBit(pInformation->Current_Feature, 5)) |
602 | else |
Line 478... | Line 603... | ||
478 | Result = Standard_ClearFeature(); |
603 | { |
Line 479... | Line 604... | ||
479 | else |
604 | Result = USB_UNSUPPORT; |
- | 605 | } |
|
Line 480... | Line 606... | ||
480 | Result = USB_UNSUPPORT; |
606 | } |
481 | } |
607 | |
- | 608 | } |
|
482 | 609 | ||
483 | } |
610 | /* Interface Request*/ |
- | 611 | ||
Line 484... | Line 612... | ||
484 | 612 | else if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT)) |
|
Line 485... | Line 613... | ||
485 | /* Interface Request*/ |
613 | { |
- | 614 | ||
486 | 615 | /*SET INTERFACE*/ |
|
487 | else if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT)) { |
616 | if (RequestNo == SET_INTERFACE) |
- | 617 | { |
|
488 | 618 | Result = Standard_SetInterface(); |
|
- | 619 | } |
|
489 | /*SET INTERFACE*/ |
620 | } |
490 | if (RequestNo == SET_INTERFACE) |
621 | |
- | 622 | ||
491 | Result = Standard_SetInterface(); |
623 | /* EndPoint Request*/ |
492 | } |
624 | |
493 | 625 | else if (Type_Recipient == (STANDARD_REQUEST | ENDPOINT_RECIPIENT)) |
|
494 | 626 | { |
|
- | 627 | /*CLEAR FEATURE for EndPoint*/ |
|
495 | /* EndPoint Request*/ |
628 | if (RequestNo == CLEAR_FEATURE) |
- | 629 | { |
|
Line 496... | Line 630... | ||
496 | 630 | Result = Standard_ClearFeature(); |
|
- | 631 | } |
|
497 | else if (Type_Recipient == (STANDARD_REQUEST | ENDPOINT_RECIPIENT)) { |
632 | /* SET FEATURE for EndPoint*/ |
498 | /*CLEAR FEATURE for EndPoint*/ |
633 | else if (RequestNo == SET_FEATURE) |
- | 634 | { |
|
499 | if (RequestNo == CLEAR_FEATURE) |
635 | Result = Standard_SetEndPointFeature(); |
500 | Result = Standard_ClearFeature(); |
636 | } |
501 | /* SET FEATURE for EndPoint*/ |
637 | } |
502 | else if (RequestNo == SET_FEATURE){ |
638 | else |
Line 503... | Line 639... | ||
503 | Result = Standard_SetEndPointFeature(); |
639 | { |
- | 640 | Result = USB_UNSUPPORT; |
|
504 | } |
641 | } |
505 | } |
642 | |
506 | else |
643 | |
Line 507... | Line 644... | ||
507 | Result = USB_UNSUPPORT; |
644 | if (Result != USB_SUCCESS) |
Line 526... | Line 663... | ||
526 | 663 | ||
527 | exit_NoData_Setup0: |
664 | exit_NoData_Setup0: |
528 | pInformation->ControlState = ControlState; |
665 | pInformation->ControlState = ControlState; |
529 | return; |
666 | return; |
- | 667 | } |
|
- | 668 | ||
530 | } |
669 | |
531 | /******************************************************************************* |
670 | /******************************************************************************* |
532 | * Function Name : Data_Setup0 |
671 | * Function Name : Data_Setup0. |
533 | * Description : Proceed the processing of setup request with data stage |
672 | * Description : Proceed the processing of setup request with data stage. |
534 | * Input : |
673 | * Input : None. |
535 | * Output : |
674 | * Output : None. |
536 | * Return : |
675 | * Return : None. |
537 | *******************************************************************************/ |
676 | *******************************************************************************/ |
538 | void Data_Setup0(void) |
677 | void Data_Setup0(void) |
539 | { |
678 | { |
540 | u8 *(*CopyRoutine)(u16); |
679 | u8 *(*CopyRoutine)(u16); |
Line 547... | Line 686... | ||
547 | 686 | ||
548 | 687 | ||
Line 549... | Line 688... | ||
549 | CopyRoutine = NULL; |
688 | CopyRoutine = NULL; |
- | 689 | wOffset = 0; |
|
550 | wOffset = 0; |
690 | |
- | 691 | if (Request_No == GET_DESCRIPTOR) |
|
551 | 692 | { |
|
552 | if (Request_No == GET_DESCRIPTOR) { |
693 | if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT)) |
- | 694 | { |
|
553 | if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT)) { |
695 | u8 wValue1 = pInformation->USBwValue1; |
- | 696 | if (wValue1 == DEVICE_DESCRIPTOR) |
|
554 | u8 wValue1 = pInformation->USBwValue1; |
697 | { |
- | 698 | CopyRoutine = pProperty->GetDeviceDescriptor; |
|
555 | if (wValue1 == DEVICE_DESCRIPTOR) |
699 | } |
- | 700 | else if (wValue1 == CONFIG_DESCRIPTOR) |
|
556 | CopyRoutine = pProperty->GetDeviceDescriptor; |
701 | { |
- | 702 | CopyRoutine = pProperty->GetConfigDescriptor; |
|
557 | else if (wValue1 == CONFIG_DESCRIPTOR) |
703 | } |
558 | CopyRoutine = pProperty->GetConfigDescriptor; |
704 | else if (wValue1 == STRING_DESCRIPTOR) |
559 | else if (wValue1 == STRING_DESCRIPTOR) { |
705 | { |
560 | CopyRoutine = pProperty->GetStringDescriptor; |
706 | CopyRoutine = pProperty->GetStringDescriptor; |
Line 561... | Line 707... | ||
561 | } /* End of GET_DESCRIPTOR */ |
707 | } /* End of GET_DESCRIPTOR */ |
562 | } |
708 | } |
- | 709 | } |
|
- | 710 | ||
- | 711 | /*GET STATUS*/ |
|
563 | } |
712 | else if ((Request_No == GET_STATUS) && (pInformation->USBwValue == 0) |
564 | 713 | && (pInformation->USBwLength == 0x0002) |
|
- | 714 | && (pInformation->USBwIndex1 == 0)) |
|
- | 715 | { |
|
565 | /*GET STATUS*/ |
716 | /* GET STATUS for Device*/ |
566 | else if (Request_No == GET_STATUS && pInformation->USBwValue==0 && pInformation->USBwLength == 0x0002 && pInformation->USBwIndex1==0) { |
717 | if ((Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT)) |
Line 567... | Line 718... | ||
567 | /* GET STATUS for Device*/ |
718 | && (pInformation->USBwIndex == 0)) |
568 | if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT) && pInformation->USBwIndex==0) { |
719 | { |
- | 720 | CopyRoutine = Standard_GetStatus; |
|
569 | CopyRoutine = Standard_GetStatus; |
721 | } |
- | 722 | ||
- | 723 | /* GET STATUS for Interface*/ |
|
570 | } |
724 | else if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT)) |
571 | 725 | { |
|
- | 726 | if (((*pProperty->Class_Get_Interface_Setting)(pInformation->USBwIndex0, 0) == USB_SUCCESS) |
|
Line 572... | Line 727... | ||
572 | /* GET STATUS for Interface*/ |
727 | && (pInformation->Current_Configuration != 0)) |
573 | else if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT)){ |
728 | { |
574 | if ((*pProperty->Class_Get_Interface_Setting)(pInformation->USBwIndex0,0)==USB_SUCCESS && pInformation->Current_Configuration!=0) |
729 | CopyRoutine = Standard_GetStatus; |
575 | CopyRoutine = Standard_GetStatus; |
730 | } |
576 | } |
731 | } |
Line -... | Line 732... | ||
- | 732 | ||
- | 733 | /* GET STATUS for EndPoint*/ |
|
577 | 734 | else if (Type_Recipient == (STANDARD_REQUEST | ENDPOINT_RECIPIENT)) |
|
578 | /* GET STATUS for EndPoint*/ |
735 | { |
579 | else if (Type_Recipient == (STANDARD_REQUEST | ENDPOINT_RECIPIENT)){ |
736 | Related_Endpoint = (pInformation->USBwIndex0 & 0x0f); |
- | 737 | Reserved = pInformation->USBwIndex0 & 0x70; |
|
- | 738 | ||
580 | 739 | if (ValBit(pInformation->USBwIndex0, 7)) |
|
- | 740 | { |
|
581 | Related_Endpoint = (pInformation->USBwIndex0 & 0x0f); |
741 | /*Get Status of endpoint & stall the request if the related_ENdpoint |
Line 582... | Line 742... | ||
582 | Reserved= pInformation->USBwIndex0 & 0x70; |
742 | is Disabled*/ |
- | 743 | Status = _GetEPTxStatus(Related_Endpoint); |
|
- | 744 | } |
|
583 | 745 | else |
|
584 | if (ValBit(pInformation->USBwIndex0, 7)) Status =_GetEPTxStatus(Related_Endpoint);/*Get Status of endpoint & stall the request if |
746 | { |
585 | the related_ENdpoint is Disabled*/ |
747 | Status = _GetEPRxStatus(Related_Endpoint); |
Line 586... | Line 748... | ||
586 | else Status =_GetEPRxStatus(Related_Endpoint); |
748 | } |
- | 749 | ||
587 | 750 | if ((Related_Endpoint < Device_Table.Total_Endpoint) && (Reserved == 0) |
|
588 | 751 | && (Status != 0)) |
|
- | 752 | { |
|
589 | 753 | CopyRoutine = Standard_GetStatus; |
|
- | 754 | } |
|
590 | if(Related_Endpoint < Device_Table.Total_Endpoint && Reserved==0 && Status != 0) |
755 | } |
591 | CopyRoutine = Standard_GetStatus; |
756 | |
- | 757 | } |
|
592 | } |
758 | |
593 | 759 | /*GET CONFIGURATION*/ |
|
- | 760 | else if (Request_No == GET_CONFIGURATION) |
|
594 | 761 | { |
|
- | 762 | if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT)) |
|
595 | } |
763 | { |
596 | /*GET CONFIGURATION*/ |
764 | CopyRoutine = Standard_GetConfiguration; |
- | 765 | } |
|
597 | else if (Request_No == GET_CONFIGURATION) { |
766 | } |
598 | if ( Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT) ) |
- | |
599 | CopyRoutine = Standard_GetConfiguration; |
767 | /*GET INTERFACE*/ |
Line -... | Line 768... | ||
- | 768 | else if (Request_No == GET_INTERFACE) |
|
Line 600... | Line 769... | ||
600 | } |
769 | { |
- | 770 | if ((Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT)) |
|
601 | /*GET INTERFACE*/ |
771 | && (pInformation->Current_Configuration != 0) && (pInformation->USBwValue == 0) |
602 | else if (Request_No == GET_INTERFACE) { |
772 | && (pInformation->USBwIndex1 == 0) && (pInformation->USBwLength == 0x0001) |
603 | if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT) && pInformation->Current_Configuration!=0 |
773 | && ((*pProperty->Class_Get_Interface_Setting)(pInformation->USBwIndex0, 0) == USB_SUCCESS)) |
604 | && pInformation->USBwValue==0 && pInformation->USBwIndex1==0 && pInformation->USBwLength == 0x0001 |
774 | { |
605 | && (*pProperty->Class_Get_Interface_Setting)(pInformation->USBwIndex0,0)==USB_SUCCESS) |
775 | CopyRoutine = Standard_GetInterface; |
606 | CopyRoutine = Standard_GetInterface; |
776 | } |
607 | 777 | ||
608 | } |
778 | } |
- | 779 | ||
609 | 780 | if (CopyRoutine) |
|
610 | 781 | { |
|
- | 782 | pInformation->Ctrl_Info.Usb_wOffset = wOffset; |
|
611 | if (CopyRoutine) { |
783 | pInformation->Ctrl_Info.CopyData = CopyRoutine; |
612 | pInformation->Ctrl_Info.Usb_wOffset = wOffset; |
784 | /* sb in the original the cast to word was directly */ |
613 | pInformation->Ctrl_Info.CopyData = CopyRoutine; |
785 | /* now the cast is made step by step */ |
614 | /* sb in the original the cast to word was directly */ |
786 | (*CopyRoutine)(0); |
Line 615... | Line 787... | ||
615 | /* now the cast is made step by step */ |
787 | Result = USB_SUCCESS; |
- | 788 | } |
|
- | 789 | else |
|
616 | (*CopyRoutine)(0); |
790 | { |
617 | Result = USB_SUCCESS; |
791 | Result = (*pProperty->Class_Data_Setup)(pInformation->USBbRequest); |
618 | } |
792 | if (Result == USB_NOT_READY) |
619 | else { |
793 | { |
- | 794 | pInformation->ControlState = PAUSE; |
|
620 | Result = (*pProperty->Class_Data_Setup)(pInformation->USBbRequest); |
795 | return; |
621 | if (Result == USB_NOT_READY) { |
796 | } |
622 | pInformation->ControlState = PAUSE; |
797 | } |
623 | return; |
798 | |
Line 624... | Line 799... | ||
624 | } |
799 | if (pInformation->Ctrl_Info.Usb_wLength == 0xFFFF) |
- | 800 | { |
|
625 | } |
801 | /* Data is not ready, wait it */ |
626 | 802 | pInformation->ControlState = PAUSE; |
|
Line 627... | Line 803... | ||
627 | if (pInformation->Ctrl_Info.Usb_wLength == 0xFFFF) { /* Data is not ready, wait it */ |
803 | return; |
628 | pInformation->ControlState = PAUSE; |
804 | } |
- | 805 | if ((Result == USB_UNSUPPORT) || (pInformation->Ctrl_Info.Usb_wLength == 0)) |
|
629 | return; |
806 | { |
- | 807 | /* Unsupported request */ |
|
- | 808 | pInformation->ControlState = STALLED; |
|
- | 809 | return; |
|
- | 810 | } |
|
- | 811 | ||
- | 812 | ||
- | 813 | if (ValBit(pInformation->USBbmRequestType, 7)) |
|
- | 814 | { |
|
- | 815 | /* Device ==> Host */ |
|
- | 816 | vu32 wLength = pInformation->USBwLength; |
|
- | 817 | ||
- | 818 | /* Restrict the data length to be the one host asks */ |
|
- | 819 | if (pInformation->Ctrl_Info.Usb_wLength > wLength) |
|
Line 630... | Line 820... | ||
630 | } |
820 | { |
631 | if (Result == USB_UNSUPPORT || pInformation->Ctrl_Info.Usb_wLength == 0) { |
821 | pInformation->Ctrl_Info.Usb_wLength = wLength; |
632 | /* Unsupported request */ |
822 | } |
633 | pInformation->ControlState = STALLED; |
823 | |
- | 824 | else if (pInformation->Ctrl_Info.Usb_wLength < pInformation->USBwLength) |
|
634 | return; |
825 | { |
635 | } |
826 | if (pInformation->Ctrl_Info.Usb_wLength < pProperty->MaxPacketSize) |
636 | 827 | { |
|
Line 637... | Line 828... | ||
637 | 828 | Data_Mul_MaxPacketSize = FALSE; |
|
638 | if (ValBit(pInformation->USBbmRequestType, 7)) { |
829 | } |
- | 830 | else if ((pInformation->Ctrl_Info.Usb_wLength % pProperty->MaxPacketSize) == 0) |
|
639 | /* Device ==> Host */ |
831 | { |
640 | u32 wLength = pInformation->USBwLength; |
832 | Data_Mul_MaxPacketSize = TRUE; |
641 | 833 | } |
|
642 | /* Restrict the data length to be the one host asks */ |
834 | } |
643 | if (pInformation->Ctrl_Info.Usb_wLength > wLength) |
835 | |
644 | pInformation->Ctrl_Info.Usb_wLength = wLength; |
836 | pInformation->Ctrl_Info.PacketSize = pProperty->MaxPacketSize; |
645 | 837 | DataStageIn(); |
|
646 | pInformation->Ctrl_Info.PacketSize = pProperty->MaxPacketSize; |
838 | } |
647 | DataStageIn(); |
839 | else |
648 | } |
840 | { |
649 | else { |
841 | pInformation->ControlState = OUT_DATA; |
650 | pInformation->ControlState = OUT_DATA; |
842 | vSetEPRxStatus(EP_RX_VALID); /* enable for next data reception */ |
651 | vSetEPRxStatus(EP_RX_VALID);/* enable for next data reception */ |
843 | } |
652 | } |
844 | |
653 | 845 | return; |
|
Line 654... | Line 846... | ||
654 | return; |
846 | } |
- | 847 | ||
655 | } /* Data_Setup0 */ |
848 | /******************************************************************************* |
656 | /******************************************************************************* |
849 | * Function Name : Setup0_Process |
657 | * Function Name : Setup0_Process |
850 | * Description : Get the device request data and dispatch to individual process. |
658 | * Description : Get the device request data and dispatch to individual process |
851 | * Input : None. |
659 | * Input : |
852 | * Output : None. |
Line 705... | Line 898... | ||
705 | /* Setup with data stage */ |
898 | /* Setup with data stage */ |
706 | Data_Setup0(); |
899 | Data_Setup0(); |
707 | } |
900 | } |
708 | return Post0_Process(); |
901 | return Post0_Process(); |
709 | } |
902 | } |
- | 903 | ||
710 | /******************************************************************************* |
904 | /******************************************************************************* |
711 | * Function Name : In0_Process |
905 | * Function Name : In0_Process |
712 | * Description : Process the IN token on all default endpoint |
906 | * Description : Process the IN token on all default endpoint. |
713 | * Input : |
907 | * Input : None. |
714 | * Output : |
908 | * Output : None. |
715 | * Return : |
909 | * Return : Post0_Process. |
716 | *******************************************************************************/ |
910 | *******************************************************************************/ |
717 | u8 In0_Process(void) |
911 | u8 In0_Process(void) |
718 | { |
912 | { |
719 | u32 ControlState = pInformation->ControlState; |
913 | u32 ControlState = pInformation->ControlState; |
Line 720... | Line 914... | ||
720 | 914 | ||
721 | if (ControlState == IN_DATA || ControlState == LAST_IN_DATA) |
915 | if ((ControlState == IN_DATA) || (ControlState == LAST_IN_DATA)) |
722 | { |
916 | { |
- | 917 | DataStageIn(); |
|
723 | DataStageIn(); |
918 | ControlState = pInformation->ControlState; |
724 | ControlState = pInformation->ControlState; /* may be changed outside the function */ |
919 | /* may be changed outside the function */ |
725 | } |
- | |
726 | 920 | } |
|
- | 921 | else if (ControlState == WAIT_STATUS_IN) |
|
727 | else if (ControlState == WAIT_STATUS_IN) { |
922 | { |
728 | if (pInformation->USBbRequest == SET_ADDRESS && |
923 | if (pInformation->USBbRequest == SET_ADDRESS && |
729 | Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT) ) |
924 | Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT) ) |
730 | { |
925 | { |
731 | SetDeviceAddress(pInformation->USBwValue0); |
926 | SetDeviceAddress(pInformation->USBwValue0); |
732 | pUser_Standard_Requests->User_SetDeviceAddress(); |
927 | pUser_Standard_Requests->User_SetDeviceAddress(); |
733 | } |
928 | } |
734 | (*pProperty->Process_Status_IN)(); |
929 | (*pProperty->Process_Status_IN)(); |
735 | ControlState = STALLED; |
930 | ControlState = STALLED; |
736 | } |
- | |
737 | 931 | } |
|
- | 932 | else |
|
738 | else |
933 | { |
- | 934 | ControlState = STALLED; |
|
Line 739... | Line 935... | ||
739 | ControlState = STALLED; |
935 | } |
Line 740... | Line 936... | ||
740 | 936 | ||
741 | pInformation->ControlState = ControlState; |
937 | pInformation->ControlState = ControlState; |
- | 938 | ||
742 | 939 | return Post0_Process(); |
|
743 | return Post0_Process(); |
940 | } |
744 | } |
941 | |
745 | /******************************************************************************* |
942 | /******************************************************************************* |
746 | * Function Name : Out0_Process |
943 | * Function Name : Out0_Process |
747 | * Description : Process the OUT token on all default endpoint |
944 | * Description : Process the OUT token on all default endpoint. |
748 | * Input : |
945 | * Input : None. |
749 | * Output : |
946 | * Output : None. |
750 | * Return : |
947 | * Return : Post0_Process. |
751 | *******************************************************************************/ |
948 | *******************************************************************************/ |
Line 752... | Line 949... | ||
752 | u8 Out0_Process(void) |
949 | u8 Out0_Process(void) |
- | 950 | { |
|
753 | { |
951 | u32 ControlState = pInformation->ControlState; |
- | 952 | ||
- | 953 | if ((ControlState == OUT_DATA) || (ControlState == LAST_OUT_DATA)) |
|
754 | u32 ControlState = pInformation->ControlState; |
954 | { |
755 | 955 | DataStageOut(); |
|
- | 956 | ControlState = pInformation->ControlState; |
|
756 | if(ControlState == OUT_DATA || ControlState == LAST_OUT_DATA) |
957 | /* may be changed outside the function */ |
757 | DataStageOut(); |
958 | } |
758 | 959 | else if (ControlState == WAIT_STATUS_OUT) |
|
759 | else if (ControlState == WAIT_STATUS_OUT) { |
- | |
760 | (*pProperty->Process_Status_OUT)(); |
960 | { |
- | 961 | (*pProperty->Process_Status_OUT)(); |
|
761 | ControlState = STALLED; |
962 | ControlState = STALLED; |
762 | } |
963 | } |
763 | 964 | else if ((ControlState == IN_DATA) || (ControlState == LAST_IN_DATA)) |
|
764 | else if (ControlState == IN_DATA || ControlState == LAST_IN_DATA) { |
- | |
765 | /* host aborts the transfer before finish */ |
- | |
766 | ControlState = STALLED; |
965 | { |
767 | } |
966 | /* host aborts the transfer before finish */ |
768 | 967 | ControlState = STALLED; |
|
769 | 968 | } |
|
770 | /* Unexpect state, STALL the endpoint */ |
969 | /* Unexpect state, STALL the endpoint */ |
Line 771... | Line 970... | ||
771 | else { |
970 | else |
Line 772... | Line 971... | ||
772 | 971 | { |
|
773 | ControlState = STALLED; |
972 | ControlState = STALLED; |
Line 774... | Line 973... | ||
774 | } |
973 | } |
775 | 974 | ||
776 | pInformation->ControlState = ControlState; |
975 | pInformation->ControlState = ControlState; |
777 | 976 | ||
778 | return Post0_Process(); |
977 | return Post0_Process(); |
- | 978 | } /* Out0_Process */ |
|
779 | } /* Out0_Process */ |
979 | |
780 | 980 | /******************************************************************************* |
|
781 | /******************************************************************************* |
981 | * Function Name : Post0_Process |
782 | * Function Name : Post0_Process |
982 | * Description : Stall the Endpoint 0 in case of error. |
783 | * Description : |
983 | * Input : None. |
Line 784... | Line 984... | ||
784 | * Input : |
984 | * Output : None. |
- | 985 | * Return : - 0 if the control State is in PAUSE |
|
785 | * Output : |
986 | * - 1 if not. |
786 | * Return : |
987 | *******************************************************************************/ |
787 | *******************************************************************************/ |
988 | u8 Post0_Process(void) |
Line 788... | Line 989... | ||
788 | u8 Post0_Process(void) |
989 | { |
789 | { |
990 | SetEPRxCount(ENDP0, Device_Property.MaxPacketSize); |
- | 991 | ||
790 | SetEPRxCount(ENDP0, Device_Property.MaxPacketSize); |
992 | if (pInformation->ControlState == STALLED) |
791 | 993 | { |
|
792 | if (pInformation->ControlState == STALLED) { |
994 | vSetEPRxStatus(EP_RX_STALL); |
793 | vSetEPRxStatus(EP_RX_STALL); |
995 | vSetEPTxStatus(EP_TX_STALL); |
794 | vSetEPTxStatus(EP_TX_STALL); |
996 | } |
795 | } |
997 | |
796 | 998 | return (pInformation->ControlState == PAUSE); |
|
797 | return (pInformation->ControlState == PAUSE); |
999 | } |
798 | } |
1000 | |
799 | /******************************************************************************* |
1001 | /******************************************************************************* |
800 | * Function Name : SetDeviceAddress |
1002 | * Function Name : SetDeviceAddress. |
Line 801... | Line 1003... | ||
801 | * Description : set the device and all the used Endpoints addresses |
1003 | * Description : Set the device and all the used Endpoints addresses. |
802 | * Input : Val : device adress |
1004 | * Input : - Val: device adress. |
803 | * Output : |
1005 | * Output : None. |
804 | * Return : |
1006 | * Return : None. |
805 | *******************************************************************************/ |
1007 | *******************************************************************************/ |
806 | void SetDeviceAddress(u8 Val) |
1008 | void SetDeviceAddress(u8 Val) |
Line 807... | Line 1009... | ||
807 | { |
1009 | { |
- | 1010 | u32 i; |
|
808 | u32 i; |
1011 | u32 nEP = Device_Table.Total_Endpoint; |
809 | u32 nEP = Device_Table.Total_Endpoint; |
1012 | |
810 | 1013 | /* set address in every used endpoint */ |
|
811 | /* set address in every used endpoint */ |
1014 | for (i = 0; i < nEP; i++) |
812 | for(i=0;i<nEP;i++) |
1015 | { |
813 | { |
1016 | _SetEPAddress((u8)i, (u8)i); |
814 | _SetEPAddress((u8)i, (u8)i); |
1017 | } |
815 | } /* for */ |
1018 | _SetDADDR(Val | DADDR_EF); /* set device address and enable function */ |
816 | _SetDADDR(Val|DADDR_EF); /* set device address and enable function */ |
1019 | |
817 | 1020 | } |
|
818 | } |
1021 |