X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Ffx2lafw%2Fprotocol.c;h=83315808d0eca129d1e37503d0375ec22de8f250;hb=599f9e1deb6b6a4a75e00e29d86935845164eeed;hp=a31231fd41a22813ae3e4f23a69e1c5aa2c71a7d;hpb=f670835f1fbc03525e995d6970a5495976ab7c1a;p=libsigrok.git diff --git a/src/hardware/fx2lafw/protocol.c b/src/hardware/fx2lafw/protocol.c index a31231fd..83315808 100644 --- a/src/hardware/fx2lafw/protocol.c +++ b/src/hardware/fx2lafw/protocol.c @@ -112,7 +112,7 @@ static int command_start_acquisition(const struct sr_dev_inst *sdi) sr_dbg("GPIF delay = %d, clocksource = %sMHz.", delay, (cmd.flags & CMD_START_FLAGS_CLK_48MHZ) ? "48" : "30"); - if (delay <= 0 || delay > MAX_SAMPLE_DELAY) { + if (delay < 0 || delay > MAX_SAMPLE_DELAY) { sr_err("Unable to sample at %" PRIu64 "Hz.", samplerate); return SR_ERR; } @@ -147,7 +147,7 @@ SR_PRIV int fx2lafw_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]; @@ -155,10 +155,6 @@ SR_PRIV int fx2lafw_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.", @@ -178,7 +174,9 @@ SR_PRIV int fx2lafw_dev_open(struct sr_dev_inst *sdi, struct sr_dev_driver *di) /* * Check device by its physical USB bus/port address. */ - usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)); + if (usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)) < 0) + continue; + if (strcmp(sdi->connection_id, connection_id)) /* This is not the one. */ continue; @@ -194,6 +192,7 @@ SR_PRIV int fx2lafw_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; } @@ -202,7 +201,8 @@ SR_PRIV int fx2lafw_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; } } } @@ -231,7 +231,6 @@ SR_PRIV int fx2lafw_dev_open(struct sr_dev_inst *sdi, struct sr_dev_driver *di) 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, @@ -240,14 +239,14 @@ SR_PRIV int fx2lafw_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 *fx2lafw_dev_new(void) @@ -617,7 +616,7 @@ static int start_transfers(const struct sr_dev_inst *sdi) if ((trigger = sr_session_trigger_get(sdi->session))) { int pre_trigger_samples = 0; if (devc->limit_samples > 0) - pre_trigger_samples = devc->capture_ratio * devc->limit_samples/100; + pre_trigger_samples = (devc->capture_ratio * devc->limit_samples) / 100; devc->stl = soft_trigger_logic_new(sdi, trigger, pre_trigger_samples); if (!devc->stl) return SR_ERR_MALLOC;