This file contains the USB control endpoint management routines corresponding to the standard enumeration process (refer to chapter 9 of the USB specification). This file calls routines of the usb_specific_request.c file for non-standard request management. The enumeration parameters (descriptor tables) are contained in the usb_descriptors.c file.
Definition in file usb_standard_request.c.
#include "conf_usb.h"
#include "usb_drv.h"
#include "usb_descriptors.h"
#include "usb_standard_request.h"
#include "usb_specific_request.h"
#include "usb_task.h"
Go to the source code of this file.
Functions | |
static void | usb_clear_feature (void) |
This function manages the CLEAR FEATURE request. | |
static void | usb_get_configuration (void) |
This function manages the GET CONFIGURATION request. | |
static void | usb_get_descriptor (void) |
This function manages the GET DESCRIPTOR request. | |
static Bool | usb_get_interface (void) |
This function manages the SETUP_GET_INTERFACE request. | |
static void | usb_get_status (void) |
This function manages the GET STATUS request. | |
void | usb_process_request (void) |
This function reads the SETUP request sent to the default control endpoint and calls the appropriate function. | |
static void | usb_set_address (void) |
This function manages the SET ADDRESS request. | |
static void | usb_set_configuration (void) |
This function manages the SET CONFIGURATION request. | |
static void | usb_set_feature (void) |
This function manages the SET FEATURE request. | |
static void | usb_set_interface (void) |
This function manages the SET INTERFACE request. | |
Variables | |
static U8 | bmRequestType |
U16 | data_to_transfer |
const void * | pbuffer |
volatile U8 | usb_configuration_nb |
volatile Bool | usb_connected |
Public : (Bool) usb_connected usb_connected is set to TRUE when VBus has been detected usb_connected is set to FALSE otherwise. | |
static U8 | usb_interface_status [NB_INTERFACE] |
const S_usb_user_configuration_descriptor | usb_user_configuration_descriptor |
const S_usb_device_descriptor | usb_user_device_descriptor |
void usb_clear_feature | ( | void | ) | [static] |
This function manages the CLEAR FEATURE request.
< keep that order (set StallRq/clear RxSetup) or a OUT request following the SETUP may be acknowledged
< dummy read (MSB of wValue)
Definition at line 553 of file usb_standard_request.c.
References bmRequestType, DEVICE_TYPE, ENDPOINT_TYPE, EP_CONTROL, FEATURE_ENDPOINT_HALT, Get_desc_ep_nbr, INTERFACE_TYPE, Is_usb_endpoint_enabled, Usb_ack_control_in_ready_send, Usb_ack_setup_received_free, Usb_disable_stall_handshake, Usb_enable_stall_handshake, Usb_read_endpoint_data, Usb_reset_data_toggle, and Usb_reset_endpoint.
Referenced by usb_process_request().
00554 { 00555 U8 wValue; 00556 U8 wIndex; 00557 00558 if (bmRequestType == DEVICE_TYPE || bmRequestType == INTERFACE_TYPE) 00559 { 00562 Usb_enable_stall_handshake(EP_CONTROL); 00563 Usb_ack_setup_received_free(); 00564 } 00565 else if (bmRequestType == ENDPOINT_TYPE) 00566 { 00567 wValue = Usb_read_endpoint_data(EP_CONTROL, 8); 00568 00569 if (wValue == FEATURE_ENDPOINT_HALT) 00570 { 00571 Usb_read_endpoint_data(EP_CONTROL, 8); 00572 wIndex = Usb_read_endpoint_data(EP_CONTROL, 8); 00573 wIndex = Get_desc_ep_nbr(wIndex); 00574 00575 if (Is_usb_endpoint_enabled(wIndex)) 00576 { 00577 if (wIndex != EP_CONTROL) 00578 { 00579 Usb_disable_stall_handshake(wIndex); 00580 Usb_reset_endpoint(wIndex); 00581 Usb_reset_data_toggle(wIndex); 00582 } 00583 Usb_ack_setup_received_free(); 00584 Usb_ack_control_in_ready_send(); 00585 } 00586 else 00587 { 00588 Usb_enable_stall_handshake(EP_CONTROL); 00589 Usb_ack_setup_received_free(); 00590 } 00591 } 00592 else 00593 { 00594 Usb_enable_stall_handshake(EP_CONTROL); 00595 Usb_ack_setup_received_free(); 00596 } 00597 } 00598 }
void usb_get_configuration | ( | void | ) | [static] |
This function manages the GET CONFIGURATION request.
The current configuration number is returned.
Definition at line 381 of file usb_standard_request.c.
References EP_CONTROL, Is_usb_control_out_received, Usb_ack_control_in_ready_send, Usb_ack_control_out_received_free, Usb_ack_setup_received_free, usb_configuration_nb, Usb_reset_endpoint_fifo_access, and Usb_write_endpoint_data.
Referenced by usb_process_request().
00382 { 00383 Usb_ack_setup_received_free(); 00384 00385 Usb_reset_endpoint_fifo_access(EP_CONTROL); 00386 Usb_write_endpoint_data(EP_CONTROL, 8, usb_configuration_nb); 00387 Usb_ack_control_in_ready_send(); 00388 00389 while (!Is_usb_control_out_received()); 00390 Usb_ack_control_out_received_free(); 00391 }
void usb_get_descriptor | ( | void | ) | [static] |
This function manages the GET DESCRIPTOR request.
The device descriptor, the configuration descriptor and the device qualifier are supported. All other descriptors must be supported by the usb_user_get_descriptor function. Only 1 configuration is supported.
< sizeof(usb_dev_desc);
< sizeof(usb_conf_desc);
< read wIndex and wLength with a 32-bit access since this access is aligned with a 32-bit boundary from the beginning of the endpoint
< ignore wIndex, keep and format wLength
< clear the setup received flag
< zero length packet condition
< send only requested number of data bytes
< Send data until necessary
Definition at line 245 of file usb_standard_request.c.
References CONFIGURATION_DESCRIPTOR, data_to_transfer, DEVICE_DESCRIPTOR, DEVICE_QUALIFIER_DESCRIPTOR, EP_CONTROL, EP_CONTROL_LENGTH, Is_usb_control_in_ready, Is_usb_control_out_received, Is_usb_full_speed_mode, Is_usb_nak_out, OTHER_SPEED_CONFIGURATION_DESCRIPTOR, pbuffer, Usb_ack_control_in_ready_send, Usb_ack_control_out_received_free, Usb_ack_nak_out, Usb_ack_setup_received_free, Usb_enable_stall_handshake, usb_format_usb_to_mcu_data, Usb_get_conf_desc_length, Usb_get_conf_desc_pointer, Usb_get_dev_desc_length, Usb_get_dev_desc_pointer, Usb_read_endpoint_data, Usb_reset_endpoint_fifo_access, usb_user_get_descriptor(), and usb_write_ep_txpacket().
Referenced by usb_process_request().
00246 { 00247 Bool zlp; 00248 U16 wLength; 00249 U8 descriptor_type; 00250 U8 string_type; 00251 Union32 temp; 00252 #if (USB_HIGH_SPEED_SUPPORT==ENABLED) 00253 Bool b_first_data = TRUE; 00254 #endif 00255 00256 zlp = FALSE; /* no zero length packet */ 00257 string_type = Usb_read_endpoint_data(EP_CONTROL, 8); /* read LSB of wValue */ 00258 descriptor_type = Usb_read_endpoint_data(EP_CONTROL, 8); /* read MSB of wValue */ 00259 00260 switch (descriptor_type) 00261 { 00262 case DEVICE_DESCRIPTOR: 00263 data_to_transfer = Usb_get_dev_desc_length(); 00264 pbuffer = Usb_get_dev_desc_pointer(); 00265 break; 00266 00267 #if (USB_HIGH_SPEED_SUPPORT==DISABLED) 00268 case CONFIGURATION_DESCRIPTOR: 00269 data_to_transfer = Usb_get_conf_desc_length(); 00270 pbuffer = Usb_get_conf_desc_pointer(); 00271 break; 00272 00273 #else 00274 case CONFIGURATION_DESCRIPTOR: 00275 if( Is_usb_full_speed_mode() ) 00276 { 00277 data_to_transfer = Usb_get_conf_desc_fs_length(); 00278 pbuffer = Usb_get_conf_desc_fs_pointer(); 00279 }else{ 00280 data_to_transfer = Usb_get_conf_desc_hs_length(); 00281 pbuffer = Usb_get_conf_desc_hs_pointer(); 00282 } 00283 break; 00284 00285 case OTHER_SPEED_CONFIGURATION_DESCRIPTOR: 00286 if( !Is_usb_full_speed_mode() ) 00287 { 00288 data_to_transfer = Usb_get_conf_desc_fs_length(); 00289 pbuffer = Usb_get_conf_desc_fs_pointer(); 00290 }else{ 00291 data_to_transfer = Usb_get_conf_desc_hs_length(); 00292 pbuffer = Usb_get_conf_desc_hs_pointer(); 00293 } 00294 break; 00295 00296 case DEVICE_QUALIFIER_DESCRIPTOR: 00297 data_to_transfer = Usb_get_qualifier_desc_length(); 00298 pbuffer = Usb_get_qualifier_desc_pointer(); 00299 break; 00300 00301 #endif 00302 00303 default: 00304 if (!usb_user_get_descriptor(descriptor_type, string_type)) 00305 { 00306 Usb_enable_stall_handshake(EP_CONTROL); 00307 Usb_ack_setup_received_free(); 00308 return; 00309 } 00310 break; 00311 } 00312 00313 temp.u32 = Usb_read_endpoint_data(EP_CONTROL, 32); 00314 00315 00316 wLength = usb_format_usb_to_mcu_data(16, temp.u16[1]); 00317 Usb_ack_setup_received_free(); 00318 00319 if (wLength > data_to_transfer) 00320 { 00321 zlp = !(data_to_transfer % EP_CONTROL_LENGTH); 00322 } 00323 else 00324 { 00325 // No need to test ZLP sending since we send the exact number of bytes as 00326 // expected by the host. 00327 data_to_transfer = wLength; 00328 } 00329 00330 Usb_ack_nak_out(EP_CONTROL); 00331 00332 while (data_to_transfer && !Is_usb_nak_out(EP_CONTROL)) 00333 { 00334 while (!Is_usb_control_in_ready() && !Is_usb_nak_out(EP_CONTROL)); 00335 00336 if (Is_usb_nak_out(EP_CONTROL)) 00337 break; // don't clear the flag now, it will be cleared after 00338 00339 Usb_reset_endpoint_fifo_access(EP_CONTROL); 00340 00341 #if (USB_HIGH_SPEED_SUPPORT==ENABLED) // To support other descriptors like OTHER_SPEED_CONFIGURATION_DESCRIPTOR 00342 if( b_first_data ) { 00343 b_first_data = FALSE; 00344 if( 0!= data_to_transfer ) { 00345 usb_write_ep_txpacket(EP_CONTROL, pbuffer, 1, &pbuffer); 00346 data_to_transfer--; 00347 } 00348 if( 0!= data_to_transfer ) { 00349 usb_write_ep_txpacket(EP_CONTROL, &descriptor_type, 1, NULL); 00350 pbuffer = ((const U8*)pbuffer)+1; 00351 data_to_transfer--; 00352 } 00353 } 00354 #endif 00355 if( 0!= data_to_transfer ) { 00356 data_to_transfer = usb_write_ep_txpacket(EP_CONTROL, pbuffer, 00357 data_to_transfer, &pbuffer); 00358 } 00359 if (Is_usb_nak_out(EP_CONTROL)) 00360 break; 00361 00362 Usb_ack_control_in_ready_send(); 00363 } 00364 00365 if (zlp && !Is_usb_nak_out(EP_CONTROL)) 00366 { 00367 while (!Is_usb_control_in_ready()); 00368 Usb_ack_control_in_ready_send(); 00369 } 00370 00371 while (!Is_usb_nak_out(EP_CONTROL)); 00372 Usb_ack_nak_out(EP_CONTROL); 00373 while (!Is_usb_control_out_received()); 00374 Usb_ack_control_out_received_free(); 00375 }
Bool usb_get_interface | ( | void | ) | [static] |
This function manages the SETUP_GET_INTERFACE request.
Definition at line 603 of file usb_standard_request.c.
References EP_CONTROL, Is_usb_control_out_received, Usb_ack_control_in_ready_send, Usb_ack_control_out_received_free, Usb_ack_setup_received_free, usb_format_usb_to_mcu_data, usb_interface_status, Usb_read_endpoint_data, Usb_reset_endpoint_fifo_access, and Usb_write_endpoint_data.
Referenced by usb_process_request().
00604 { 00605 U16 wInterface; 00606 U16 wValue; 00607 00608 // Read wValue 00609 wValue = usb_format_usb_to_mcu_data(16, Usb_read_endpoint_data(EP_CONTROL, 16)); 00610 // wValue = Alternate Setting 00611 // wIndex = Interface 00612 wInterface=usb_format_usb_to_mcu_data(16, Usb_read_endpoint_data(EP_CONTROL, 16)); 00613 if(0!=wValue) 00614 return FALSE; 00615 Usb_ack_setup_received_free(); 00616 00617 Usb_reset_endpoint_fifo_access(EP_CONTROL); 00618 Usb_write_endpoint_data(EP_CONTROL, 8, usb_interface_status[wInterface] ); 00619 Usb_ack_control_in_ready_send(); 00620 00621 while( !Is_usb_control_out_received() ); 00622 Usb_ack_control_out_received_free(); 00623 return TRUE; 00624 }
void usb_get_status | ( | void | ) | [static] |
This function manages the GET STATUS request.
The device, interface or endpoint status is returned.
< dummy read (wValue)
Definition at line 397 of file usb_standard_request.c.
References bmRequestType, DEVICE_STATUS, EP_CONTROL, Get_desc_ep_nbr, INTERFACE_STATUS, Is_usb_control_out_received, Is_usb_endpoint_stall_requested, REQUEST_DEVICE_STATUS, REQUEST_ENDPOINT_STATUS, REQUEST_INTERFACE_STATUS, Usb_ack_control_in_ready_send, Usb_ack_control_out_received_free, Usb_ack_setup_received_free, Usb_enable_stall_handshake, Usb_read_endpoint_data, Usb_reset_endpoint_fifo_access, and Usb_write_endpoint_data.
Referenced by usb_process_request().
00398 { 00399 U8 wIndex; 00400 00401 switch (bmRequestType) 00402 { 00403 case REQUEST_DEVICE_STATUS: 00404 Usb_ack_setup_received_free(); 00405 Usb_reset_endpoint_fifo_access(EP_CONTROL); 00406 Usb_write_endpoint_data(EP_CONTROL, 8, DEVICE_STATUS); 00407 break; 00408 00409 case REQUEST_INTERFACE_STATUS: 00410 Usb_ack_setup_received_free(); 00411 Usb_reset_endpoint_fifo_access(EP_CONTROL); 00412 Usb_write_endpoint_data(EP_CONTROL, 8, INTERFACE_STATUS); 00413 break; 00414 00415 case REQUEST_ENDPOINT_STATUS: 00416 Usb_read_endpoint_data(EP_CONTROL, 16); 00417 wIndex = Usb_read_endpoint_data(EP_CONTROL, 8); 00418 wIndex = Get_desc_ep_nbr(wIndex); 00419 Usb_ack_setup_received_free(); 00420 Usb_reset_endpoint_fifo_access(EP_CONTROL); 00421 Usb_write_endpoint_data(EP_CONTROL, 8, Is_usb_endpoint_stall_requested(wIndex) ); 00422 break; 00423 00424 default: 00425 Usb_enable_stall_handshake(EP_CONTROL); 00426 Usb_ack_setup_received_free(); 00427 return; 00428 } 00429 00430 Usb_write_endpoint_data(EP_CONTROL, 8, 0x00); 00431 Usb_ack_control_in_ready_send(); 00432 00433 while (!Is_usb_control_out_received()); 00434 Usb_ack_control_out_received_free(); 00435 }
void usb_set_address | ( | void | ) | [static] |
This function manages the SET ADDRESS request.
When complete, the device will filter the requests using the new address.
< send a ZLP for STATUS phase
< waits for status phase done before using the new address
Definition at line 194 of file usb_standard_request.c.
References EP_CONTROL, Is_usb_control_in_ready, Usb_ack_control_in_ready_send, Usb_ack_setup_received_free, Usb_configure_address, Usb_enable_address, and Usb_read_endpoint_data.
Referenced by usb_process_request().
00195 { 00196 U8 addr = Usb_read_endpoint_data(EP_CONTROL, 8); 00197 Usb_configure_address(addr); 00198 00199 Usb_ack_setup_received_free(); 00200 00201 Usb_ack_control_in_ready_send(); 00202 while (!Is_usb_control_in_ready()); 00203 00204 Usb_enable_address(); 00205 }
void usb_set_configuration | ( | void | ) | [static] |
This function manages the SET CONFIGURATION request.
If the selected configuration is valid, this function call the usb_user_endpoint_init() function that will configure the endpoints following the configuration number.
< endpoint configuration
< send a ZLP for STATUS phase
< keep that order (set StallRq/clear RxSetup) or a OUT request following the SETUP may be acknowledged
Definition at line 213 of file usb_standard_request.c.
References EP_CONTROL, NB_CONFIGURATION, NB_INTERFACE, Usb_ack_control_in_ready_send, Usb_ack_setup_received_free, usb_configuration_nb, Usb_enable_stall_handshake, usb_interface_status, Usb_read_endpoint_data, Usb_set_configuration_action, and usb_user_endpoint_init().
Referenced by usb_process_request().
00214 { 00215 U8 configuration_number = Usb_read_endpoint_data(EP_CONTROL, 8); 00216 U8 u8_i; 00217 00218 if (configuration_number <= NB_CONFIGURATION) 00219 { 00220 Usb_ack_setup_received_free(); 00221 usb_configuration_nb = configuration_number; 00222 for( u8_i=0; u8_i<NB_INTERFACE; u8_i++) usb_interface_status[u8_i]=0; 00223 00224 usb_user_endpoint_init(usb_configuration_nb); 00225 Usb_set_configuration_action(); 00226 00227 Usb_ack_control_in_ready_send(); 00228 } 00229 else 00230 { 00233 Usb_enable_stall_handshake(EP_CONTROL); 00234 Usb_ack_setup_received_free(); 00235 } 00236 }
void usb_set_feature | ( | void | ) | [static] |
This function manages the SET FEATURE request.
The USB test modes are supported by this function.
Definition at line 441 of file usb_standard_request.c.
References AVR32_USBB_udcon, bmRequestType, DEVICE_TYPE, DIRECTION_IN, ENDPOINT_TYPE, EP_CONTROL, FEATURE_DEVICE_REMOTE_WAKEUP, FEATURE_ENDPOINT_HALT, FEATURE_TEST_MODE, Get_desc_ep_nbr, Is_usb_control_in_ready, Is_usb_endpoint_enabled, SINGLE_BANK, TEST_FORCE_ENABLE, TEST_J, TEST_K, TEST_PACKET, TEST_SE0_NAK, TYPE_BULK, Usb_ack_control_in_ready_send, Usb_ack_setup_received_free, Usb_configure_endpoint, Usb_disable_endpoint, Usb_enable_stall_handshake, usb_format_usb_to_mcu_data, Usb_read_endpoint_data, Usb_reset_endpoint, Usb_send_in, Usb_unallocate_memory, and usb_write_ep_txpacket().
Referenced by usb_process_request().
00442 { 00443 U16 wValue = usb_format_usb_to_mcu_data(16, Usb_read_endpoint_data(EP_CONTROL, 16)); 00444 U16 wIndex = usb_format_usb_to_mcu_data(16, Usb_read_endpoint_data(EP_CONTROL, 16)); 00445 U16 wLength = usb_format_usb_to_mcu_data(16, Usb_read_endpoint_data(EP_CONTROL, 16)); 00446 00447 if (wLength) 00448 goto unsupported_request; 00449 00450 switch (wValue) 00451 { 00452 case FEATURE_ENDPOINT_HALT: 00453 wIndex = Get_desc_ep_nbr(wIndex); // clear direction flag 00454 if (bmRequestType != ENDPOINT_TYPE || 00455 wIndex == EP_CONTROL || 00456 !Is_usb_endpoint_enabled(wIndex)) 00457 goto unsupported_request; 00458 00459 Usb_enable_stall_handshake(wIndex); 00460 Usb_ack_setup_received_free(); 00461 Usb_ack_control_in_ready_send(); 00462 break; 00463 00464 #if (USB_HIGH_SPEED_SUPPORT==ENABLED) 00465 case FEATURE_TEST_MODE: 00466 if (bmRequestType != DEVICE_TYPE || 00467 wIndex & 0x00FF) 00468 goto unsupported_request; 00469 00470 switch (wIndex >> 8) 00471 { 00472 case TEST_J: 00473 Usb_ack_setup_received_free(); 00474 Usb_ack_control_in_ready_send(); 00475 while (!Is_usb_control_in_ready()); 00476 Wr_bitfield(AVR32_USBB_udcon, AVR32_USBB_UDCON_SPDCONF_MASK, 2); 00477 Set_bits(AVR32_USBB_udcon, AVR32_USBB_UDCON_TSTJ_MASK); 00478 break; 00479 00480 case TEST_K: 00481 Usb_ack_setup_received_free(); 00482 Usb_ack_control_in_ready_send(); 00483 while (!Is_usb_control_in_ready()); 00484 Wr_bitfield(AVR32_USBB_udcon, AVR32_USBB_UDCON_SPDCONF_MASK, 2); 00485 Set_bits(AVR32_USBB_udcon, AVR32_USBB_UDCON_TSTK_MASK); 00486 break; 00487 00488 case TEST_SE0_NAK: 00489 Usb_ack_setup_received_free(); 00490 Usb_ack_control_in_ready_send(); 00491 while (!Is_usb_control_in_ready()); 00492 Wr_bitfield(AVR32_USBB_udcon, AVR32_USBB_UDCON_SPDCONF_MASK, 2); 00493 break; 00494 00495 case TEST_PACKET: 00496 { 00497 static const U8 test_packet[] = 00498 { 00499 // 00000000 * 9 00500 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00501 // 01010101 * 8 00502 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 00503 // 01110111 * 8 00504 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 00505 // 0, {111111S * 15}, 111111 00506 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 00507 // S, 111111S, {0111111S * 7} 00508 0x7F, 0xBF, 0xDF, 0xEF, 0xF7, 0xFB, 0xFD, 00509 // 00111111, {S0111111 * 9}, S0 00510 0xFC, 0x7E, 0xBF, 0xDF, 0xEF, 0xF7, 0xFB, 0xFD, 0x7E 00511 }; 00512 00513 Usb_ack_setup_received_free(); 00514 Usb_ack_control_in_ready_send(); 00515 while (!Is_usb_control_in_ready()); 00516 Wr_bitfield(AVR32_USBB_udcon, AVR32_USBB_UDCON_SPDCONF_MASK, 2); 00517 Usb_disable_endpoint(EP_CONTROL); 00518 Usb_unallocate_memory(EP_CONTROL); 00519 (void)Usb_configure_endpoint(EP_CONTROL, 00520 TYPE_BULK, 00521 DIRECTION_IN, 00522 64, 00523 SINGLE_BANK); 00524 Usb_reset_endpoint(EP_CONTROL); 00525 Set_bits(AVR32_USBB_udcon, AVR32_USBB_UDCON_TSTPCKT_MASK); 00526 usb_write_ep_txpacket(EP_CONTROL, &test_packet, sizeof(test_packet), NULL); 00527 Usb_send_in(EP_CONTROL); 00528 } 00529 break; 00530 00531 case TEST_FORCE_ENABLE: // Only for downstream facing hub ports 00532 default: 00533 goto unsupported_request; 00534 } 00535 break; 00536 #endif 00537 00538 case FEATURE_DEVICE_REMOTE_WAKEUP: 00539 default: 00540 goto unsupported_request; 00541 } 00542 00543 return; 00544 00545 unsupported_request: 00546 Usb_enable_stall_handshake(EP_CONTROL); 00547 Usb_ack_setup_received_free(); 00548 }
void usb_set_interface | ( | void | ) | [static] |
This function manages the SET INTERFACE request.
< sizeof(usb_conf_desc_fs);
< sizeof(usb_conf_desc_hs);
Definition at line 629 of file usb_standard_request.c.
References CONFIGURATION_DESCRIPTOR, data_to_transfer, ENDPOINT_DESCRIPTOR, EP_CONTROL, INTERFACE_DESCRIPTOR, Is_usb_control_in_ready, Is_usb_full_speed_mode, MSK_EP_DIR, pbuffer, Usb_ack_control_in_ready_send, Usb_ack_setup_received_free, usb_configuration_nb, Usb_disable_stall_handshake, Usb_enable_stall_handshake, usb_format_usb_to_mcu_data, Usb_get_conf_desc_length, Usb_get_conf_desc_pointer, usb_interface_status, Usb_read_endpoint_data, Usb_reset_data_toggle, and Usb_reset_endpoint.
Referenced by usb_process_request().
00630 { 00631 U8 u8_i; 00632 00633 // wValue = Alternate Setting 00634 // wIndex = Interface 00635 U16 wValue = usb_format_usb_to_mcu_data(16, Usb_read_endpoint_data(EP_CONTROL, 16)); 00636 U16 wIndex = usb_format_usb_to_mcu_data(16, Usb_read_endpoint_data(EP_CONTROL, 16)); 00637 Usb_ack_setup_received_free(); 00638 00639 // Get descriptor 00640 #if (USB_HIGH_SPEED_SUPPORT==ENABLED) 00641 if( Is_usb_full_speed_mode() ) 00642 { 00643 data_to_transfer = Usb_get_conf_desc_fs_length(); 00644 pbuffer = Usb_get_conf_desc_fs_pointer(); 00645 }else{ 00646 data_to_transfer = Usb_get_conf_desc_hs_length(); 00647 pbuffer = Usb_get_conf_desc_hs_pointer(); 00648 } 00649 #else 00650 data_to_transfer = Usb_get_conf_desc_length(); 00651 pbuffer = Usb_get_conf_desc_pointer(); 00652 #endif 00653 00654 //** Scan descriptor 00655 00656 //* Find configuration selected 00657 if( usb_configuration_nb == 0 ) 00658 { 00659 // No configuration selected then no interface enable 00660 Usb_enable_stall_handshake(EP_CONTROL); 00661 Usb_ack_setup_received_free(); 00662 return; 00663 } 00664 u8_i = usb_configuration_nb; 00665 while( u8_i != 0 ) 00666 { 00667 if( CONFIGURATION_DESCRIPTOR != ((S_usb_configuration_descriptor*)pbuffer)->bDescriptorType ) 00668 { 00669 data_to_transfer -= ((S_usb_configuration_descriptor*)pbuffer)->bLength; 00670 pbuffer = (U8*)pbuffer + ((S_usb_configuration_descriptor*)pbuffer)->bLength; 00671 continue; 00672 } 00673 u8_i--; 00674 if( u8_i != 0 ) 00675 { 00676 data_to_transfer -= ((S_usb_configuration_descriptor*)pbuffer)->wTotalLength; 00677 pbuffer = (U8*)pbuffer + ((S_usb_configuration_descriptor*)pbuffer)->wTotalLength; 00678 } 00679 } 00680 00681 // Find interface selected 00682 if( wIndex >= ((S_usb_configuration_descriptor*)pbuffer)->bNumInterfaces ) 00683 { 00684 // Interface number unknow 00685 Usb_enable_stall_handshake(EP_CONTROL); 00686 Usb_ack_setup_received_free(); 00687 return; 00688 } 00689 while( 1 ) 00690 { 00691 if( data_to_transfer <= ((S_usb_interface_descriptor*)pbuffer)->bLength ) 00692 { 00693 // Interface unknow 00694 Usb_enable_stall_handshake(EP_CONTROL); 00695 Usb_ack_setup_received_free(); 00696 return; 00697 } 00698 data_to_transfer -= ((S_usb_interface_descriptor*)pbuffer)->bLength; 00699 pbuffer = (U8*)pbuffer + ((S_usb_interface_descriptor*)pbuffer)->bLength; 00700 if( INTERFACE_DESCRIPTOR != ((S_usb_interface_descriptor*)pbuffer)->bDescriptorType ) 00701 continue; 00702 if( wIndex != ((S_usb_interface_descriptor*)pbuffer)->bInterfaceNumber ) 00703 continue; 00704 if( wValue != ((S_usb_interface_descriptor*)pbuffer)->bAlternateSetting ) 00705 continue; 00706 usb_interface_status[wIndex] = wValue; 00707 break; 00708 } 00709 00710 //* Find endpoints of interface and reset it 00711 while( 1 ) 00712 { 00713 if( data_to_transfer <= ((S_usb_endpoint_descriptor*)pbuffer)->bLength ) 00714 break; // End of interface 00715 data_to_transfer -= ((S_usb_endpoint_descriptor*)pbuffer)->bLength; 00716 pbuffer = (U8*)pbuffer + ((S_usb_endpoint_descriptor*)pbuffer)->bLength; 00717 if( INTERFACE_DESCRIPTOR == ((S_usb_endpoint_descriptor*)pbuffer)->bDescriptorType ) 00718 break; // End of interface 00719 if( ENDPOINT_DESCRIPTOR == ((S_usb_endpoint_descriptor*)pbuffer)->bDescriptorType ) 00720 { 00721 // Reset endpoint 00722 u8_i = ((S_usb_endpoint_descriptor*)pbuffer)->bEndpointAddress & (~MSK_EP_DIR); 00723 Usb_disable_stall_handshake(u8_i); 00724 Usb_reset_endpoint(u8_i); 00725 Usb_reset_data_toggle(u8_i); 00726 } 00727 } 00728 00729 // send a ZLP for STATUS phase 00730 Usb_ack_control_in_ready_send(); 00731 while (!Is_usb_control_in_ready()); 00732 }
U8 bmRequestType [static] |
Definition at line 91 of file usb_standard_request.c.
Referenced by usb_clear_feature(), usb_get_status(), usb_process_request(), and usb_set_feature().
U16 data_to_transfer |
Definition at line 90 of file usb_standard_request.c.
Referenced by usb_get_descriptor(), usb_set_interface(), and usb_user_get_descriptor().
const void* pbuffer |
Definition at line 89 of file usb_standard_request.c.
Referenced by usb_get_descriptor(), usb_set_interface(), and usb_user_get_descriptor().
volatile Bool usb_connected |
Public : (Bool) usb_connected usb_connected is set to TRUE when VBus has been detected usb_connected is set to FALSE otherwise.
Definition at line 80 of file usb_device_task.c.
U8 usb_interface_status[NB_INTERFACE] [static] |
Definition at line 96 of file usb_standard_request.c.
Referenced by usb_get_interface(), usb_set_configuration(), and usb_set_interface().