Commit f3d406ec72aee0850a91c1a3f24a00acf57550d1

Con Kolivas 2013-11-06T22:22:43

Use usbutils' own cps function for slowing rate of usb writes on avalon.

diff --git a/driver-avalon.c b/driver-avalon.c
index 7cced1f..f63f881 100644
--- a/driver-avalon.c
+++ b/driver-avalon.c
@@ -146,9 +146,7 @@ static int avalon_send_task(const struct avalon_task *at, struct cgpu_info *aval
 
 {
 	uint8_t buf[AVALON_WRITE_SIZE + 4 * AVALON_DEFAULT_ASIC_NUM];
-	int delay, ret, i, ep = C_AVALON_TASK;
-	struct avalon_info *info;
-	cgtimer_t ts_start;
+	int ret, i, ep = C_AVALON_TASK;
 	uint32_t nonce_range;
 	size_t nr_len;
 
@@ -189,10 +187,6 @@ static int avalon_send_task(const struct avalon_task *at, struct cgpu_info *aval
 	tt |= ((buf[4] & 0x80) ? (1 << 0) : 0);
 	buf[4] = tt;
 #endif
-	info = avalon->device_data;
-	delay = nr_len * 10 * 1000000;
-	delay = delay / info->baud;
-	delay += 4000;
 
 	if (at->reset) {
 		ep = C_AVALON_RESET;
@@ -202,11 +196,7 @@ static int avalon_send_task(const struct avalon_task *at, struct cgpu_info *aval
 		applog(LOG_DEBUG, "Avalon: Sent(%u):", (unsigned int)nr_len);
 		hexdump(buf, nr_len);
 	}
-	cgsleep_prepare_r(&ts_start);
 	ret = avalon_write(avalon, (char *)buf, nr_len, ep);
-	cgsleep_us_r(&ts_start, delay);
-
-	applog(LOG_DEBUG, "Avalon: Sent: Buffer delay: %dus", delay);
 
 	return ret;
 }
@@ -216,7 +206,6 @@ static int bitburner_send_task(const struct avalon_task *at, struct cgpu_info *a
 {
 	uint8_t buf[AVALON_WRITE_SIZE + 4 * AVALON_DEFAULT_ASIC_NUM];
 	int ret, ep = C_AVALON_TASK;
-	cgtimer_t ts_start;
 	size_t nr_len;
 
 	if (at->nonce_elf)
@@ -253,9 +242,7 @@ static int bitburner_send_task(const struct avalon_task *at, struct cgpu_info *a
 		applog(LOG_DEBUG, "Avalon: Sent(%u):", (unsigned int)nr_len);
 		hexdump(buf, nr_len);
 	}
-	cgsleep_prepare_r(&ts_start);
 	ret = avalon_write(avalon, (char *)buf, nr_len, ep);
-	cgsleep_us_r(&ts_start, 3000); // 3 ms = 333 tasks per second, or 1.4 TH/s
 
 	return ret;
 }
@@ -825,6 +812,9 @@ static bool avalon_detect_one(libusb_device *dev, struct usb_find_devices *found
 	if (!add_cgpu(avalon))
 		goto unshin;
 
+	usb_set_cps(avalon, info->baud / 10);
+	usb_enable_cps(avalon);
+
 	ret = avalon_reset(avalon, true);
 	if (ret && !configured)
 		goto unshin;