Make the avalon_read function parse the ftdi responses appopriately.
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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
diff --git a/driver-avalon.c b/driver-avalon.c
index de0ade2..537ace1 100644
--- a/driver-avalon.c
+++ b/driver-avalon.c
@@ -246,13 +246,26 @@ 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;
+ unsigned char readbuf[AVALON_READBUF_SIZE];
+ size_t total = 0, readsize = bufsize + 2;
+ int err, amount, ofs = 2, cp;
err = libusb_bulk_transfer(usbdev->handle, usbdev->found->eps[DEFAULT_EP_IN].ep,
- buf, bufsize, &amount, timeout);
+ readbuf, readsize, &amount, timeout);
applog(LOG_DEBUG, "%s%i: Get avalon read got err %d",
avalon->drv->name, avalon->device_id, err);
- return amount;
+
+ /* The first 2 of every 64 bytes are status on FTDIRL */
+ while (amount > 2) {
+ cp = amount - 2;
+ if (cp > 62)
+ cp = 62;
+ memcpy(&buf[total], &readbuf[ofs], cp);
+ total += cp;
+ amount -= cp + 2;
+ ofs += 64;
+ }
+ return total;
}
static int avalon_reset(struct cgpu_info *avalon, bool initial)
@@ -746,7 +759,7 @@ static void *avalon_get_results(void *userdata)
while (42) {
struct timeval tv_start, now, tdiff;
unsigned char buf[rsize];
- int amount, ofs, cp;
+ int ret;
if (offset >= (int)AVALON_READ_SIZE)
avalon_parse_results(avalon, info, thr, readbuf, &offset);
@@ -758,9 +771,9 @@ static void *avalon_get_results(void *userdata)
}
cgtime(&tv_start);
- amount = avalon_read(avalon, buf, rsize, AVALON_READ_TIMEOUT);
+ ret = avalon_read(avalon, buf, rsize, AVALON_READ_TIMEOUT);
- if (amount < 3) {
+ if (ret < 1) {
int ms_delay;
cgtime(&now);
@@ -773,7 +786,7 @@ static void *avalon_get_results(void *userdata)
if (opt_debug) {
applog(LOG_DEBUG, "Avalon: get:");
- hexdump((uint8_t *)buf, amount);
+ hexdump((uint8_t *)buf, ret);
}
/* During a reset, goes on reading but discards anything */
@@ -782,16 +795,7 @@ static void *avalon_get_results(void *userdata)
continue;
}
- ofs = 2;
- do {
- cp = amount - 2;
- if (cp > 62)
- cp = 62;
- memcpy(&readbuf[offset], &buf[ofs], cp);
- offset += cp;
- amount -= cp + 2;
- ofs += 64;
- } while (amount > 2);
+ memcpy(&readbuf[offset], &buf, ret);
}
return NULL;
}
diff --git a/driver-avalon.h b/driver-avalon.h
index d7dc870..551b66d 100644
--- a/driver-avalon.h
+++ b/driver-avalon.h
@@ -28,7 +28,7 @@
#define AVALON_DEFAULT_MINER_NUM 0x20
#define AVALON_DEFAULT_ASIC_NUM 0xA
-#define AVALON_FTDI_READSIZE 512
+#define AVALON_FTDI_READSIZE 510
#define AVALON_READBUF_SIZE 8192
#define AVALON_RESET_TIMEOUT 100
#define AVALON_READ_TIMEOUT 10