Commit a640164381ea763199d3c45f307bb8302f6a630c

Con Kolivas 2013-05-25T14:42:38

Create an avalon_wait_write function that is used before sending avalon idle command.

diff --git a/driver-avalon.c b/driver-avalon.c
index 5eb43b2..23cda76 100644
--- a/driver-avalon.c
+++ b/driver-avalon.c
@@ -378,11 +378,24 @@ static void avalon_clear_readbuf(int fd)
 	} while (ret > 0);
 }
 
+/* Wait until the avalon says it's ready to receive a write, or 2 seconds has
+ * elapsed, whichever comes first. The status is updated by the ftdi device
+ * every 40ms. */
+static void avalon_wait_write(int fd)
+{
+	int i = 0;
+
+	while (avalon_buffer_full(fd) && i++ < 40)
+		nmsleep(50);
+}
+
 static void avalon_idle(struct cgpu_info *avalon, int fd)
 {
 	struct avalon_info *info = avalon->device_data;
 	int i;
 
+	avalon_wait_write(fd);
+
 	for (i = 0; i < info->miner_count; i++) {
 		struct avalon_task at;
 		int ret;