#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_enum_var_init (void) |
usb_enum_variable_init.This function initializes the main usb variables:
| |
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 [2] |
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.
|
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.
< 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 266 of file usb_standard_request.c. References CONFIGURATION_DESCRIPTOR, data_to_transfer, DEVICE_DESCRIPTOR, EP_CONTROL_LENGTH, FALSE, Is_usb_read_control_enabled, Is_usb_receive_out, LSB, MSB, pbuffer, TRUE, Usb_ack_receive_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(). 00267 { 00268 U16 wLength ; 00269 U8 descriptor_type ; 00270 U8 string_type ; 00271 U8 dummy; 00272 U8 nb_byte; 00273 00274 zlp = FALSE; /* no zero length packet */ 00275 string_type = Usb_read_byte(); /* read LSB of wValue */ 00276 descriptor_type = Usb_read_byte(); /* read MSB of wValue */ 00277 00278 switch (descriptor_type) 00279 { 00280 case DEVICE_DESCRIPTOR: 00281 data_to_transfer = Usb_get_dev_desc_length(); 00282 pbuffer = Usb_get_dev_desc_pointer(); 00283 break; 00284 case CONFIGURATION_DESCRIPTOR: 00285 data_to_transfer = Usb_get_conf_desc_length(); 00286 pbuffer = Usb_get_conf_desc_pointer(); 00287 break; 00288 default: 00289 if( usb_user_get_descriptor(descriptor_type, string_type)==FALSE ) 00290 { 00291 Usb_enable_stall_handshake(); 00292 Usb_ack_receive_setup(); 00293 return; 00294 } 00295 break; 00296 } 00297 00298 dummy = Usb_read_byte(); 00299 dummy = Usb_read_byte(); 00300 LSB(wLength) = Usb_read_byte(); 00301 MSB(wLength) = Usb_read_byte(); 00302 Usb_ack_receive_setup() ; 00303 00304 if (wLength > data_to_transfer) 00305 { 00306 if ((data_to_transfer % EP_CONTROL_LENGTH) == 0) { zlp = TRUE; } 00307 else { zlp = FALSE; } 00308 } 00309 else 00310 { 00311 data_to_transfer = (U8)wLength; 00312 } 00313 00314 while((data_to_transfer != 0) && (!Is_usb_receive_out())) 00315 { 00316 while(!Is_usb_read_control_enabled()); 00317 00318 nb_byte=0; 00319 while(data_to_transfer != 0) 00320 { 00321 if(nb_byte++==EP_CONTROL_LENGTH) 00322 { 00323 break; 00324 } 00325 #ifndef AVRGCC 00326 Usb_write_byte(*pbuffer++); 00327 #else // AVRGCC does not support point to PGM space 00328 #warning with avrgcc assumes devices descriptors are stored in the lower 64Kbytes of on-chip flash memory 00329 Usb_write_byte(pgm_read_byte_near((unsigned int)pbuffer++)); 00330 #endif 00331 data_to_transfer --; 00332 } 00333 Usb_send_control_in(); 00334 } 00335 00336 Usb_send_control_in(); 00337 00338 if(Is_usb_receive_out()) { Usb_ack_receive_out(); return; } 00339 if(zlp == TRUE) 00340 { 00341 while(!Is_usb_read_control_enabled()); 00342 Usb_send_control_in(); 00343 } 00344 00345 00346 while(!Is_usb_receive_out()); 00347 Usb_ack_receive_out(); 00348 }
Here is the call graph for this function: ![]() |
|
usb_set_address. This function manages the SET ADDRESS request. When complete, the device will filter the requests using the new address.
< waits for status phase done before using the new address Definition at line 199 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(). 00200 { 00201 Usb_configure_address(Usb_read_byte()); 00202 00203 Usb_ack_receive_setup(); 00204 00205 Usb_send_control_in(); 00206 while(!Is_usb_in_ready()); 00207 00208 Usb_enable_address(); 00209 }
|
|
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.
< send a ZLP for STATUS phase < endpoint configuration Definition at line 225 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(). 00226 { 00227 U8 configuration_number; 00228 00229 configuration_number = Usb_read_byte(); 00230 00231 if (configuration_number <= NB_CONFIGURATION) 00232 { 00233 Usb_ack_receive_setup(); 00234 usb_configuration_nb = configuration_number; 00235 } 00236 else 00237 { 00240 Usb_enable_stall_handshake(); 00241 Usb_ack_receive_setup(); 00242 return; 00243 } 00244 00245 Usb_send_control_in(); 00246 00247 usb_user_endpoint_init(usb_configuration_nb); 00248 Usb_set_configuration_action(); 00249 }
Here is the call graph for this function: ![]() |
|
usb_clear_feature. This function manages the SET FEATURE request.
< keep that order (set StallRq/clear RxSetup) or a OUT request following the SETUP may be acknowledged < dummy read Definition at line 498 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(). 00499 { 00500 U8 wValue; 00501 U8 wIndex; 00502 U8 dummy; 00503 00504 if (bmRequestType == ZERO_TYPE) 00505 { 00508 Usb_enable_stall_handshake(); 00509 Usb_ack_receive_setup(); 00510 return; 00511 } 00512 else if (bmRequestType == INTERFACE_TYPE) 00513 { 00516 Usb_enable_stall_handshake(); 00517 Usb_ack_receive_setup(); 00518 return; 00519 } 00520 else if (bmRequestType == ENDPOINT_TYPE) 00521 { 00522 wValue = Usb_read_byte(); 00523 dummy = Usb_read_byte(); 00524 00525 if (wValue == FEATURE_ENDPOINT_HALT) 00526 { 00527 wIndex = (Usb_read_byte() & MSK_EP_DIR); 00528 00529 Usb_select_endpoint(wIndex); 00530 if(Is_usb_endpoint_enabled()) 00531 { 00532 if(wIndex != EP_CONTROL) 00533 { 00534 Usb_disable_stall_handshake(); 00535 Usb_reset_endpoint(wIndex); 00536 Usb_reset_data_toggle(); 00537 } 00538 Usb_select_endpoint(EP_CONTROL); 00539 endpoint_status[wIndex] = 0x00; 00540 Usb_ack_receive_setup(); 00541 Usb_send_control_in(); 00542 } 00543 else 00544 { 00545 Usb_enable_stall_handshake(); 00546 Usb_ack_receive_setup(); 00547 return; 00548 } 00549 } 00550 else 00551 { 00552 Usb_enable_stall_handshake(); 00553 Usb_ack_receive_setup(); 00554 return; 00555 } 00556 } 00557 }
|
|
usb_set_feature. This function manages the SET FEATURE request. The USB test modes are supported by this function.
< dummy read Definition at line 432 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_enable_stall_handshake, Usb_read_byte, Usb_select_endpoint, and Usb_send_control_in. Referenced by usb_process_request(). 00433 { 00434 U8 wValue; 00435 U8 wIndex; 00436 U8 dummy; 00437 00438 if (bmRequestType == INTERFACE_TYPE) 00439 { 00442 Usb_enable_stall_handshake(); 00443 Usb_ack_receive_setup(); 00444 return; 00445 } 00446 else if (bmRequestType == ENDPOINT_TYPE) 00447 { 00448 wValue = Usb_read_byte(); 00449 dummy = Usb_read_byte(); 00450 00451 if (wValue == FEATURE_ENDPOINT_HALT) 00452 { 00453 wIndex = (Usb_read_byte() & MSK_EP_DIR); 00454 00455 if (wIndex == EP_CONTROL) 00456 { 00457 Usb_enable_stall_handshake(); 00458 Usb_ack_receive_setup(); 00459 return; 00460 } 00461 00462 Usb_select_endpoint(wIndex); 00463 if(Is_usb_endpoint_enabled()) 00464 { 00465 Usb_enable_stall_handshake(); 00466 Usb_select_endpoint(EP_CONTROL); 00467 endpoint_status[wIndex] = 0x01; 00468 Usb_ack_receive_setup(); 00469 Usb_send_control_in(); 00470 } 00471 else 00472 { 00473 Usb_enable_stall_handshake(); 00474 Usb_ack_receive_setup(); 00475 return; 00476 } 00477 } 00478 else 00479 { 00480 Usb_enable_stall_handshake(); 00481 Usb_ack_receive_setup(); 00482 return; 00483 } 00484 } 00485 }
|
|
usb_get_status. This function manages the GET STATUS request. The device, interface or endpoint status is returned.
< dummy read Definition at line 384 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(). 00385 { 00386 U8 wIndex; 00387 U8 dummy; 00388 00389 dummy = Usb_read_byte(); 00390 dummy = Usb_read_byte(); 00391 wIndex = Usb_read_byte(); 00392 00393 switch(bmRequestType) 00394 { 00395 case REQUEST_DEVICE_STATUS: Usb_ack_receive_setup(); 00396 Usb_write_byte(DEVICE_STATUS); 00397 break; 00398 00399 case REQUEST_INTERFACE_STATUS: Usb_ack_receive_setup(); 00400 Usb_write_byte(INTERFACE_STATUS); 00401 break; 00402 00403 case REQUEST_ENDPOINT_STATUS: Usb_ack_receive_setup(); 00404 wIndex = wIndex & MSK_EP_DIR; 00405 Usb_write_byte(endpoint_status[wIndex]); 00406 break; 00407 default: 00408 Usb_enable_stall_handshake(); 00409 Usb_ack_receive_setup(); 00410 return; 00411 } 00412 00413 Usb_write_byte(0x00); 00414 Usb_send_control_in(); 00415 00416 while( !Is_usb_receive_out() ); 00417 Usb_ack_receive_out(); 00418 }
|
|
usb_get_configuration. This function manages the GET CONFIGURATION request. The current configuration number is returned.
Definition at line 362 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(). 00363 { 00364 Usb_ack_receive_setup(); 00365 00366 Usb_write_byte(usb_configuration_nb); 00367 Usb_ack_in_ready(); 00368 00369 while( !Is_usb_receive_out() ); 00370 Usb_ack_receive_out(); 00371 }
|
|
usb_get_interface. TThis function manages the GET_INTERFACE request.
Definition at line 571 of file usb_standard_request.c. References Usb_ack_receive_setup, and Usb_enable_stall_handshake. Referenced by usb_process_request(). 00572 { 00573 Usb_enable_stall_handshake(); 00574 Usb_ack_receive_setup(); 00575 }
|
|
usb_set_interface. TThis function manages the SET_INTERFACE request.
Definition at line 587 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(). 00588 { 00589 Usb_ack_receive_setup(); 00590 Usb_send_control_in(); 00591 while(!Is_usb_in_ready()); 00592 }
|
|
usb_enum_variable_init.This function initializes the main usb variables:
Definition at line 88 of file usb_standard_request.c. References endpoint_status, ep_num, and NB_ENDPOINTS. 00089 { 00090 U8 ep_num ; 00091 00092 for( ep_num=0 ; ep_num<NB_ENDPOINTS ; ep_num++ ) 00093 { 00094 endpoint_status[ep_num] = 0; 00095 } 00096 usb_connected = FALSE; // USB is not connected 00097 usb_configuration_nb = 0 ; // Default configuration number is 0 00098 }
|
|
Definition at line 56 of file usb_standard_request.c. Referenced by hid_get_report(), and usb_get_descriptor(). |
|
Definition at line 57 of file usb_standard_request.c. Referenced by usb_clear_feature(), usb_enum_var_init(), usb_get_status(), and usb_set_feature(). |
|
Definition at line 62 of file usb_standard_request.c. Referenced by 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_report(), usb_get_descriptor(), and usb_user_get_descriptor(). |
|
Definition at line 66 of file usb_standard_request.c. Referenced by hid_get_report(), usb_hid_get_interface(), and usb_hid_set_idle(). |
|
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(). |
|
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 46 of file usb_device_task.c. |
|
|
|
|