Use the avalon read timeout to completion if no data has been read.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
diff --git a/driver-avalon.c b/driver-avalon.c
index f300b3e..de0ade2 100644
--- a/driver-avalon.c
+++ b/driver-avalon.c
@@ -242,13 +242,14 @@ static void wait_avalon_ready(struct cgpu_info *avalon)
}
}
-static int avalon_read(struct cgpu_info *avalon, unsigned char *buf, size_t bufsize)
+static int avalon_read(struct cgpu_info *avalon, unsigned char *buf,
+ size_t bufsize, int timeout)
{
struct cg_usb_device *usbdev = avalon->usbdev;
int err, amount;
err = libusb_bulk_transfer(usbdev->handle, usbdev->found->eps[DEFAULT_EP_IN].ep,
- buf, bufsize, &amount, AVALON_READ_TIMEOUT);
+ buf, bufsize, &amount, timeout);
applog(LOG_DEBUG, "%s%i: Get avalon read got err %d",
avalon->drv->name, avalon->device_id, err);
return amount;
@@ -281,7 +282,8 @@ static int avalon_reset(struct cgpu_info *avalon, bool initial)
return 0;
}
- ret = avalon_read(avalon, (unsigned char *)&ar, AVALON_READ_SIZE);
+ ret = avalon_read(avalon, (unsigned char *)&ar, AVALON_READ_SIZE,
+ AVALON_RESET_TIMEOUT);
/* What do these sleeps do?? */
p.tv_sec = 0;
@@ -742,6 +744,7 @@ static void *avalon_get_results(void *userdata)
RenameThread(threadname);
while (42) {
+ struct timeval tv_start, now, tdiff;
unsigned char buf[rsize];
int amount, ofs, cp;
@@ -754,10 +757,19 @@ static void *avalon_get_results(void *userdata)
offset = 0;
}
- amount = avalon_read(avalon, buf, rsize);
+ cgtime(&tv_start);
+ amount = avalon_read(avalon, buf, rsize, AVALON_READ_TIMEOUT);
- if (amount < 3)
+ if (amount < 3) {
+ int ms_delay;
+
+ cgtime(&now);
+ timersub(&now, &tv_start, &tdiff);
+ ms_delay = AVALON_READ_TIMEOUT - (tdiff.tv_usec / 1000);
+ if (ms_delay > 0)
+ nmsleep(ms_delay);
continue;
+ }
if (opt_debug) {
applog(LOG_DEBUG, "Avalon: get:");
diff --git a/driver-avalon.h b/driver-avalon.h
index 03c89d7..d7dc870 100644
--- a/driver-avalon.h
+++ b/driver-avalon.h
@@ -30,6 +30,7 @@
#define AVALON_FTDI_READSIZE 512
#define AVALON_READBUF_SIZE 8192
+#define AVALON_RESET_TIMEOUT 100
#define AVALON_READ_TIMEOUT 10
struct avalon_task {