]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/dreamsourcelab-dslogic/protocol.c
drivers: Drop some unnecessary prefixes.
[libsigrok.git] / src / hardware / dreamsourcelab-dslogic / protocol.c
index b5ca61b77e36efc80fabb17398bebd99fcc20fc1..efb626dc45ea024e569996a5393a7afc2091dc4c 100644 (file)
@@ -98,7 +98,7 @@ struct cmd_start_acquisition {
        uint8_t sample_delay_l;
 };
 
-struct dslogic_fpga_config {
+struct fpga_config {
        uint32_t sync;
 
        uint16_t mode_header;
@@ -337,8 +337,7 @@ static uint16_t enabled_channel_mask(const struct sr_dev_inst *sdi)
  * Get the session trigger and configure the FPGA structure
  * accordingly.
  */
-static void set_trigger(const struct sr_dev_inst *sdi,
-       struct dslogic_fpga_config *cfg)
+static void set_trigger(const struct sr_dev_inst *sdi, struct fpga_config *cfg)
 {
        struct sr_trigger *trigger;
        struct sr_trigger_stage *stage;
@@ -443,7 +442,7 @@ static int fpga_configure(const struct sr_dev_inst *sdi)
        struct dev_context *devc;
        struct sr_usb_dev_inst *usb;
        uint8_t c[3];
-       struct dslogic_fpga_config cfg;
+       struct fpga_config cfg;
        uint16_t v16;
        uint32_t v32;
        int transferred, len, ret;
@@ -464,7 +463,7 @@ static int fpga_configure(const struct sr_dev_inst *sdi)
        WL32(&cfg.end_sync, DS_CFG_END);
 
        /* Pass in the length of a fixed-size struct. Really. */
-       len = sizeof(struct dslogic_fpga_config) / 2;
+       len = sizeof(struct fpga_config) / 2;
        c[0] = len & 0xff;
        c[1] = (len >> 8) & 0xff;
        c[2] = (len >> 16) & 0xff;
@@ -517,7 +516,7 @@ static int fpga_configure(const struct sr_dev_inst *sdi)
 
        set_trigger(sdi, &cfg);
 
-       len = sizeof(struct dslogic_fpga_config);
+       len = sizeof(struct fpga_config);
        ret = libusb_bulk_transfer(usb->devhdl, 2 | LIBUSB_ENDPOINT_OUT,
                        (unsigned char *)&cfg, len, &transferred, USB_TIMEOUT);
        if (ret < 0 || transferred != len) {
@@ -560,7 +559,7 @@ SR_PRIV int dslogic_dev_open(struct sr_dev_inst *sdi, struct sr_dev_driver *di)
        struct dev_context *devc;
        struct drv_context *drvc;
        struct version_info vi;
-       int ret, i, device_count;
+       int ret = SR_ERR, i, device_count;
        uint8_t revid;
        char connection_id[64];
 
@@ -568,10 +567,6 @@ SR_PRIV int dslogic_dev_open(struct sr_dev_inst *sdi, struct sr_dev_driver *di)
        devc = sdi->priv;
        usb = sdi->conn;
 
-       if (sdi->status == SR_ST_ACTIVE)
-               /* Device is already in use. */
-               return SR_ERR;
-
        device_count = libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist);
        if (device_count < 0) {
                sr_err("Failed to get device list: %s.",
@@ -588,9 +583,7 @@ SR_PRIV int dslogic_dev_open(struct sr_dev_inst *sdi, struct sr_dev_driver *di)
 
                if ((sdi->status == SR_ST_INITIALIZING) ||
                                (sdi->status == SR_ST_INACTIVE)) {
-                       /*
-                        * Check device by its physical USB bus/port address.
-                        */
+                       /* Check device by its physical USB bus/port address. */
                        usb_get_port_path(devlist[i], connection_id, sizeof(connection_id));
                        if (strcmp(sdi->connection_id, connection_id))
                                /* This is not the one. */
@@ -607,6 +600,7 @@ SR_PRIV int dslogic_dev_open(struct sr_dev_inst *sdi, struct sr_dev_driver *di)
                } else {
                        sr_err("Failed to open device: %s.",
                               libusb_error_name(ret));
+                       ret = SR_ERR;
                        break;
                }
 
@@ -615,7 +609,8 @@ SR_PRIV int dslogic_dev_open(struct sr_dev_inst *sdi, struct sr_dev_driver *di)
                                if ((ret = libusb_detach_kernel_driver(usb->devhdl, USB_INTERFACE)) < 0) {
                                        sr_err("Failed to detach kernel driver: %s.",
                                                libusb_error_name(ret));
-                                       return SR_ERR;
+                                       ret = SR_ERR;
+                                       break;
                                }
                        }
                }
@@ -641,10 +636,10 @@ SR_PRIV int dslogic_dev_open(struct sr_dev_inst *sdi, struct sr_dev_driver *di)
                        sr_err("Expected firmware version %d.x, "
                               "got %d.%d.", DSLOGIC_REQUIRED_VERSION_MAJOR,
                               vi.major, vi.minor);
+                       ret = SR_ERR;
                        break;
                }
 
-               sdi->status = SR_ST_ACTIVE;
                sr_info("Opened device on %d.%d (logical) / %s (physical), "
                        "interface %d, firmware %d.%d.",
                        usb->bus, usb->address, connection_id,
@@ -653,14 +648,14 @@ SR_PRIV int dslogic_dev_open(struct sr_dev_inst *sdi, struct sr_dev_driver *di)
                sr_info("Detected REVID=%d, it's a Cypress CY7C68013%s.",
                        revid, (revid != 1) ? " (FX2)" : "A (FX2LP)");
 
+               ret = SR_OK;
+
                break;
        }
-       libusb_free_device_list(devlist, 1);
 
-       if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR;
+       libusb_free_device_list(devlist, 1);
 
-       return SR_OK;
+       return ret;
 }
 
 SR_PRIV struct dev_context *dslogic_dev_new(void)
@@ -1056,9 +1051,6 @@ SR_PRIV int dslogic_acquisition_start(const struct sr_dev_inst *sdi)
        struct libusb_transfer *transfer;
        int ret;
 
-       if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR_DEV_CLOSED;
-
        di = sdi->driver;
        drvc = di->context;
        devc = sdi->priv;