#include "config.h"
#include "conf_usb.h"
#include "lib_mcu\usb\usb_drv.h"
#include "usb_descriptors.h"
#include "modules\usb\device_chap9\usb_standard_request.h"
#include "usb_specific_request.h"
Include dependency graph for usb_standard_request.c:

Go to the source code of this file.
Functions | |
| static void | usb_get_descriptor (void) |
| usb_get_descriptor. | |
| static void | usb_set_address (void) |
| usb_set_address. | |
| static void | usb_set_configuration (void) |
| usb_set_configuration. | |
| static void | usb_clear_feature (void) |
| usb_clear_feature. | |
| static void | usb_set_feature (void) |
| usb_set_feature. | |
| static void | usb_get_status (void) |
| usb_get_status. | |
| static void | usb_get_configuration (void) |
| usb_get_configuration. | |
| static void | usb_get_interface (void) |
| usb_get_interface. | |
| static void | usb_set_interface (void) |
| usb_set_interface. | |
| void | usb_process_request (void) |
| This function reads the SETUP request sent to the default control endpoint and calls the appropriate function. | |
Variables | |
| static bit | zlp |
| static U8 | endpoint_status [1] |
| U8 code * | pbuffer |
| U8 | data_to_transfer |
| U16 | wInterface |
| static U8 | bmRequestType |
| U8 | usb_configuration_nb |
| Public : (U8) usb_configuration_nb Store the number of the USB configuration used by the USB device when its value is different from zero, it means the device mode is enumerated Used with USB_DEVICE_FEATURE == ENABLED only /. | |
| bit | usb_connected |
| Public : (bit) usb_connected usb_connected is set to TRUE when VBUS has been detected usb_connected is set to FALSE otherwise /. | |
| code S_usb_device_descriptor | usb_user_device_descriptor |
| code S_usb_user_configuration_descriptor | usb_user_configuration_descriptor |
Copyright (c) 2004 Atmel.
Use of this program is subject to Atmel's End User License Agreement. Please read file license.txt for copyright notice.
This file contains the USB endpoint 0 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.
| void usb_get_descriptor | ( | void | ) | [static] |
usb_get_descriptor.
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.
| none |
< sizeof (usb_user_device_descriptor);
< sizeof (usb_user_configuration_descriptor);
< don't care of wIndex field
< read wLength
< clear the receive setup flag
< send only requested number of data
< Send data until necessary
< Check endpoint 0 size
Definition at line 250 of file usb_standard_request.c.
References CONFIGURATION_DESCRIPTOR, data_to_transfer, DEVICE_DESCRIPTOR, EP_CONTROL_LENGTH, FALSE, Is_usb_nak_out_sent, Is_usb_read_control_enabled, LSB, MSB, pbuffer, RXOUTI, TRUE, Usb_ack_nak_out, Usb_ack_receive_setup, Usb_enable_stall_handshake, Usb_get_conf_desc_length, Usb_get_conf_desc_pointer, Usb_get_dev_desc_length, Usb_get_dev_desc_pointer, Usb_read_byte, Usb_send_control_in, usb_user_get_descriptor(), Usb_write_byte, and zlp.
Referenced by usb_process_request().
00251 { 00252 U16 wLength; 00253 U8 descriptor_type ; 00254 U8 string_type; 00255 U8 dummy; 00256 U8 nb_byte; 00257 00258 zlp = FALSE; /* no zero length packet */ 00259 string_type = Usb_read_byte(); /* read LSB of wValue */ 00260 descriptor_type = Usb_read_byte(); /* read MSB of wValue */ 00261 00262 switch (descriptor_type) 00263 { 00264 case DEVICE_DESCRIPTOR: 00265 data_to_transfer = Usb_get_dev_desc_length(); 00266 pbuffer = Usb_get_dev_desc_pointer(); 00267 break; 00268 case CONFIGURATION_DESCRIPTOR: 00269 data_to_transfer = Usb_get_conf_desc_length(); 00270 pbuffer = Usb_get_conf_desc_pointer(); 00271 break; 00272 default: 00273 if( usb_user_get_descriptor(descriptor_type, string_type)==FALSE ) 00274 { 00275 Usb_enable_stall_handshake(); 00276 Usb_ack_receive_setup(); 00277 return; 00278 } 00279 break; 00280 } 00281 00282 dummy = Usb_read_byte(); 00283 dummy = Usb_read_byte(); 00284 LSB(wLength) = Usb_read_byte(); 00285 MSB(wLength) = Usb_read_byte(); 00286 Usb_ack_receive_setup() ; 00287 00288 if (wLength > data_to_transfer) 00289 { 00290 if ((data_to_transfer % EP_CONTROL_LENGTH) == 0) { zlp = TRUE; } 00291 else { zlp = FALSE; } 00292 } 00293 else 00294 { 00295 data_to_transfer = (U8)wLength; 00296 } 00297 00298 Usb_ack_nak_out(); 00299 00300 while((data_to_transfer != 0) && (!Is_usb_nak_out_sent())) 00301 { 00302 while(!Is_usb_read_control_enabled()) 00303 { 00304 if (Is_usb_nak_out_sent()) 00305 break; // don't clear the flag now, it will be cleared after 00306 } 00307 00308 nb_byte=0; 00309 while(data_to_transfer != 0) 00310 { 00311 if(nb_byte++==EP_CONTROL_LENGTH) 00312 { 00313 break; 00314 } 00315 #ifndef AVRGCC 00316 Usb_write_byte(*pbuffer++); 00317 #else // AVRGCC does not support point to PGM space 00318 #warning with avrgcc assumes devices descriptors are stored in the lower 64Kbytes of on-chip flash memory 00319 Usb_write_byte(pgm_read_byte_near((unsigned int)pbuffer++)); 00320 #endif 00321 data_to_transfer --; 00322 } 00323 00324 if (Is_usb_nak_out_sent()) 00325 break; 00326 else 00327 Usb_send_control_in(); 00328 } 00329 00330 if((zlp == TRUE) && (!Is_usb_nak_out_sent())) 00331 { 00332 while(!Is_usb_read_control_enabled()); 00333 Usb_send_control_in(); 00334 } 00335 00336 while (!(Is_usb_nak_out_sent())); 00337 Usb_ack_nak_out(); // clear NAKOUTI 00338 UEINTX &= ~(1<<RXOUTI); // clear RXOUTI 00339 }
Here is the call graph for this function:

| void usb_set_address | ( | void | ) | [static] |
usb_set_address.
This function manages the SET ADDRESS request. When complete, the device will filter the requests using the new address.
| none |
< send a ZLP for STATUS phase
< waits for status phase done before using the new address
Definition at line 183 of file usb_standard_request.c.
References Is_usb_in_ready, Usb_ack_receive_setup, Usb_configure_address, Usb_enable_address, Usb_read_byte, and Usb_send_control_in.
Referenced by usb_process_request().
00184 { 00185 Usb_configure_address(Usb_read_byte()); 00186 00187 Usb_ack_receive_setup(); 00188 00189 Usb_send_control_in(); 00190 while(!Is_usb_in_ready()); 00191 00192 Usb_enable_address(); 00193 }
| void usb_set_configuration | ( | void | ) | [static] |
usb_set_configuration.
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.
| none |
< keep that order (set StallRq/clear RxSetup) or a OUT request following the SETUP may be acknowledged
< send a ZLP for STATUS phase
< endpoint configuration
Definition at line 209 of file usb_standard_request.c.
References NB_CONFIGURATION, Usb_ack_receive_setup, usb_configuration_nb, Usb_enable_stall_handshake, Usb_read_byte, Usb_send_control_in, Usb_set_configuration_action, and usb_user_endpoint_init().
Referenced by usb_process_request().
00210 { 00211 U8 configuration_number; 00212 00213 configuration_number = Usb_read_byte(); 00214 00215 if (configuration_number <= NB_CONFIGURATION) 00216 { 00217 Usb_ack_receive_setup(); 00218 usb_configuration_nb = configuration_number; 00219 } 00220 else 00221 { 00224 Usb_enable_stall_handshake(); 00225 Usb_ack_receive_setup(); 00226 return; 00227 } 00228 00229 Usb_send_control_in(); 00230 00231 usb_user_endpoint_init(usb_configuration_nb); 00232 Usb_set_configuration_action(); 00233 }
Here is the call graph for this function:

| void usb_clear_feature | ( | void | ) | [static] |
usb_clear_feature.
This function manages the SET FEATURE request.
| none |
< keep that order (set StallRq/clear RxSetup) or a OUT request following the SETUP may be acknowledged
< keep that order (set StallRq/clear RxSetup) or a OUT request following the SETUP may be acknowledged
< dummy read
Definition at line 563 of file usb_standard_request.c.
References bmRequestType, endpoint_status, ENDPOINT_TYPE, EP_CONTROL, FEATURE_ENDPOINT_HALT, INTERFACE_TYPE, Is_usb_endpoint_enabled, MSK_EP_DIR, Usb_ack_receive_setup, Usb_disable_stall_handshake, Usb_enable_stall_handshake, Usb_read_byte, Usb_reset_data_toggle, Usb_reset_endpoint, Usb_select_endpoint, Usb_send_control_in, and ZERO_TYPE.
Referenced by usb_process_request().
00564 { 00565 U8 wValue; 00566 U8 wIndex; 00567 U8 dummy; 00568 00569 if (bmRequestType == ZERO_TYPE) 00570 { 00573 Usb_enable_stall_handshake(); 00574 Usb_ack_receive_setup(); 00575 return; 00576 } 00577 else if (bmRequestType == INTERFACE_TYPE) 00578 { 00581 Usb_enable_stall_handshake(); 00582 Usb_ack_receive_setup(); 00583 return; 00584 } 00585 else if (bmRequestType == ENDPOINT_TYPE) 00586 { 00587 wValue = Usb_read_byte(); 00588 dummy = Usb_read_byte(); 00589 00590 if (wValue == FEATURE_ENDPOINT_HALT) 00591 { 00592 wIndex = (Usb_read_byte() & MSK_EP_DIR); 00593 00594 Usb_select_endpoint(wIndex); 00595 if(Is_usb_endpoint_enabled()) 00596 { 00597 if(wIndex != EP_CONTROL) 00598 { 00599 Usb_disable_stall_handshake(); 00600 Usb_reset_endpoint(wIndex); 00601 Usb_reset_data_toggle(); 00602 } 00603 Usb_select_endpoint(EP_CONTROL); 00604 endpoint_status[wIndex] = 0x00; 00605 Usb_ack_receive_setup(); 00606 Usb_send_control_in(); 00607 } 00608 else 00609 { 00610 Usb_select_endpoint(EP_CONTROL); 00611 Usb_enable_stall_handshake(); 00612 Usb_ack_receive_setup(); 00613 return; 00614 } 00615 } 00616 else 00617 { 00618 Usb_enable_stall_handshake(); 00619 Usb_ack_receive_setup(); 00620 return; 00621 } 00622 } 00623 }
| void usb_set_feature | ( | void | ) | [static] |
usb_set_feature.
This function manages the SET FEATURE request. The USB test modes are supported by this function.
| none |
< keep that order (set StallRq/clear RxSetup) or a OUT request following the SETUP may be acknowledged
< dummy read
Definition at line 423 of file usb_standard_request.c.
References BDEV_HNP_NB_RETRY, bmRequestType, CONF_ATTRIBUTES, DISABLED, ENABLED, endpoint_status, ENDPOINT_TYPE, EP_CONTROL, FEATURE_ENDPOINT_HALT, HNP_SUPPORT, INTERFACE_TYPE, Is_usb_endpoint_enabled, MSK_EP_DIR, OTG_A_ALT_HNP_SUPPORT, OTG_A_HNP_SUPPORT, OTG_B_HNP_ENABLE, OTG_BMATTRIBUTES, otg_device_nb_hnp_retry, otg_features_supported, remote_wakeup_feature, Usb_ack_receive_setup, USB_CONFIG_REMOTEWAKEUP, Usb_enable_stall_handshake, USB_OTG_FEATURE, Usb_read_byte, USB_REMOTE_WAKEUP, Usb_select_endpoint, Usb_send_control_in, and ZERO_TYPE.
Referenced by usb_process_request().
00424 { 00425 U8 wValue; 00426 U8 wIndex; 00427 U8 dummy; 00428 00429 switch (bmRequestType) 00430 { 00431 case ZERO_TYPE: 00432 wValue = Usb_read_byte(); 00433 switch (wValue) 00434 { 00435 case USB_REMOTE_WAKEUP: 00436 if ((CONF_ATTRIBUTES&USB_CONFIG_REMOTEWAKEUP) == USB_CONFIG_REMOTEWAKEUP) // enabled in descriptors ? 00437 { 00438 remote_wakeup_feature = ENABLED; 00439 Usb_ack_receive_setup(); 00440 Usb_send_control_in(); 00441 } 00442 else 00443 { 00444 Usb_enable_stall_handshake(); 00445 Usb_ack_receive_setup(); 00446 } 00447 break; 00448 00449 #if (USB_OTG_FEATURE == ENABLED) 00450 case OTG_B_HNP_ENABLE: 00451 if (((OTG_BMATTRIBUTES&HNP_SUPPORT) == 0) || (USB_OTG_FEATURE == DISABLED)) // see usb_descriptors.h 00452 { 00453 Usb_enable_stall_handshake(); 00454 Usb_ack_receive_setup(); 00455 } 00456 else 00457 { 00458 otg_features_supported |= OTG_B_HNP_ENABLE; 00459 otg_device_nb_hnp_retry = BDEV_HNP_NB_RETRY; 00460 Usb_ack_receive_setup(); 00461 Usb_send_control_in(); 00462 } 00463 break; 00464 00465 case OTG_A_HNP_SUPPORT: 00466 if (((OTG_BMATTRIBUTES&HNP_SUPPORT) == 0) || (USB_OTG_FEATURE == DISABLED)) 00467 { 00468 Usb_enable_stall_handshake(); 00469 Usb_ack_receive_setup(); 00470 } 00471 else 00472 { 00473 otg_features_supported |= OTG_A_HNP_SUPPORT; 00474 Usb_ack_receive_setup(); 00475 Usb_send_control_in(); 00476 } 00477 break; 00478 00479 case OTG_A_ALT_HNP_SUPPORT: 00480 if (((OTG_BMATTRIBUTES&HNP_SUPPORT) == 0) || (USB_OTG_FEATURE == DISABLED)) 00481 { 00482 Usb_enable_stall_handshake(); 00483 Usb_ack_receive_setup(); 00484 } 00485 else 00486 { 00487 otg_features_supported |= OTG_A_ALT_HNP_SUPPORT; 00488 Usb_ack_receive_setup(); 00489 Usb_send_control_in(); 00490 } 00491 break; 00492 #endif 00493 00494 default: 00495 Usb_enable_stall_handshake(); 00496 Usb_ack_receive_setup(); 00497 break; 00498 } 00499 break; 00500 00501 case INTERFACE_TYPE: 00504 Usb_enable_stall_handshake(); 00505 Usb_ack_receive_setup(); 00506 break; 00507 00508 case ENDPOINT_TYPE: 00509 wValue = Usb_read_byte(); 00510 dummy = Usb_read_byte(); 00511 00512 if (wValue == FEATURE_ENDPOINT_HALT) 00513 { 00514 wIndex = (Usb_read_byte() & MSK_EP_DIR); 00515 00516 if (wIndex == EP_CONTROL) 00517 { 00518 Usb_enable_stall_handshake(); 00519 Usb_ack_receive_setup(); 00520 } 00521 00522 Usb_select_endpoint(wIndex); 00523 if(Is_usb_endpoint_enabled()) 00524 { 00525 Usb_enable_stall_handshake(); 00526 Usb_select_endpoint(EP_CONTROL); 00527 endpoint_status[wIndex] = 0x01; 00528 Usb_ack_receive_setup(); 00529 Usb_send_control_in(); 00530 } 00531 else 00532 { 00533 Usb_select_endpoint(EP_CONTROL); 00534 Usb_enable_stall_handshake(); 00535 Usb_ack_receive_setup(); 00536 } 00537 } 00538 else 00539 { 00540 Usb_enable_stall_handshake(); 00541 Usb_ack_receive_setup(); 00542 } 00543 break; 00544 00545 default: 00546 Usb_enable_stall_handshake(); 00547 Usb_ack_receive_setup(); 00548 break; 00549 } 00550 }
| void usb_get_status | ( | void | ) | [static] |
usb_get_status.
This function manages the GET STATUS request. The device, interface or endpoint status is returned.
| none |
< dummy read
< dummy read
Definition at line 375 of file usb_standard_request.c.
References bmRequestType, DEVICE_STATUS, endpoint_status, INTERFACE_STATUS, Is_usb_receive_out, MSK_EP_DIR, REQUEST_DEVICE_STATUS, REQUEST_ENDPOINT_STATUS, REQUEST_INTERFACE_STATUS, Usb_ack_receive_out, Usb_ack_receive_setup, Usb_enable_stall_handshake, Usb_read_byte, Usb_send_control_in, and Usb_write_byte.
Referenced by usb_process_request().
00376 { 00377 U8 wIndex; 00378 U8 dummy; 00379 00380 dummy = Usb_read_byte(); 00381 dummy = Usb_read_byte(); 00382 wIndex = Usb_read_byte(); 00383 00384 switch(bmRequestType) 00385 { 00386 case REQUEST_DEVICE_STATUS: Usb_ack_receive_setup(); 00387 Usb_write_byte(DEVICE_STATUS); 00388 break; 00389 00390 case REQUEST_INTERFACE_STATUS: Usb_ack_receive_setup(); 00391 Usb_write_byte(INTERFACE_STATUS); 00392 break; 00393 00394 case REQUEST_ENDPOINT_STATUS: Usb_ack_receive_setup(); 00395 wIndex = wIndex & MSK_EP_DIR; 00396 Usb_write_byte(endpoint_status[wIndex]); 00397 break; 00398 default: 00399 Usb_enable_stall_handshake(); 00400 Usb_ack_receive_setup(); 00401 return; 00402 } 00403 00404 Usb_write_byte(0x00); 00405 Usb_send_control_in(); 00406 00407 while( !Is_usb_receive_out() ); 00408 Usb_ack_receive_out(); 00409 }
| void usb_get_configuration | ( | void | ) | [static] |
usb_get_configuration.
This function manages the GET CONFIGURATION request. The current configuration number is returned.
| none |
Definition at line 353 of file usb_standard_request.c.
References Is_usb_receive_out, Usb_ack_in_ready, Usb_ack_receive_out, Usb_ack_receive_setup, usb_configuration_nb, and Usb_write_byte.
Referenced by usb_process_request().
00354 { 00355 Usb_ack_receive_setup(); 00356 00357 Usb_write_byte(usb_configuration_nb); 00358 Usb_ack_in_ready(); 00359 00360 while( !Is_usb_receive_out() ); 00361 Usb_ack_receive_out(); 00362 }
| void usb_get_interface | ( | void | ) | [static] |
usb_get_interface.
TThis function manages the GET_INTERFACE request.
| none |
Definition at line 637 of file usb_standard_request.c.
References Is_usb_receive_out, Usb_ack_receive_out, Usb_ack_receive_setup, and Usb_send_control_in.
Referenced by usb_process_request().
00638 { 00639 Usb_ack_receive_setup(); 00640 Usb_send_control_in(); 00641 00642 while( !Is_usb_receive_out() ); 00643 Usb_ack_receive_out(); 00644 }
| void usb_set_interface | ( | void | ) | [static] |
usb_set_interface.
TThis function manages the SET_INTERFACE request.
| none |
< send a ZLP for STATUS phase
Definition at line 656 of file usb_standard_request.c.
References Is_usb_in_ready, Usb_ack_receive_setup, and Usb_send_control_in.
Referenced by usb_process_request().
00657 { 00658 Usb_ack_receive_setup(); 00659 Usb_send_control_in(); 00660 while(!Is_usb_in_ready()); 00661 }
bit zlp [static] |
Definition at line 56 of file usb_standard_request.c.
Referenced by hid_get_hid_descriptor(), hid_get_report(), and usb_get_descriptor().
U8 endpoint_status[1] [static] |
Definition at line 57 of file usb_standard_request.c.
Referenced by usb_clear_feature(), usb_get_status(), and usb_set_feature().
Definition at line 62 of file usb_standard_request.c.
Referenced by hid_get_hid_descriptor(), hid_get_report(), usb_get_descriptor(), and usb_user_get_descriptor().
Definition at line 64 of file usb_standard_request.c.
Referenced by hid_get_hid_descriptor(), hid_get_report(), usb_get_descriptor(), and usb_user_get_descriptor().
Definition at line 66 of file usb_standard_request.c.
Referenced by hid_get_hid_descriptor(), hid_get_report(), usb_hid_get_interface(), and usb_hid_set_idle().
U8 bmRequestType [static] |
Definition at line 68 of file usb_standard_request.c.
Referenced by usb_clear_feature(), usb_get_status(), usb_process_request(), and usb_set_feature().
| bit usb_connected |
Public : (bit) usb_connected usb_connected is set to TRUE when VBUS has been detected usb_connected is set to FALSE otherwise /.
Definition at line 52 of file usb_device_task.c.
1.5.1-p1