Do a non-blocking read of anything in the avalon buffer after opening the device.
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
diff --git a/driver-avalon.c b/driver-avalon.c
index 6f33526..1ab2efc 100644
--- a/driver-avalon.c
+++ b/driver-avalon.c
@@ -550,6 +550,25 @@ static void get_options(int this_option_offset, int *baud, int *miner_count,
}
}
+/* Non blocking clearing of anything in the buffer */
+static void avalon_clear_readbuf(int fd)
+{
+ ssize_t ret;
+
+ do {
+ struct timeval timeout;
+ char buf[AVALON_FTDI_READSIZE];
+ fd_set rd;
+
+ timeout.tv_sec = timeout.tv_usec = 0;
+ FD_ZERO(&rd);
+ FD_SET((SOCKETTYPE)fd, &rd);
+ ret = select(fd + 1, &rd, NULL, NULL, &timeout);
+ if (ret > 0)
+ ret = read(fd, buf, AVALON_FTDI_READSIZE);
+ } while (ret > 0);
+}
+
static bool avalon_detect_one(const char *devpath)
{
struct avalon_info *info;
@@ -571,6 +590,7 @@ static bool avalon_detect_one(const char *devpath)
applog(LOG_ERR, "Avalon Detect: Failed to open %s", devpath);
return false;
}
+ avalon_clear_readbuf(fd);
/* We have a real Avalon! */
avalon = calloc(1, sizeof(struct cgpu_info));
diff --git a/driver-avalon.h b/driver-avalon.h
index ed745e7..d097788 100644
--- a/driver-avalon.h
+++ b/driver-avalon.h
@@ -28,6 +28,8 @@
#define AVALON_DEFAULT_MINER_NUM 0x20
#define AVALON_DEFAULT_ASIC_NUM 0xA
+#define AVALON_FTDI_READSIZE 512
+
struct avalon_task {
uint8_t reset :1;
uint8_t flush_fifo :1;