📄 protocol.lst
字号:
188 1
189 1 //bRecipient is used to judge the recipient of SetUp packet is device/interface/endpoint or other
190 1 bRecipient = sSysInformation.sUsbDeviceRequest.bmRequestType & 0x1F;
191 1
192 1 if ((bRecipient == 0)&& (sSysInformation.sUsbDeviceRequest.wValue==1))
193 1 { //if recipient is device and feature selector is DEVICE_REMOPTE_WAKEUP
194 2 sSysInformation.bRemoteWakeUpEnable = FALSE; //remote wakeup is disabled
195 2
196 2 #ifdef _Debug_
197 2 printf("ClearFeature: Remote wakeup is %x.\n",(unsigned int)(sSysInformation.bRemoteWakeUpEnable));
198 2 #endif
199 2
200 2 ControlOutComplete();
201 2 }
202 1 else if ((bRecipient == 2) && (sSysInformation.sUsbDeviceRequest.wValue==0))
203 1 { //if recipient is endpoint and feature selector is ENDPOINT_HALT
204 2 bEndpointIndex = sSysInformation.sUsbDeviceRequest.wIndex & 0x0F;
205 2 if (sSysInformation.sUsbDeviceRequest.wIndex & 0x80)
206 2 D12SetEndpointStatus((bEndpointIndex*2) + 1 +0x40,D12_ENDPOINT_NO_STALL); //if wIndex direction bit is
-1,select
207 2 //endpoint index 1/3/5,and clear stall bit
208 2 else
209 2 D12SetEndpointStatus((bEndpointIndex*2) + 0x40,D12_ENDPOINT_NO_STALL); //else select endpoint 0/2/4,
210 2
211 2 #ifdef _Debug_
212 2 printf("ClearFeature: Endpoint %x not be stalled.\n",(unsigned int)(sSysInformation.bRemoteWakeUpEnable
-));
213 2 #endif
214 2
215 2 ControlOutComplete();
216 2 }
217 1 else //else,not supported request,and stall endpoint0
218 1 {
219 2 CONTROL_ENDPOINT_STALL //set control endpoint stall
220 2 }
221 1 }
222 //
223 //*************************************************************************
224 // Parameter:
225 // In : None
226 // Out: None
227 // Function:
228 // the process of SetFeature is very similar to ClearFeature
229 void SetFeature(void)
230 {
231 1 unsigned char bEndpointIndex;
232 1 unsigned char bRecipient ;
233 1
234 1 bRecipient= sSysInformation.sUsbDeviceRequest.bmRequestType & 0x1F;
235 1
236 1 if ((bRecipient == 0)&& (sSysInformation.sUsbDeviceRequest.wValue==1))
237 1 { //if recipient is device and feature selector is DEVICE_REMOPTE_WAKEUP
238 2 sSysInformation.bRemoteWakeUpEnable = TRUE; //remote wakeup is enabled
239 2 #ifdef _Debug_
C51 COMPILER V7.01 PROTOCOL 02/17/2006 15:09:24 PAGE 5
240 2 printf("SetFeature: Device remote wakeup enabled!\n");
241 2 #endif
242 2
243 2 ControlOutComplete();
244 2 }
245 1 else if ((bRecipient == 2) && (sSysInformation.sUsbDeviceRequest.wValue==0))
246 1 { //if recipient is endpoint and feature selector is ENDPOINT_HALT
247 2 bEndpointIndex = (unsigned char)(sSysInformation.sUsbDeviceRequest.wIndex) & 0x0F;
248 2 if ((unsigned char)(sSysInformation.sUsbDeviceRequest.wIndex) & 0x80)
249 2 { D12SetEndpointStatus((bEndpointIndex*2) + 1 + 0x40,D12_ENDPOINT_STALL); //if wIndex direction bit is 1
-,select
250 3 //endpoint index 1/3/5,and set stall bit
251 3 }
252 2 else
253 2 {
254 3 D12SetEndpointStatus((bEndpointIndex*2)+0x40,D12_ENDPOINT_STALL); //else select endpoint 0/2/4,
255 3 }
256 2 #ifdef _Debug_
257 2 printf("SetFeature: Endpoint %x is stalled!\n",(unsigned int)(bEndpointIndex));
258 2 #endif
259 2
260 2 ControlOutComplete();
261 2 }
262 1 else
263 1 {
264 2 CONTROL_ENDPOINT_STALL //set control endpoint stall
265 2 }
266 1 }
267 //
268 //*************************************************************************
269 // Parameter:
270 // In : None
271 // Out: None
272 // Function:
273 // After host read device descriptor the first time,it will assignments
274 // a new address to our device.
275 void SetAddress(void)
276 {
277 1 D12SetAddressEnable(sSysInformation.sUsbDeviceRequest.wValue, 1);
278 1
279 1 ControlOutComplete();
280 1 }
281
282 //
283 //*************************************************************************
284 // Parameter:
285 // In : None
286 // Out: None
287 // Function:
288 // Different form other request,get descriptor may be need more than one times IN data transaction.
289 // For example,when received get configuration+interface+endpoint descriptor request,several
290 // times IN transaction is needed.This function will prepare for the data buffer for the first
291 // IN token,but the succeed IN request will be dealed by endpoint0 IN interrupt routine.
292
293 void GetDescriptor(void)
294 {
295 1 unsigned char data bDescriptorType =(unsigned char)((sSysInformation.sUsbDeviceRequest.wValue>>8) & 0xFF)
-; //
296 1
297 1
298 1 if ((bDescriptorType == USB_DEVICE_DESCRIPTOR_TYPE) || (bDescriptorType == USB_CONFIGURATION_DESCRIPTOR_
-TYPE))
C51 COMPILER V7.01 PROTOCOL 02/17/2006 15:09:24 PAGE 6
299 1 {
300 2 if (bDescriptorType == USB_DEVICE_DESCRIPTOR_TYPE)
301 2 {
302 3 //Device Descriptor always is 18 bytes, see USB specification 9.6.1,
303 3 //but the maximum length of endpoint0 of PDIUSBD12 is 16 bytes,so this request need
304 3 //more than one times IN transaction.Here we will ready for the data of first IN transaction,
305 3 //the succeed IN transaction will be dealed with in endpoint0 IN interrupt routine.
306 3
307 3 //in fact,when Host issue GetDescriptor request,the length that host
308 3 //required usually is longer than the descriptor that device declared,
309 3 //but when host received short packet,host will believe he had already got
310 3 //what he want.So here we adjust the wRemaindLength to device's actual length.
311 3 sSysInformation.sUsbSetUpDealwith.pDataSourceAddress = &D12_DEVICE_DESCRIPTOR.bLength;
312 3 if (sSysInformation.sUsbSetUpDealwith.wRemaindLength>sizeof(USB_DEVICE_DESCRIPTOR))
313 3 sSysInformation.sUsbSetUpDealwith.wRemaindLength = sizeof(USB_DEVICE_DESCRIPTOR);
314 3 }
315 2 else
316 2 {
317 3 sSysInformation.sUsbSetUpDealwith.pDataSourceAddress = &D12_CONFIGURATION_INTERFACE_ENDPOINT_DESCRIPTOR
-.D12_CONFIGURATION_DESCRIPTOR.bLength;
318 3 if (sSysInformation.sUsbSetUpDealwith.wRemaindLength>USB_CONFIGURATION_DESCRIPTOR_LENGTH)
319 3 sSysInformation.sUsbSetUpDealwith.wRemaindLength = USB_CONFIGURATION_DESCRIPTOR_LENGTH;
320 3
321 3 }
322 2
323 2 if (sSysInformation.sUsbSetUpDealwith.wRemaindLength >= D12_EP0_MAX_PACKET_SIZE)
324 2 {
325 3 D12WriteBuffer(D12_SELECT_ENDPOINT_CONTROL_IN,D12_EP0_MAX_PACKET_SIZE,sSysInformation.sUsbSetUpDealwith
-.pDataSourceAddress);
326 3
327 3 //remains bytes count should be transmit
328 3 sSysInformation.sUsbSetUpDealwith.wRemaindLength -= D12_EP0_MAX_PACKET_SIZE;
329 3 //data start address of next transmit
330 3 sSysInformation.sUsbSetUpDealwith.pDataSourceAddress += D12_EP0_MAX_PACKET_SIZE;
331 3 //to tell interrupt routine that there has data should be transmit to Host
332 3 sSysInformation.bUsbStatus = TRANSMIT;
333 3 }
334 2 else
335 2 {
336 3 D12WriteBuffer(D12_SELECT_ENDPOINT_CONTROL_IN,sSysInformation.sUsbSetUpDealwith.wRemaindLength,sSysInfo
-rmation.sUsbSetUpDealwith.pDataSourceAddress);
337 3 sSysInformation.sUsbSetUpDealwith.wRemaindLength = 0;
338 3 }
339 2 }
340 1 else //GetDescriptor request only has two kinds, device and configuration descriptor,all others are illeg
-al
341 1 {
342 2 CONTROL_ENDPOINT_STALL //set control endpoint stall
343 2 }
344 1
345 1 }
346 //
347 //*************************************************************************
348 // Parameter:
349 // In : None
350 // Out: None
351 // Function:
352 // If device has been configed,a non-zero value should be returned to Host
353 // For PDIUSBD12 Develop Board,only one configuration value 1 is avaliable.
354 // See USB specification 9.4.2
355 void GetConfiguration(void)
356 {
C51 COMPILER V7.01 PROTOCOL 02/17/2006 15:09:24 PAGE 7
357 1 unsigned char data bConfigurationValue ;
358 1
359 1 bConfigurationValue = sSysInformation.bD12ConfigurationValue;
360 1 D12WriteBuffer(D12_SELECT_ENDPOINT_CONTROL_IN,0x01,&bConfigurationValue );
361 1 sSysInformation.sUsbSetUpDealwith.wRemaindLength = 0;
362 1 }
363
364 //
365 //*************************************************************************
366 // Parameter:
367 // In : None
368 // Out: None
369 // Function:
370 // See USB specification 9.4.7
371 void SetConfiguration(void)
372 {
373 1 if (sSysInformation.sUsbDeviceRequest.wValue == 0)
374 1 {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -