Commit 569a6f65a0a28d3a7422f26c39b8c1bec0b4fd2c

Con Kolivas 2013-05-25T12:11:26

Do a non-blocking read of anything in the avalon buffer after opening the device.

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;