[tuxdroid-svn] r1202 - firmware/fuxusb/trunk/src
Status: Beta
Brought to you by:
ks156
From: Paul_R <c2m...@c2...> - 2008-05-23 15:27:10
|
Author: Paul_R Date: 2008-05-23 17:27:06 +0200 (Fri, 23 May 2008) New Revision: 1202 Modified: firmware/fuxusb/trunk/src/usb_desc.h firmware/fuxusb/trunk/src/usb_enum.c Log: * Splitted and cleaned the get_descriptor function. * Added attribute 'code' on the descriptors structures. (see C51 reference manual). Modified: firmware/fuxusb/trunk/src/usb_desc.h =================================================================== --- firmware/fuxusb/trunk/src/usb_desc.h 2008-05-23 14:20:56 UTC (rev 1201) +++ firmware/fuxusb/trunk/src/usb_desc.h 2008-05-23 15:27:06 UTC (rev 1202) @@ -217,7 +217,7 @@ /* @} */ /* @} */ -struct usb_st_device_descriptor +code struct usb_st_device_descriptor { uint8_t bLength; /**< Size of this descriptor in bytes. */ uint8_t bDescriptorType; /**< DEVICE descriptor type */ @@ -235,7 +235,7 @@ uint8_t bNumConfigurations; /**< Number of possible configurations */ }; -struct usb_st_configuration_descriptor +code struct usb_st_configuration_descriptor { uint8_t bLength; /**< size of this descriptor in bytes */ uint8_t bDescriptorType; /**< CONFIGURATION descriptor type */ @@ -247,7 +247,7 @@ uint8_t MaxPower; /**< maximum power consumption */ }; -struct usb_st_interface_descriptor +code struct usb_st_interface_descriptor { uint8_t bLength; /**< size of this descriptor in bytes */ uint8_t bDescriptorType; /**< INTERFACE descriptor type */ @@ -260,7 +260,7 @@ uint8_t iInterface; /**< Index of string descriptor */ }; -struct usb_st_endpoint_descriptor +code struct usb_st_endpoint_descriptor { uint8_t bLength; /**< Size of this descriptor in bytes */ uint8_t bDescriptorType; /**< ENDPOINT descriptor type */ @@ -271,7 +271,7 @@ }; /* HID specific */ -struct usb_hid_descriptor +code struct usb_hid_descriptor { uint8_t bLength; /**< size of this descriptor in bytes */ uint8_t bDescriptorType; /**< INTERFACE descriptor type */ @@ -283,7 +283,7 @@ }; /* Audio Class specific */ -struct usb_Audio_st_ACinterface_descriptor +code struct usb_Audio_st_ACinterface_descriptor { uint8_t bLength; /**< size of this descriptor in bytes */ uint8_t bDescriptorType; /**< INTERFACE descriptor type */ @@ -296,7 +296,7 @@ uint8_t iInterface; /**< Index of string descriptor */ }; -struct usb_Audio_cs_ACinterface_descriptor +code struct usb_Audio_cs_ACinterface_descriptor { uint8_t bLength; /**< size of this descriptor in bytes */ uint8_t bDescriptorType; /**< INTERFACE descriptor type */ @@ -307,7 +307,7 @@ uint8_t baInterfaceNr[2]; /**< Class code assigned by the USB */ }; -struct usb_Audio_cs_ACinterface_descriptor_NbCol1 +code struct usb_Audio_cs_ACinterface_descriptor_NbCol1 { uint8_t bLength; /**< size of this descriptor in bytes */ uint8_t bDescriptorType; /**< INTERFACE descriptor type */ @@ -319,7 +319,7 @@ }; /* Audio input terminal */ -struct usb_Audio_InputTerminal_descriptor +code struct usb_Audio_InputTerminal_descriptor { uint8_t bLength; /**< size of this descriptor in bytes */ uint8_t bDescriptorType; /**< INTERFACE descriptor type */ @@ -334,7 +334,7 @@ }; /* Audio output terminal */ -struct usb_Audio_OutputTerminal_descriptor +code struct usb_Audio_OutputTerminal_descriptor { uint8_t bLength; /**< size of this descriptor in bytes */ uint8_t bDescriptorType; /**< INTERFACE descriptor type */ @@ -347,7 +347,7 @@ }; /* Audio feature unit */ -struct usb_Audio_FeatureUnit_descriptor +code struct usb_Audio_FeatureUnit_descriptor { uint8_t bLength; /**< size of this descriptor in bytes */ uint8_t bDescriptorType; /**< INTERFACE descriptor type */ @@ -360,7 +360,7 @@ }; /* Audio stream */ -struct usb_Audio_st_ASinterface_descriptor +code struct usb_Audio_st_ASinterface_descriptor { uint8_t bLength; /**< size of this descriptor in bytes */ uint8_t bDescriptorType; /**< INTERFACE descriptor type */ @@ -374,7 +374,7 @@ }; /* Audio class specific */ -struct usb_Audio_cs_ASinterface_descriptor +code struct usb_Audio_cs_ASinterface_descriptor { uint8_t bLength; /**< size of this descriptor in bytes */ uint8_t bDescriptorType; /**< INTERFACE descriptor type */ @@ -385,7 +385,7 @@ }; /* Audio EP */ -struct usb_Audio_st_endpoint_descriptor +code struct usb_Audio_st_endpoint_descriptor { uint8_t bLength; /**< Size of this descriptor in bytes */ uint8_t bDescriptorType; /**< ENDPOINT descriptor type */ @@ -398,7 +398,7 @@ }; /* Audio stream */ -struct usb_Audio_cs_ASendpoint_descriptor +code struct usb_Audio_cs_ASendpoint_descriptor { uint8_t bLength; /**< Size of this descriptor in bytes */ uint8_t bDescriptorType; /**< ENDPOINT descriptor type */ @@ -409,7 +409,7 @@ }; /* Audio endpoint */ -struct usb_Audio_TYPEI_FormatType_descriptor +code struct usb_Audio_TYPEI_FormatType_descriptor { uint8_t bLength; /**< Size of this descriptor in bytes */ uint8_t bDescriptorType; /**< ENDPOINT descriptor type */ @@ -425,7 +425,7 @@ /** \name General structure * This structure contain all the descriptors. * @{ */ -struct usb_configuration_s +code struct usb_configuration_s { /*! Configuration descriptor */ struct usb_st_configuration_descriptor cfg; @@ -532,56 +532,56 @@ /** \name String descriptors * @{ */ -struct usb_st_language_descriptor +code struct usb_st_language_descriptor { uint8_t bLength; /**< size of this descriptor in bytes */ uint8_t bDescriptorType; /**< STRING descriptor type */ uint16_t wstring[USB_CONFIG_LENGTH]; /**< language id */ }; -struct usb_st_manufacturer +code struct usb_st_manufacturer { uint8_t bLength; /**< size of this descriptor in bytes */ uint8_t bDescriptorType; /**< STRING descriptor type */ uint16_t wstring[USB_MN_LENGTH];/**< unicode characters */ }; -struct usb_st_product +code struct usb_st_product { uint8_t bLength; /**< size of this descriptor in bytes */ uint8_t bDescriptorType; /**< STRING descriptor type */ uint16_t wstring[USB_PN_LENGTH];/**< unicode characters */ }; -struct usb_st_serial_number +code struct usb_st_serial_number { uint8_t bLength; /**< size of this descriptor in bytes */ uint8_t bDescriptorType; /**< STRING descriptor type */ uint16_t wstring[USB_SN_LENGTH];/**< unicode characters */ }; -struct usb_st_config +code struct usb_st_config { uint8_t bLength; /**< size of this descriptor in bytes */ uint8_t bDescriptorType; /**< STRING descriptor type */ uint16_t wstring[USB_CONFIG_LENGTH];/**< unicode characters */ }; -struct usb_st_speaker_descriptor +code struct usb_st_speaker_descriptor { uint8_t bLength; /**< size of this descriptor in bytes */ uint8_t bDescriptorType; /**< STRING descriptor type */ uint16_t wstring[AUDIO_SPEAKER_LENGTH]; /**< language id */ }; -struct usb_st_micro_descriptor +code struct usb_st_micro_descriptor { uint8_t bLength; /**< size of this descriptor in bytes */ uint8_t bDescriptorType; /**< STRING descriptor type */ uint16_t wstring[AUDIO_MICRO_LENGTH]; /**< language id */ }; -struct usb_st_tts_descriptor +code struct usb_st_tts_descriptor { uint8_t bLength; /**< size of this descriptor in bytes */ uint8_t bDescriptorType; /**< STRING descriptor type */ @@ -589,7 +589,7 @@ }; -struct usb_st_audio_descriptor +code struct usb_st_audio_descriptor { uint8_t bLength; /**< size of this descriptor in bytes */ uint8_t bDescriptorType; /**< STRING descriptor type */ @@ -600,7 +600,7 @@ /** \name String structure * This structure contain all the descriptors. * @{ */ -struct string_s +code struct string_s { /*! Language string descriptor */ struct usb_st_language_descriptor st_language; Modified: firmware/fuxusb/trunk/src/usb_enum.c =================================================================== --- firmware/fuxusb/trunk/src/usb_enum.c 2008-05-23 14:20:56 UTC (rev 1201) +++ firmware/fuxusb/trunk/src/usb_enum.c 2008-05-23 15:27:06 UTC (rev 1202) @@ -54,6 +54,8 @@ * \ingroup usb_enum */ uint8_t usb_configuration_nb = 0; /*! @} */ +/** Number of data to transfert during a get_descriptor process. */ +uint16_t data_to_transfer; /** \name Standard enumeration functions * @{ */ @@ -90,6 +92,7 @@ /** \name Misc functions * @{ */ +static bit send_descriptor(uint8_t *buffer, uint8_t size); static void stall_request(void); static void send_zlp(void); /* @} */ @@ -391,8 +394,8 @@ */ static void usb_get_descriptor (void) { - uint16_t data_to_transfer; - uint16_t wLength; + + uint16_t wLength; uint8_t descriptor_type; uint8_t string_type; @@ -401,25 +404,18 @@ string_type = Usb_read_byte(); descriptor_type = Usb_read_byte(); -#ifdef USB_ENUM_DEBUG - printf("GET_DESCRIPTOR %BX %BX ",descriptor_type,string_type); -#endif + + /* Parse the request, and prepare data */ switch (descriptor_type) { case DEVICE: data_to_transfer = sizeof (usb_device_descriptor); pbuffer = &(usb_device_descriptor.bLength); -#ifdef USB_ENUM_DEBUG - printf("DEVICE "); -#endif break; case CONFIGURATION: data_to_transfer = sizeof (usb_configuration); pbuffer = &(usb_configuration.cfg.bLength); -#ifdef USB_ENUM_DEBUG - printf("CONFIGURATION "); -#endif break; #ifdef HID_DEVICE @@ -435,9 +431,6 @@ #endif case STRING: -#ifdef USB_ENUM_DEBUG - printf("STRING %BX", string_type); -#endif switch (string_type) { case LANG_ID: @@ -493,95 +486,64 @@ } break; default: -#ifdef USB_ENUM_DEBUG - printf("UNKNOWN"); -#endif + Usb_clear_rx_setup(); stall_request(); Usb_clear_DIR(); -#ifdef USB_ENUM_DEBUG - printf("1"); -#endif return; } - ACC = Usb_read_byte(); /* don't care of wIndex field */ + /* Pop 2 bytes from the usb fifo. We don't need them. */ ACC = Usb_read_byte(); + ACC = Usb_read_byte(); - ((uint8_t *)&wLength)[1] = Usb_read_byte(); /* read wLength */ + /* Read the wLength value */ + ((uint8_t *)&wLength)[1] = Usb_read_byte(); ((uint8_t *)&wLength)[0] = Usb_read_byte(); + /* Determine if the last paket will be complete or not */ if (wLength > data_to_transfer) { - if ((data_to_transfer % EP_CONTROL_LENGTH) == 0) - { - zlp = True; - } - else - { - zlp = False; - } /* no need of zero length packet */ + zlp = (data_to_transfer % EP_CONTROL_LENGTH) ? False : True; } else { data_to_transfer = wLength; /* send only requested number of data */ } - Usb_clear_rx_setup(); /* clear the receive setup flag */ - Usb_set_DIR(); /* set out on EP0 */ + /* Clear setup bit, prepare EP to send data */ + Usb_clear_rx_setup(); + Usb_set_DIR(); + + /* Send data on the bus */ while (data_to_transfer > EP_CONTROL_LENGTH) { - pbuffer = usb_send_ep0_packet(pbuffer, EP_CONTROL_LENGTH); - data_to_transfer -= EP_CONTROL_LENGTH; - - while ((!(Usb_rx_complete())) && (!(Usb_tx_complete()))); - Usb_clear_tx_complete(); - if ((Usb_rx_complete())) /* if cancel from USB Host */ + if (!send_descriptor(pbuffer, EP_CONTROL_LENGTH)) { - Usb_clear_tx_ready(); - Usb_clear_rx(); -#ifdef USB_ENUM_DEBUG - printf("2"); -#endif return; } } - /* send last data packet */ - pbuffer = usb_send_ep0_packet(pbuffer, data_to_transfer); - data_to_transfer = 0; - while ((!(Usb_rx_complete())) && (!(Usb_tx_complete()))); - Usb_clear_tx_complete(); - if ((Usb_rx_complete())) /* if cancel from USB Host */ + + /* Send last packet */ + if (!send_descriptor(pbuffer, data_to_transfer)) { - Usb_clear_tx_ready(); - Usb_clear_rx(); -#ifdef USB_ENUM_DEBUG - printf("3"); -#endif return; } + + /* The last packet was smaller than the EP size : send a ZLP. */ if (zlp == True) { - usb_send_ep0_packet(pbuffer, 0); - while ((!(Usb_rx_complete())) && (!(Usb_tx_complete()))); - Usb_clear_tx_complete(); - if ((Usb_rx_complete())) /* if cancel from USB Host */ + if (!send_descriptor(pbuffer, 0)) { - Usb_clear_tx_ready(); - Usb_clear_rx(); -#ifdef USB_ENUM_DEBUG - printf("4"); -#endif return; } - } + + /* Wait until the last packet has not be sent */ while ((!(Usb_rx_complete())) && (!(Usb_setup_received()))); + if (Usb_setup_received()) { -#ifdef USB_ENUM_DEBUG - printf("5"); -#endif return; } @@ -590,10 +552,33 @@ Usb_clear_DIR(); /* set in on EP0 */ Usb_clear_rx(); } -#ifdef USB_ENUM_DEBUG - printf("6"); -#endif +} +/** + * \brief This function send the descriptor to the host. + * \param *buffer Pointer on a buffer wich contain data to send. + * \param size The number of data to send. + * \return True is the host as acknoledged the packet. + */ +static bit send_descriptor(uint8_t *buffer, uint8_t size) +{ + pbuffer = usb_send_ep0_packet(buffer, size); + data_to_transfer -= size; + + /* Wait until the EP isn't ready */ + while (!Usb_rx_complete() && !Usb_tx_complete()); + + /* Clear TX complete flag */ + Usb_clear_tx_complete(); + + /* Cancelled by host, abort */ + if ((Usb_rx_complete())) + { + Usb_clear_tx_ready(); + Usb_clear_rx(); + return False; + } + return True; } /** |