From: arighi Date: Wed, 22 Sep 2010 10:18:43 +0000 (+0000) Subject: USB: make all the read-only descriptors as const X-Git-Tag: 2.6.0~141 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=6ddebfbb0e36bb5e68c9364cafca25340e0be191;p=bertos.git USB: make all the read-only descriptors as const NOTE: at the moment only usb_device_descriptor_t can't be made const, because the attribute bMaxPacketSize0 is automatically filled by the low-level driver at runtime. TODO: refactor this part to evaluate bMaxPacketSize0 at compile time and make usb_device_descriptor_t read-only as well. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4260 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/cpu/cortex-m3/drv/usb_stm32.c b/bertos/cpu/cortex-m3/drv/usb_stm32.c index 2348599f..bbd02d21 100644 --- a/bertos/cpu/cortex-m3/drv/usb_stm32.c +++ b/bertos/cpu/cortex-m3/drv/usb_stm32.c @@ -929,13 +929,13 @@ static void USB_StallCtrlEP(void) */ static int usb_find_interface(uint32_t num, uint32_t alt) { - usb_interface_descriptor_t *id; + const usb_interface_descriptor_t *id; int i; for (i = 0; ; i++) { /* TODO: support more than one configuration per device */ - id = (usb_interface_descriptor_t *)usb_dev->config[i]; + id = (const usb_interface_descriptor_t *)usb_dev->config[i]; if (id == NULL) break; if (id->bDescriptorType != USB_DT_INTERFACE) @@ -953,7 +953,7 @@ static int usb_find_interface(uint32_t num, uint32_t alt) static void usb_configure_ep_interface(unsigned int num, unsigned int alt, bool enable) { - usb_endpoint_descriptor_t *epd; + const usb_endpoint_descriptor_t *epd; int i, start; /* @@ -976,7 +976,7 @@ usb_configure_ep_interface(unsigned int num, unsigned int alt, bool enable) */ for (i = start + 1; ; i++) { - epd = (usb_endpoint_descriptor_t *)usb_dev->config[i]; + epd = (const usb_endpoint_descriptor_t *)usb_dev->config[i]; if ((epd == NULL) || (epd->bDescriptorType == USB_DT_INTERFACE)) break; if (epd->bDescriptorType != USB_DT_ENDPOINT) @@ -1343,10 +1343,11 @@ static int usb_get_configuration_descriptor(int id) static int usb_get_string_descriptor(unsigned int id) { - usb_string_descriptor_t *lang_str; + const usb_string_descriptor_t *lang_str; unsigned int lang_id, str_id; uint16_t w_index_lo = usb_le16_to_cpu(setup_packet.wIndex) & 0x00ff; - uint16_t w_index_hi = (usb_le16_to_cpu(setup_packet.wIndex) & 0xff00) >> 8; + uint16_t w_index_hi = (usb_le16_to_cpu(setup_packet.wIndex) & + 0xff00) >> 8; ASSERT(usb_dev->strings != NULL); ASSERT(usb_dev->strings[0] != NULL); @@ -1357,8 +1358,8 @@ static int usb_get_string_descriptor(unsigned int id) /* Find Language index */ for (lang_id = 0; ; lang_id++) { - usb_string_descriptor_t *str = usb_dev->strings[lang_id]; - + const usb_string_descriptor_t *str = + usb_dev->strings[lang_id]; if (UNLIKELY(str == NULL)) return -USB_NODEV_ERROR; if ((str->data[0] == w_index_lo) && diff --git a/bertos/drv/usb.h b/bertos/drv/usb.h index 29dcb73c..d686c63e 100644 --- a/bertos/drv/usb.h +++ b/bertos/drv/usb.h @@ -330,8 +330,8 @@ typedef struct usb_endpoint_descriptor struct usb_device { usb_device_descriptor_t *device; - usb_descriptor_header_t **config; - usb_string_descriptor_t **strings; + const usb_descriptor_header_t **config; + const usb_string_descriptor_t **strings; /* Callbacks */ void (*event_cb)(usb_ctrlrequest_t *); diff --git a/bertos/drv/usb_serial.c b/bertos/drv/usb_serial.c index 3c3947be..ce2094b1 100644 --- a/bertos/drv/usb_serial.c +++ b/bertos/drv/usb_serial.c @@ -84,7 +84,7 @@ static usb_device_descriptor_t usb_serial_device_descriptor = .bNumConfigurations = 1, }; -static usb_config_descriptor_t usb_serial_config_descriptor = +static const usb_config_descriptor_t usb_serial_config_descriptor = { .bLength = sizeof(usb_serial_config_descriptor), .bDescriptorType = USB_DT_CONFIG, @@ -95,7 +95,7 @@ static usb_config_descriptor_t usb_serial_config_descriptor = .bMaxPower = 50, /* 100 mA */ }; -static usb_interface_descriptor_t usb_serial_interface_descriptor = +static const usb_interface_descriptor_t usb_serial_interface_descriptor = { .bLength = sizeof(usb_serial_interface_descriptor), .bDescriptorType = USB_DT_INTERFACE, @@ -108,7 +108,7 @@ static usb_interface_descriptor_t usb_serial_interface_descriptor = .iInterface = 0, }; -static usb_endpoint_descriptor_t usb_serial_ep_report_descriptor = +static const usb_endpoint_descriptor_t usb_serial_ep_report_descriptor = { .bLength = sizeof(usb_serial_ep_report_descriptor), .bDescriptorType = USB_DT_ENDPOINT, @@ -118,7 +118,7 @@ static usb_endpoint_descriptor_t usb_serial_ep_report_descriptor = .bInterval = 1, }; -static usb_endpoint_descriptor_t usb_serial_ep_in_descriptor = +static const usb_endpoint_descriptor_t usb_serial_ep_in_descriptor = { .bLength = sizeof(usb_serial_ep_in_descriptor), .bDescriptorType = USB_DT_ENDPOINT, @@ -128,7 +128,7 @@ static usb_endpoint_descriptor_t usb_serial_ep_in_descriptor = .bInterval = 0, }; -static usb_endpoint_descriptor_t usb_serial_ep_out_descriptor = +static const usb_endpoint_descriptor_t usb_serial_ep_out_descriptor = { .bLength = sizeof(usb_serial_ep_in_descriptor), .bDescriptorType = USB_DT_ENDPOINT, @@ -138,13 +138,13 @@ static usb_endpoint_descriptor_t usb_serial_ep_out_descriptor = .bInterval = 0, }; -static usb_descriptor_header_t *usb_serial_config[] = +static const usb_descriptor_header_t *usb_serial_config[] = { - (usb_descriptor_header_t *)&usb_serial_config_descriptor, - (usb_descriptor_header_t *)&usb_serial_interface_descriptor, - (usb_descriptor_header_t *)&usb_serial_ep_report_descriptor, - (usb_descriptor_header_t *)&usb_serial_ep_in_descriptor, - (usb_descriptor_header_t *)&usb_serial_ep_out_descriptor, + (const usb_descriptor_header_t *)&usb_serial_config_descriptor, + (const usb_descriptor_header_t *)&usb_serial_interface_descriptor, + (const usb_descriptor_header_t *)&usb_serial_ep_report_descriptor, + (const usb_descriptor_header_t *)&usb_serial_ep_in_descriptor, + (const usb_descriptor_header_t *)&usb_serial_ep_out_descriptor, NULL, }; @@ -156,7 +156,7 @@ static DEFINE_USB_STRING(product_str, static DEFINE_USB_STRING(serial_str, USB_STRING("0", "0", "1")); -static usb_string_descriptor_t *usb_serial_strings[] = +static const usb_string_descriptor_t *usb_serial_strings[] = { (usb_string_descriptor_t *)&language_str, (usb_string_descriptor_t *)&manufacturer_str,