hantek-dso: get rid of broken GTV_TO_MSEC firmware upload timeout

This commit is contained in:
Bert Vermeulen 2012-06-27 00:55:15 +02:00
parent e749a8cb50
commit fc8fe3e314
2 changed files with 16 additions and 16 deletions

View File

@ -34,10 +34,9 @@
#include "config.h" #include "config.h"
#include "dso.h" #include "dso.h"
/* FIXME: Temporary build fix, this will be removed later. */
#define GTV_TO_MSEC(gtv) (gtv.tv_sec * 1000 + gtv.tv_usec / 1000)
/* Max time in ms before we want to check on events */ /* Max time in ms before we want to check on USB events */
/* TODO tune this properly */
#define TICK 1 #define TICK 1
static const int hwcaps[] = { static const int hwcaps[] = {
@ -228,7 +227,7 @@ static int hw_init(const char *devinfo)
if (ezusb_upload_firmware(devlist[i], USB_CONFIGURATION, if (ezusb_upload_firmware(devlist[i], USB_CONFIGURATION,
prof->firmware) == SR_OK) prof->firmware) == SR_OK)
/* Remember when the firmware on this device was updated */ /* Remember when the firmware on this device was updated */
g_get_current_time(&ctx->fw_updated); ctx->fw_updated = g_get_monotonic_time();
else else
sr_err("hantek-dso: firmware upload failed for " sr_err("hantek-dso: firmware upload failed for "
"device %d", devcnt); "device %d", devcnt);
@ -263,33 +262,34 @@ static int hw_init(const char *devinfo)
static int hw_dev_open(int dev_index) static int hw_dev_open(int dev_index)
{ {
GTimeVal cur_time;
struct sr_dev_inst *sdi; struct sr_dev_inst *sdi;
struct context *ctx; struct context *ctx;
int timediff, err; int64_t timediff_us, timediff_ms;
int err;
if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) if (!(sdi = sr_dev_inst_get(dev_insts, dev_index)))
return SR_ERR_ARG; return SR_ERR_ARG;
ctx = sdi->priv; ctx = sdi->priv;
/* /*
* if the firmware was recently uploaded, wait up to MAX_RENUM_DELAY ms * if the firmware was recently uploaded, wait up to MAX_RENUM_DELAY_MS
* for the FX2 to renumerate * for the FX2 to renumerate
*/ */
err = 0; err = SR_ERR;
if (GTV_TO_MSEC(ctx->fw_updated) > 0) { if (ctx->fw_updated > 0) {
sr_info("hantek-dso: waiting for device to reset"); sr_info("hantek-dso: waiting for device to reset");
/* takes at least 300ms for the FX2 to be gone from the USB bus */ /* takes at least 300ms for the FX2 to be gone from the USB bus */
g_usleep(300 * 1000); g_usleep(300 * 1000);
timediff = 0; timediff_ms = 0;
while (timediff < MAX_RENUM_DELAY) { while (timediff_ms < MAX_RENUM_DELAY_MS) {
if ((err = dso_open(dev_index)) == SR_OK) if ((err = dso_open(dev_index)) == SR_OK)
break; break;
g_usleep(100 * 1000); g_usleep(100 * 1000);
g_get_current_time(&cur_time); timediff_us = g_get_monotonic_time() - ctx->fw_updated;
timediff = GTV_TO_MSEC(cur_time) - GTV_TO_MSEC(ctx->fw_updated); timediff_ms = timediff_us / 1000;
sr_spew("fx2lafw: waited %" PRIi64 " ms", timediff_ms);
} }
sr_info("hantek-dso: device came back after %d ms", timediff); sr_info("hantek-dso: device came back after %d ms", timediff_ms);
} else { } else {
err = dso_open(dev_index); err = dso_open(dev_index);
} }

View File

@ -28,7 +28,7 @@
#define DSO_EP_OUT 0x02 #define DSO_EP_OUT 0x02
/* FX2 renumeration delay in ms */ /* FX2 renumeration delay in ms */
#define MAX_RENUM_DELAY 3000 #define MAX_RENUM_DELAY_MS 3000
#define MAX_CAPTURE_EMPTY 3 #define MAX_CAPTURE_EMPTY 3
@ -170,7 +170,7 @@ struct context {
* after the upgrade) this is like a global lock. No device will open * after the upgrade) this is like a global lock. No device will open
* until a proper delay after the last device was upgraded. * until a proper delay after the last device was upgraded.
*/ */
GTimeVal fw_updated; int64_t fw_updated;
int epin_maxpacketsize; int epin_maxpacketsize;
int capture_empty_count; int capture_empty_count;
int dev_state; int dev_state;