]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/fx2lafw/api.c
Fix a few "value never read" scan-build warnings.
[libsigrok.git] / src / hardware / fx2lafw / api.c
index 1fb2235f1e57bedf1ed61c216eaf0ce6361a94ae..b9123513c49ade9ac38726ad62cd9a0080d19cba 100644 (file)
@@ -18,6 +18,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <config.h>
 #include "protocol.h"
 #include "dslogic.h"
 
@@ -45,20 +46,33 @@ static const struct fx2lafw_profile supported_fx2[] = {
                FIRMWARE_DIR "/fx2lafw-cwav-usbeesx.fw",
                0, NULL, NULL},
 
-       /*
-        * DreamSourceLab DSLogic (before FW upload)
-        */
+       /* DreamSourceLab DSLogic (before FW upload) */
        { 0x2a0e, 0x0001, "DreamSourceLab", "DSLogic", NULL,
                FIRMWARE_DIR "/dreamsourcelab-dslogic-fx2.fw",
                DEV_CAPS_16BIT, NULL, NULL},
-
-       /*
-        * DreamSourceLab DSLogic (after FW upload)
-        */
+       /* DreamSourceLab DSLogic (after FW upload) */
        { 0x2a0e, 0x0001, "DreamSourceLab", "DSLogic", NULL,
                FIRMWARE_DIR "/dreamsourcelab-dslogic-fx2.fw",
                DEV_CAPS_16BIT, "DreamSourceLab", "DSLogic"},
 
+       /* DreamSourceLab DSCope (before FW upload) */
+       { 0x2a0e, 0x0002, "DreamSourceLab", "DSCope", NULL,
+               FIRMWARE_DIR "/dreamsourcelab-dscope-fx2.fw",
+               DEV_CAPS_16BIT, NULL, NULL},
+       /* DreamSourceLab DSCope (after FW upload) */
+       { 0x2a0e, 0x0002, "DreamSourceLab", "DSCope", NULL,
+               FIRMWARE_DIR "/dreamsourcelab-dscope-fx2.fw",
+               DEV_CAPS_16BIT, "DreamSourceLab", "DSCope"},
+
+       /* DreamSourceLab DSLogic Pro (before FW upload) */
+       { 0x2a0e, 0x0003, "DreamSourceLab", "DSLogic Pro", NULL,
+               FIRMWARE_DIR "/dreamsourcelab-dslogic-pro-fx2.fw",
+               DEV_CAPS_16BIT, NULL, NULL},
+       /* DreamSourceLab DSLogic Pro (after FW upload) */
+       { 0x2a0e, 0x0003, "DreamSourceLab", "DSLogic Pro", NULL,
+               FIRMWARE_DIR "/dreamsourcelab-dslogic-pro-fx2.fw",
+               DEV_CAPS_16BIT, "DreamSourceLab", "DSLogic"},
+
        /*
         * Saleae Logic
         * EE Electronics ESLA100
@@ -106,9 +120,8 @@ static const uint32_t devopts[] = {
 };
 
 static const char *channel_names[] = {
-       "0",  "1",  "2",  "3",  "4",  "5",  "6",  "7",
-       "8",  "9", "10", "11", "12", "13", "14", "15",
-       NULL,
+       "0", "1", "2", "3", "4", "5", "6", "7",
+       "8", "9", "10", "11", "12", "13", "14", "15",
 };
 
 static const int32_t soft_trigger_matches[] = {
@@ -181,7 +194,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
        const char *conn;
        char manufacturer[64], product[64], serial_num[64], connection_id[64];
 
-       drvc = di->priv;
+       drvc = di->context;
 
        conn = NULL;
        for (l = options; l; l = l->next) {
@@ -215,11 +228,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
                                continue;
                }
 
-               if ((ret = libusb_get_device_descriptor( devlist[i], &des)) != 0) {
-                       sr_warn("Failed to get device descriptor: %s.",
-                               libusb_error_name(ret));
-                       continue;
-               }
+               libusb_get_device_descriptor( devlist[i], &des);
 
                if ((ret = libusb_open(devlist[i], &hdl)) < 0)
                        continue;
@@ -297,18 +306,20 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
                drvc->instances = g_slist_append(drvc->instances, sdi);
                devices = g_slist_append(devices, sdi);
 
-               if (strcmp(prof->model, "DSLogic")) {
+               if (!strcmp(prof->model, "DSLogic")
+                               || !strcmp(prof->model, "DSLogic Pro")
+                               || !strcmp(prof->model, "DSCope")) {
+                       devc->dslogic = TRUE;
+                       devc->samplerates = dslogic_samplerates;
+                       devc->num_samplerates = ARRAY_SIZE(dslogic_samplerates);
+                       has_firmware = match_manuf_prod(devlist[i], "DreamSourceLab", "DSLogic")
+                                       || match_manuf_prod(devlist[i], "DreamSourceLab", "DSCope");
+               } else {
                        devc->dslogic = FALSE;
                        devc->samplerates = samplerates;
                        devc->num_samplerates = ARRAY_SIZE(samplerates);
                        has_firmware = match_manuf_prod(devlist[i],
                                        "sigrok", "fx2lafw");
-               } else {
-                       devc->dslogic = TRUE;
-                       devc->samplerates = dslogic_samplerates;
-                       devc->num_samplerates = ARRAY_SIZE(dslogic_samplerates);
-                       has_firmware = match_manuf_prod(devlist[i],
-                                       "DreamSourceLab", "DSLogic");
                }
 
                if (has_firmware) {
@@ -341,7 +352,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
 
 static GSList *dev_list(const struct sr_dev_driver *di)
 {
-       return ((struct drv_context *)(di->priv))->instances;
+       return ((struct drv_context *)(di->context))->instances;
 }
 
 static int dev_open(struct sr_dev_inst *sdi)
@@ -349,6 +360,7 @@ static int dev_open(struct sr_dev_inst *sdi)
        struct sr_dev_driver *di = sdi->driver;
        struct sr_usb_dev_inst *usb;
        struct dev_context *devc;
+       char *fpga_firmware = NULL;
        int ret;
        int64_t timediff_us, timediff_ms;
 
@@ -409,8 +421,16 @@ static int dev_open(struct sr_dev_inst *sdi)
        }
 
        if (devc->dslogic) {
+               if (!strcmp(devc->profile->model, "DSLogic")) {
+                       fpga_firmware = DSLOGIC_FPGA_FIRMWARE;
+               } else if (!strcmp(devc->profile->model, "DSLogic Pro")) {
+                       fpga_firmware = DSLOGIC_PRO_FPGA_FIRMWARE;
+               } else if (!strcmp(devc->profile->model, "DSCope")) {
+                       fpga_firmware = DSCOPE_FPGA_FIRMWARE;
+               }
+
                if ((ret = dslogic_fpga_firmware_upload(sdi,
-                               DSLOGIC_FPGA_FIRMWARE)) != SR_OK)
+                               fpga_firmware)) != SR_OK)
                        return ret;
        }
 
@@ -427,7 +447,7 @@ static int dev_close(struct sr_dev_inst *sdi)
        struct sr_usb_dev_inst *usb;
 
        usb = sdi->conn;
-       if (usb->devhdl == NULL)
+       if (!usb->devhdl)
                return SR_ERR;
 
        sr_info("fx2lafw: Closing device on %d.%d (logical) / %s (physical) interface %d.",
@@ -445,7 +465,7 @@ static int cleanup(const struct sr_dev_driver *di)
        int ret;
        struct drv_context *drvc;
 
-       if (!(drvc = di->priv))
+       if (!(drvc = di->context))
                return SR_OK;
 
        ret = std_dev_clear(di, NULL);
@@ -502,8 +522,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
 {
        struct dev_context *devc;
        uint64_t arg;
-       unsigned int i;
-       int ret;
+       int i, ret;
 
        (void)cg;
 
@@ -518,30 +537,30 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
        ret = SR_OK;
 
        switch (key) {
-               case SR_CONF_SAMPLERATE:
-                       arg = g_variant_get_uint64(data);
-                       for (i = 0; i < ARRAY_SIZE(samplerates); i++) {
-                               if (samplerates[i] == arg) {
-                                       devc->cur_samplerate = arg;
-                                       break;
-                               }
+       case SR_CONF_SAMPLERATE:
+               arg = g_variant_get_uint64(data);
+               for (i = 0; i < devc->num_samplerates; i++) {
+                       if (devc->samplerates[i] == arg) {
+                               devc->cur_samplerate = arg;
+                               break;
                        }
-                       if (i == ARRAY_SIZE(samplerates))
-                               ret = SR_ERR_ARG;
-                       break;
-               case SR_CONF_LIMIT_SAMPLES:
-                       devc->limit_samples = g_variant_get_uint64(data);
-                       break;
-               case SR_CONF_CAPTURE_RATIO:
-                       devc->capture_ratio = g_variant_get_uint64(data);
-                       if (devc->capture_ratio > 100) {
-                               devc->capture_ratio = 0;
-                               ret = SR_ERR;
-                       } else
-                               ret = SR_OK;
-                       break;
-               default:
-                       ret = SR_ERR_NA;
+               }
+               if (i == devc->num_samplerates)
+                       ret = SR_ERR_ARG;
+               break;
+       case SR_CONF_LIMIT_SAMPLES:
+               devc->limit_samples = g_variant_get_uint64(data);
+               break;
+       case SR_CONF_CAPTURE_RATIO:
+               devc->capture_ratio = g_variant_get_uint64(data);
+               if (devc->capture_ratio > 100) {
+                       devc->capture_ratio = 0;
+                       ret = SR_ERR;
+               } else
+                       ret = SR_OK;
+               break;
+       default:
+               ret = SR_ERR_NA;
        }
 
        return ret;
@@ -598,9 +617,8 @@ static int receive_data(int fd, int revents, void *cb_data)
 
        (void)fd;
        (void)revents;
-       (void)cb_data;
 
-       drvc = (struct drv_context *) cb_data;
+       drvc = (struct drv_context *)cb_data;
 
        tv.tv_sec = tv.tv_usec = 0;
        libusb_handle_events_timeout(drvc->sr_ctx->libusb_ctx, &tv);
@@ -631,14 +649,12 @@ static int start_transfers(const struct sr_dev_inst *sdi)
                if (devc->limit_samples > 0)
                        pre_trigger_samples = devc->capture_ratio * devc->limit_samples/100;
                devc->stl = soft_trigger_logic_new(sdi, trigger, pre_trigger_samples);
-               if (devc->stl == NULL)
+               if (!devc->stl)
                        return SR_ERR_MALLOC;
                devc->trigger_fired = FALSE;
        } else
                devc->trigger_fired = TRUE;
 
-       timeout = fx2lafw_get_timeout(devc);
-
        num_transfers = fx2lafw_get_number_of_transfers(devc);
        size = fx2lafw_get_buffer_size(devc);
        devc->submitted_transfers = 0;
@@ -679,7 +695,7 @@ static int start_transfers(const struct sr_dev_inst *sdi)
        return SR_OK;
 }
 
-static void dslogic_trigger_receive(struct libusb_transfer *transfer)
+static void LIBUSB_CALL dslogic_trigger_receive(struct libusb_transfer *transfer)
 {
        const struct sr_dev_inst *sdi;
        struct dslogic_trigger_pos *tpos;
@@ -743,7 +759,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
                return SR_ERR_DEV_CLOSED;
 
        di = sdi->driver;
-       drvc = di->priv;
+       drvc = di->context;
        devc = sdi->priv;
 
        devc->ctx = drvc->sr_ctx;
@@ -757,11 +773,12 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
 
        if (devc->dslogic) {
                dslogic_trigger_request(sdi);
-       }
-       else {
-               if ((ret = fx2lafw_command_start_acquisition(sdi)) != SR_OK)
-                       return ret;
+       } else {
                start_transfers(sdi);
+               if ((ret = fx2lafw_command_start_acquisition(sdi)) != SR_OK) {
+                       fx2lafw_abort_acquisition(devc);
+                       return ret;
+               }
        }
 
        return SR_OK;
@@ -792,5 +809,5 @@ SR_PRIV struct sr_dev_driver fx2lafw_driver_info = {
        .dev_close = dev_close,
        .dev_acquisition_start = dev_acquisition_start,
        .dev_acquisition_stop = dev_acquisition_stop,
-       .priv = NULL,
+       .context = NULL,
 };