X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fhardware%2Fasix-sigma%2Fprotocol.c;h=ee7ce02211e373dbc55f13d82ac3d50ca77deefc;hb=ac9534f48a8656a52b1cfc504915531afd0b9f70;hp=60c6a34843c6c415f55df1c02a78bb0f4d589e89;hpb=74d453abfd29f8ea5426c4400f29d30cc18e97dd;p=libsigrok.git diff --git a/src/hardware/asix-sigma/protocol.c b/src/hardware/asix-sigma/protocol.c index 60c6a348..ee7ce022 100644 --- a/src/hardware/asix-sigma/protocol.c +++ b/src/hardware/asix-sigma/protocol.c @@ -462,14 +462,14 @@ static int upload_firmware(struct sr_context *ctx, if (ret < 0) { sr_err("ftdi_usb_open failed: %s", ftdi_get_error_string(ftdic)); - return 0; + return SR_ERR; } ret = ftdi_set_bitmode(ftdic, 0xdf, BITMODE_BITBANG); if (ret < 0) { sr_err("ftdi_set_bitmode failed: %s", ftdi_get_error_string(ftdic)); - return 0; + return SR_ERR; } /* Four times the speed of sigmalogan - Works well. */ @@ -477,7 +477,7 @@ static int upload_firmware(struct sr_context *ctx, if (ret < 0) { sr_err("ftdi_set_baudrate failed: %s", ftdi_get_error_string(ftdic)); - return 0; + return SR_ERR; } /* Initialize the FPGA for firmware upload. */ @@ -554,6 +554,7 @@ SR_PRIV int sigma_set_samplerate(const struct sr_dev_inst *sdi, uint64_t sampler struct drv_context *drvc; size_t i; int ret; + int num_channels; devc = sdi->priv; drvc = sdi->driver->context; @@ -572,15 +573,16 @@ SR_PRIV int sigma_set_samplerate(const struct sr_dev_inst *sdi, uint64_t sampler * firmware is required and higher rates might limit the set * of available channels. */ + num_channels = devc->num_channels; if (samplerate <= SR_MHZ(50)) { ret = upload_firmware(drvc->sr_ctx, 0, devc); - devc->num_channels = 16; + num_channels = 16; } else if (samplerate == SR_MHZ(100)) { ret = upload_firmware(drvc->sr_ctx, 1, devc); - devc->num_channels = 8; + num_channels = 8; } else if (samplerate == SR_MHZ(200)) { ret = upload_firmware(drvc->sr_ctx, 2, devc); - devc->num_channels = 4; + num_channels = 4; } /* @@ -589,6 +591,7 @@ SR_PRIV int sigma_set_samplerate(const struct sr_dev_inst *sdi, uint64_t sampler * an "event" (memory organization internal to the device). */ if (ret == SR_OK) { + devc->num_channels = num_channels; devc->cur_samplerate = samplerate; devc->samples_per_event = 16 / devc->num_channels; devc->state.state = SIGMA_IDLE; @@ -1138,7 +1141,7 @@ static int sigma_capture_mode(struct sr_dev_inst *sdi) { struct dev_context *devc; uint64_t running_msec; - struct timeval tv; + uint64_t current_time; devc = sdi->priv; @@ -1146,9 +1149,8 @@ static int sigma_capture_mode(struct sr_dev_inst *sdi) * Check if the selected sampling duration passed. Sample count * limits are covered by this enforced timeout as well. */ - gettimeofday(&tv, 0); - running_msec = (tv.tv_sec - devc->start_tv.tv_sec) * 1000 + - (tv.tv_usec - devc->start_tv.tv_usec) / 1000; + current_time = g_get_monotonic_time(); + running_msec = (current_time - devc->start_time) / 1000; if (running_msec >= devc->limit_msec) return download_capture(sdi);