#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 "lib_mcu/pll/pll_drv.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. | |
void | usb_generate_remote_wakeup (void) |
This function manages the remote wakeup generation to wake up the host controlle. | |
Variables | |
static bit | zlp |
static U8 | endpoint_status [NB_ENDPOINTS] |
static U8 | device_status = DEVICE_STATUS |
U8 code * | pbuffer |
U8 | data_to_transfer |
U16 | wInterface |
static U8 | bmRequestType |
U8 | remote_wakeup_feature = DISABLE |
Public : (U8) remote_wakeup_feature Store a host request for remote wake up (set feature received) /. | |
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 |
U8 | usb_remote_wup_feature |
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 277 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, TRUE, Usb_ack_control_out, 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().
00278 { 00279 U16 wLength; 00280 U8 descriptor_type ; 00281 U8 string_type; 00282 U8 dummy; 00283 U8 nb_byte; 00284 00285 zlp = FALSE; /* no zero length packet */ 00286 string_type = Usb_read_byte(); /* read LSB of wValue */ 00287 descriptor_type = Usb_read_byte(); /* read MSB of wValue */ 00288 00289 switch (descriptor_type) 00290 { 00291 case DEVICE_DESCRIPTOR: 00292 data_to_transfer = Usb_get_dev_desc_length(); 00293 pbuffer = Usb_get_dev_desc_pointer(); 00294 break; 00295 case CONFIGURATION_DESCRIPTOR: 00296 data_to_transfer = Usb_get_conf_desc_length(); 00297 pbuffer = Usb_get_conf_desc_pointer(); 00298 break; 00299 default: 00300 if( usb_user_get_descriptor(descriptor_type, string_type)==FALSE ) 00301 { 00302 Usb_enable_stall_handshake(); 00303 Usb_ack_receive_setup(); 00304 return; 00305 } 00306 break; 00307 } 00308 00309 dummy = Usb_read_byte(); 00310 dummy = Usb_read_byte(); 00311 LSB(wLength) = Usb_read_byte(); 00312 MSB(wLength) = Usb_read_byte(); 00313 Usb_ack_receive_setup() ; 00314 00315 if (wLength > data_to_transfer) 00316 { 00317 if ((data_to_transfer % EP_CONTROL_LENGTH) == 0) { zlp = TRUE; } 00318 else { zlp = FALSE; } 00319 } 00320 else 00321 { 00322 data_to_transfer = (U8)wLength; 00323 } 00324 00325 Usb_ack_nak_out(); 00326 00327 while((data_to_transfer != 0) && (!Is_usb_nak_out_sent())) 00328 { 00329 while(!Is_usb_read_control_enabled()) 00330 { 00331 if (Is_usb_nak_out_sent()) 00332 break; // don't clear the flag now, it will be cleared after 00333 } 00334 00335 nb_byte=0; 00336 while(data_to_transfer != 0) 00337 { 00338 if(nb_byte++==EP_CONTROL_LENGTH) 00339 { 00340 break; 00341 } 00342 00343 #ifndef __GNUC__ 00344 Usb_write_byte(*pbuffer++); 00345 #else // AVRGCC does not support point to PGM space 00346 Usb_write_byte(pgm_read_byte_near((unsigned int)pbuffer++)); 00347 #endif 00348 data_to_transfer --; 00349 } 00350 00351 if (Is_usb_nak_out_sent()) 00352 break; 00353 else 00354 Usb_send_control_in(); 00355 } 00356 00357 if((zlp == TRUE) && (!Is_usb_nak_out_sent())) 00358 { 00359 while(!Is_usb_read_control_enabled()); 00360 Usb_send_control_in(); 00361 } 00362 00363 while (!(Is_usb_nak_out_sent())); 00364 Usb_ack_nak_out(); // clear NAKOUTI 00365 Usb_ack_control_out(); // clear RXOUTI 00366 00367 00368 00369 }
Here is the call graph for this function:
Here is the caller 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 209 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().
00210 { 00211 U8 addr = Usb_read_byte(); 00212 Usb_configure_address(addr); 00213 00214 Usb_ack_receive_setup(); 00215 00216 Usb_send_control_in(); 00217 while(!Is_usb_in_ready()); 00218 00219 Usb_enable_address(); 00220 }
Here is the caller graph for this function:
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 236 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().
00237 { 00238 U8 configuration_number; 00239 00240 configuration_number = Usb_read_byte(); 00241 00242 if (configuration_number <= NB_CONFIGURATION) 00243 { 00244 Usb_ack_receive_setup(); 00245 usb_configuration_nb = configuration_number; 00246 } 00247 else 00248 { 00251 Usb_enable_stall_handshake(); 00252 Usb_ack_receive_setup(); 00253 return; 00254 } 00255 00256 Usb_send_control_in(); 00257 00258 usb_user_endpoint_init(usb_configuration_nb); 00259 Usb_set_configuration_action(); 00260 }
Here is the call graph for this function:
Here is the caller 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
< dummy read
Definition at line 551 of file usb_standard_request.c.
References bmRequestType, device_status, DISABLED, ENABLED, endpoint_status, ENDPOINT_TYPE, EP_CONTROL, FEATURE_DEVICE_REMOTE_WAKEUP, FEATURE_ENDPOINT_HALT, INTERFACE_TYPE, Is_usb_endpoint_enabled, MSK_EP_DIR, remote_wakeup_feature, Usb_ack_receive_setup, Usb_disable_stall_handshake, Usb_enable_stall_handshake, Usb_read_byte, USB_REMOTE_WAKEUP_FEATURE, Usb_reset_data_toggle, Usb_reset_endpoint, Usb_select_endpoint, Usb_send_control_in, USB_STATUS_REMOTEWAKEUP, and ZERO_TYPE.
Referenced by usb_process_request().
00552 { 00553 U8 wValue; 00554 U8 wIndex; 00555 U8 dummy; 00556 00557 if (bmRequestType == ZERO_TYPE) 00558 { 00559 wValue = Usb_read_byte(); 00560 if ((wValue == FEATURE_DEVICE_REMOTE_WAKEUP) && (USB_REMOTE_WAKEUP_FEATURE == ENABLED)) 00561 { 00562 device_status &= ~USB_STATUS_REMOTEWAKEUP; 00563 remote_wakeup_feature = DISABLED; 00564 Usb_ack_receive_setup(); 00565 Usb_send_control_in(); 00566 } 00567 else 00568 { 00569 Usb_enable_stall_handshake(); 00570 Usb_ack_receive_setup(); 00571 } 00572 return; 00573 } 00574 else if (bmRequestType == INTERFACE_TYPE) 00575 { 00578 Usb_enable_stall_handshake(); 00579 Usb_ack_receive_setup(); 00580 return; 00581 } 00582 else if (bmRequestType == ENDPOINT_TYPE) 00583 { 00584 wValue = Usb_read_byte(); 00585 dummy = Usb_read_byte(); 00586 00587 if (wValue == FEATURE_ENDPOINT_HALT) 00588 { 00589 wIndex = (Usb_read_byte() & MSK_EP_DIR); 00590 00591 Usb_select_endpoint(wIndex); 00592 if(Is_usb_endpoint_enabled()) 00593 { 00594 if(wIndex != EP_CONTROL) 00595 { 00596 Usb_disable_stall_handshake(); 00597 Usb_reset_endpoint(wIndex); 00598 Usb_reset_data_toggle(); 00599 } 00600 Usb_select_endpoint(EP_CONTROL); 00601 endpoint_status[wIndex] = 0x00; 00602 Usb_ack_receive_setup(); 00603 Usb_send_control_in(); 00604 } 00605 else 00606 { 00607 Usb_select_endpoint(EP_CONTROL); 00608 Usb_enable_stall_handshake(); 00609 Usb_ack_receive_setup(); 00610 return; 00611 } 00612 } 00613 else 00614 { 00615 Usb_enable_stall_handshake(); 00616 Usb_ack_receive_setup(); 00617 return; 00618 } 00619 } 00620 }
Here is the caller graph for this function:
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 453 of file usb_standard_request.c.
References bmRequestType, device_status, ENABLED, endpoint_status, ENDPOINT_TYPE, EP_CONTROL, FEATURE_DEVICE_REMOTE_WAKEUP, FEATURE_ENDPOINT_HALT, INTERFACE_TYPE, Is_usb_endpoint_enabled, MSK_EP_DIR, remote_wakeup_feature, Usb_ack_receive_setup, Usb_enable_stall_handshake, Usb_read_byte, USB_REMOTE_WAKEUP, USB_REMOTE_WAKEUP_FEATURE, Usb_select_endpoint, Usb_send_control_in, USB_STATUS_REMOTEWAKEUP, and ZERO_TYPE.
Referenced by usb_process_request().
00454 { 00455 U8 wValue; 00456 U8 wIndex; 00457 U8 dummy; 00458 00459 switch (bmRequestType) 00460 { 00461 case ZERO_TYPE: 00462 wValue = Usb_read_byte(); 00463 switch (wValue) 00464 { 00465 case USB_REMOTE_WAKEUP: 00466 if ((wValue == FEATURE_DEVICE_REMOTE_WAKEUP) && (USB_REMOTE_WAKEUP_FEATURE == ENABLED)) 00467 { 00468 device_status |= USB_STATUS_REMOTEWAKEUP; 00469 remote_wakeup_feature = ENABLED; 00470 Usb_ack_receive_setup(); 00471 Usb_send_control_in(); 00472 } 00473 else 00474 { 00475 Usb_enable_stall_handshake(); 00476 Usb_ack_receive_setup(); 00477 } 00478 break; 00479 00480 00481 00482 default: 00483 Usb_enable_stall_handshake(); 00484 Usb_ack_receive_setup(); 00485 break; 00486 } 00487 break; 00488 00489 case INTERFACE_TYPE: 00492 Usb_enable_stall_handshake(); 00493 Usb_ack_receive_setup(); 00494 break; 00495 00496 case ENDPOINT_TYPE: 00497 wValue = Usb_read_byte(); 00498 dummy = Usb_read_byte(); 00499 00500 if (wValue == FEATURE_ENDPOINT_HALT) 00501 { 00502 wIndex = (Usb_read_byte() & MSK_EP_DIR); 00503 00504 if (wIndex == EP_CONTROL) 00505 { 00506 Usb_enable_stall_handshake(); 00507 Usb_ack_receive_setup(); 00508 } 00509 00510 Usb_select_endpoint(wIndex); 00511 if(Is_usb_endpoint_enabled()) 00512 { 00513 Usb_enable_stall_handshake(); 00514 Usb_select_endpoint(EP_CONTROL); 00515 endpoint_status[wIndex] = 0x01; 00516 Usb_ack_receive_setup(); 00517 Usb_send_control_in(); 00518 } 00519 else 00520 { 00521 Usb_select_endpoint(EP_CONTROL); 00522 Usb_enable_stall_handshake(); 00523 Usb_ack_receive_setup(); 00524 } 00525 } 00526 else 00527 { 00528 Usb_enable_stall_handshake(); 00529 Usb_ack_receive_setup(); 00530 } 00531 break; 00532 00533 default: 00534 Usb_enable_stall_handshake(); 00535 Usb_ack_receive_setup(); 00536 break; 00537 } 00538 }
Here is the caller graph for this function:
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 405 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().
00406 { 00407 U8 wIndex; 00408 U8 dummy; 00409 00410 dummy = Usb_read_byte(); 00411 dummy = Usb_read_byte(); 00412 wIndex = Usb_read_byte(); 00413 00414 switch(bmRequestType) 00415 { 00416 case REQUEST_DEVICE_STATUS: Usb_ack_receive_setup(); 00417 Usb_write_byte(device_status); 00418 break; 00419 00420 case REQUEST_INTERFACE_STATUS: Usb_ack_receive_setup(); 00421 Usb_write_byte(INTERFACE_STATUS); 00422 break; 00423 00424 case REQUEST_ENDPOINT_STATUS: Usb_ack_receive_setup(); 00425 wIndex = wIndex & MSK_EP_DIR; 00426 Usb_write_byte(endpoint_status[wIndex]); 00427 break; 00428 default: 00429 Usb_enable_stall_handshake(); 00430 Usb_ack_receive_setup(); 00431 return; 00432 } 00433 00434 Usb_write_byte(0x00); 00435 Usb_send_control_in(); 00436 00437 while( !Is_usb_receive_out() ); 00438 Usb_ack_receive_out(); 00439 }
Here is the caller graph for this function:
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 383 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().
00384 { 00385 Usb_ack_receive_setup(); 00386 00387 Usb_write_byte(usb_configuration_nb); 00388 Usb_ack_in_ready(); 00389 00390 while( !Is_usb_receive_out() ); 00391 Usb_ack_receive_out(); 00392 }
Here is the caller graph for this function:
void usb_get_interface | ( | void | ) | [static] |
usb_get_interface.
TThis function manages the GET_INTERFACE request.
none |
Definition at line 634 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().
00635 { 00636 Usb_ack_receive_setup(); 00637 Usb_send_control_in(); 00638 00639 while( !Is_usb_receive_out() ); 00640 Usb_ack_receive_out(); 00641 }
Here is the caller graph for this function:
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 653 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().
00654 { 00655 Usb_ack_receive_setup(); 00656 Usb_send_control_in(); 00657 while(!Is_usb_in_ready()); 00658 }
Here is the caller graph for this function:
bit zlp [static] |
U8 endpoint_status[NB_ENDPOINTS] [static] |
Definition at line 88 of file usb_standard_request.c.
Referenced by usb_clear_feature(), usb_get_status(), and usb_set_feature().
U8 device_status = DEVICE_STATUS [static] |
Definition at line 89 of file usb_standard_request.c.
Referenced by usb_clear_feature(), usb_get_status(), and usb_set_feature().
Definition at line 98 of file usb_standard_request.c.
U8 bmRequestType [static] |
Definition at line 100 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 69 of file usb_device_task.c.