USB: make all the read-only descriptors as const
authorarighi <arighi@38d2e660-2303-0410-9eaa-f027e97ec537>
Wed, 22 Sep 2010 10:18:43 +0000 (10:18 +0000)
committerarighi <arighi@38d2e660-2303-0410-9eaa-f027e97ec537>
Wed, 22 Sep 2010 10:18:43 +0000 (10:18 +0000)
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

bertos/cpu/cortex-m3/drv/usb_stm32.c
bertos/drv/usb.h
bertos/drv/usb_serial.c

index 2348599f41b94d5aa4bd272627c1ff57b9ac9f6c..bbd02d21aa676d80b268fe431ffb60d3fe003817 100644 (file)
@@ -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) &&
index 29dcb73c17709a154eb8f25d32588e872fa902a8..d686c63ecca186266f3ad164abbf173294beb1b9 100644 (file)
@@ -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 *);
index 3c3947be3b015eccc35e997a6e205502233c9388..ce2094b1720d390775fa08a8e6f448d826648def 100644 (file)
@@ -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,