OpenULINK firmware: Use C99 designated struct initializers 84/1484/2
authorMartin Schmölzer <martin.schmoelzer@student.tuwien.ac.at>
Thu, 4 Jul 2013 18:06:02 +0000 (20:06 +0200)
committerSpencer Oliver <spen@spen-soft.co.uk>
Wed, 17 Jul 2013 14:31:08 +0000 (14:31 +0000)
Recent versions of SDCC added support for C99 designated struct initializers.
This provides better code readability (no functional changes).

Successfully tested with ULINK probe and STM32F103 (debug, erase and write
flash).

Change-Id: Idfa35147d2c3043baaa21a811b926b3845c85f9b
Signed-off-by: Martin Schmölzer <martin.schmoelzer@student.tuwien.ac.at>
Reviewed-on: http://openocd.zylin.com/1484
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
src/jtag/drivers/OpenULINK/src/usb.c

index 557afff55121f4e9bccfaf0820ab231ce808980c..98ae67f70fb6488de6f048a68d310533bfea45d8 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
 /***************************************************************************
- *   Copyright (C) 2011 by Martin Schmoelzer                               *
+ *   Copyright (C) 2011-2013 by Martin Schmoelzer                          *
  *   <martin.schmoelzer@student.tuwien.ac.at>                              *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
  *   <martin.schmoelzer@student.tuwien.ac.at>                              *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
@@ -43,87 +43,72 @@ volatile __xdata __at 0x7FE8 struct setup_data setup_data;
  * Be sure to include the neccessary endpoint descriptors! */
 #define NUM_ENDPOINTS 2
 
  * Be sure to include the neccessary endpoint descriptors! */
 #define NUM_ENDPOINTS 2
 
-/*
- * Normally, we would initialize the descriptor structures in C99 style:
- *
- * __code usb_device_descriptor_t device_descriptor = {
- *   .bLength = foo,
- *   .bDescriptorType = bar,
- *   .bcdUSB = 0xABCD,
- *   ...
- * };
- *
- * But SDCC currently does not support this, so we have to do it the
- * old-fashioned way...
- */
-
 __code struct usb_device_descriptor device_descriptor = {
 __code struct usb_device_descriptor device_descriptor = {
-       /* .bLength = */ sizeof(struct usb_device_descriptor),
-       /* .bDescriptorType = */ DESCRIPTOR_TYPE_DEVICE,
-       /* .bcdUSB = */ 0x0110,         /* BCD: 01.00 (Version 1.0 USB spec) */
-       /* .bDeviceClass = */ 0xFF,     /* 0xFF = vendor-specific */
-       /* .bDeviceSubClass = */ 0xFF,
-       /* .bDeviceProtocol = */ 0xFF,
-       /* .bMaxPacketSize0 = */ 64,
-       /* .idVendor = */ 0xC251,
-       /* .idProduct = */ 0x2710,
-       /* .bcdDevice = */ 0x0100,
-       /* .iManufacturer = */ 1,
-       /* .iProduct = */ 2,
-       /* .iSerialNumber = */ 3,
-       /* .bNumConfigurations = */ 1
+       .bLength =              sizeof(struct usb_device_descriptor),
+       .bDescriptorType =      DESCRIPTOR_TYPE_DEVICE,
+       .bcdUSB =               0x0110, /* BCD: 01.00 (Version 1.0 USB spec) */
+       .bDeviceClass =         0xFF,   /* 0xFF = vendor-specific */
+       .bDeviceSubClass =      0xFF,
+       .bDeviceProtocol =      0xFF,
+       .bMaxPacketSize0 =      64,
+       .idVendor =             0xC251,
+       .idProduct =            0x2710,
+       .bcdDevice =            0x0100,
+       .iManufacturer =        1,
+       .iProduct =             2,
+       .iSerialNumber =        3,
+       .bNumConfigurations =   1
 };
 
 /* WARNING: ALL config, interface and endpoint descriptors MUST be adjacent! */
 
 __code struct usb_config_descriptor config_descriptor = {
 };
 
 /* WARNING: ALL config, interface and endpoint descriptors MUST be adjacent! */
 
 __code struct usb_config_descriptor config_descriptor = {
-       /* .bLength = */ sizeof(struct usb_config_descriptor),
-       /* .bDescriptorType = */ DESCRIPTOR_TYPE_CONFIGURATION,
-       /* .wTotalLength = */ sizeof(struct usb_config_descriptor) +
-       sizeof(struct usb_interface_descriptor) +
-       (NUM_ENDPOINTS *
-        sizeof(struct usb_endpoint_descriptor)),
-       /* .bNumInterfaces = */ 1,
-       /* .bConfigurationValue = */ 1,
-       /* .iConfiguration = */ 4,      /* String describing this configuration */
-       /* .bmAttributes = */ 0x80,     /* Only MSB set according to USB spec */
-       /* .MaxPower = */ 50            /* 100 mA */
+       .bLength =              sizeof(struct usb_config_descriptor),
+       .bDescriptorType =      DESCRIPTOR_TYPE_CONFIGURATION,
+       .wTotalLength =         sizeof(struct usb_config_descriptor) +
+               sizeof(struct usb_interface_descriptor) +
+               (NUM_ENDPOINTS * sizeof(struct usb_endpoint_descriptor)),
+       .bNumInterfaces =       1,
+       .bConfigurationValue =  1,
+       .iConfiguration =       4,      /* String describing this configuration */
+       .bmAttributes =         0x80,   /* Only MSB set according to USB spec */
+       .MaxPower =             50      /* 100 mA */
 };
 
 __code struct usb_interface_descriptor interface_descriptor00 = {
 };
 
 __code struct usb_interface_descriptor interface_descriptor00 = {
-       /* .bLength = */ sizeof(struct usb_interface_descriptor),
-       /* .bDescriptorType = */ DESCRIPTOR_TYPE_INTERFACE,
-       /* .bInterfaceNumber = */ 0,
-       /* .bAlternateSetting = */ 0,
-       /* .bNumEndpoints = */ NUM_ENDPOINTS,
-       /* .bInterfaceClass = */ 0xFF,
-       /* .bInterfaceSubclass = */ 0xFF,
-       /* .bInterfaceProtocol = */ 0xFF,
-       /* .iInterface = */ 0
+       .bLength = sizeof(struct usb_interface_descriptor),
+       .bDescriptorType =      DESCRIPTOR_TYPE_INTERFACE,
+       .bInterfaceNumber =     0,
+       .bAlternateSetting =    0,
+       .bNumEndpoints =        NUM_ENDPOINTS,
+       .bInterfaceClass =      0xFF,
+       .bInterfaceSubclass =   0xFF,
+       .bInterfaceProtocol =   0xFF,
+       .iInterface =           0
 };
 
 __code struct usb_endpoint_descriptor Bulk_EP2_IN_Endpoint_Descriptor = {
 };
 
 __code struct usb_endpoint_descriptor Bulk_EP2_IN_Endpoint_Descriptor = {
-       /* .bLength = */ sizeof(struct usb_endpoint_descriptor),
-       /* .bDescriptorType = */ 0x05,
-       /* .bEndpointAddress = */ 2 | USB_DIR_IN,
-       /* .bmAttributes = */ 0x02,
-       /* .wMaxPacketSize = */ 64,
-       /* .bInterval = */ 0
+       .bLength =              sizeof(struct usb_endpoint_descriptor),
+       .bDescriptorType =      0x05,
+       .bEndpointAddress =     (2 | USB_DIR_IN),
+       .bmAttributes =         0x02,
+       .wMaxPacketSize =       64,
+       .bInterval =            0
 };
 
 __code struct usb_endpoint_descriptor Bulk_EP2_OUT_Endpoint_Descriptor = {
 };
 
 __code struct usb_endpoint_descriptor Bulk_EP2_OUT_Endpoint_Descriptor = {
-       /* .bLength = */ sizeof(struct usb_endpoint_descriptor),
-       /* .bDescriptorType = */ 0x05,
-       /* .bEndpointAddress = */ 2 | USB_DIR_OUT,
-       /* .bmAttributes = */ 0x02,
-       /* .wMaxPacketSize = */ 64,
-       /* .bInterval = */ 0
+       .bLength =              sizeof(struct usb_endpoint_descriptor),
+       .bDescriptorType =      0x05,
+       .bEndpointAddress =     (2 | USB_DIR_OUT),
+       .bmAttributes =         0x02,
+       .wMaxPacketSize =       64,
+       .bInterval =            0
 };
 
 __code struct usb_language_descriptor language_descriptor = {
 };
 
 __code struct usb_language_descriptor language_descriptor = {
-       /* .bLength =  */ 4,
-       /* .bDescriptorType = */ DESCRIPTOR_TYPE_STRING,
-       /* .wLANGID = */ {0x0409 /* US English */}
+       .bLength =              4,
+       .bDescriptorType =      DESCRIPTOR_TYPE_STRING,
+       .wLANGID =              {0x0409 /* US English */}
 };
 
 __code struct usb_string_descriptor strManufacturer =
 };
 
 __code struct usb_string_descriptor strManufacturer =

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)