Commit 8fea60f384226d06b58bdea7a291ab5ff9b811ca

Con Kolivas 2013-05-27T15:01:13

Define a cts equivalent for direct usb and use it for avalon driver full.

diff --git a/driver-avalon.h b/driver-avalon.h
index 47bad5c..17e5f22 100644
--- a/driver-avalon.h
+++ b/driver-avalon.h
@@ -129,7 +129,7 @@ struct avalon_info {
 #define avalon_open(devpath, baud)  avalon_open2(devpath, baud, true)
 #define avalon_close(fd) close(fd)
 
-#define avalon_buffer_full(fd)	get_serial_cts(fd)
+#define avalon_buffer_full(avalon) !usb_ftdi_cts(avalon)
 
 #define AVALON_READ_TIME(baud) ((double)AVALON_READ_SIZE * (double)8.0 / (double)(baud))
 #define ASSERT1(condition) __maybe_unused static char sizeof_uint32_t_must_be_4[(condition)?1:-1]
diff --git a/usbutils.c b/usbutils.c
index c8323e6..f94dc84 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -2210,6 +2210,21 @@ int _usb_read(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *pro
 	return err;
 }
 
+#define FTDI_STATUS_B0_MASK     (FTDI_RS0_CTS | FTDI_RS0_DSR | FTDI_RS0_RI | FTDI_RS0_RLSD)
+#define FTDI_RS0_CTS    (1 << 4)
+#define FTDI_RS0_DSR    (1 << 5)
+#define FTDI_RS0_RI     (1 << 6)
+#define FTDI_RS0_RLSD   (1 << 7)
+
+int usb_ftdi_cts(struct cgpu_info *cgpu)
+{
+	libusb_control_transfer(usbdev->handle, (uint8_t)FTDI_TYPE_IN,
+				(uint8_t)5, (uint16_t)0, (uint16_t)0, buf, 2,
+				DEVTIMEOUT);
+	ret = buf[0] & FTDI_STATUS_B0_MASK;
+	return (ret & FTDI_RS0_CTS);
+}
+
 int _usb_write(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *processed, unsigned int timeout, __maybe_unused enum usb_cmds cmd)
 {
 	struct cg_usb_device *usbdev = cgpu->usbdev;
diff --git a/usbutils.h b/usbutils.h
index 862a208..23fdef2 100644
--- a/usbutils.h
+++ b/usbutils.h
@@ -225,6 +225,7 @@ void usb_detect(struct device_drv *drv, bool (*device_detect)(struct libusb_devi
 struct api_data *api_usb_stats(int *count);
 void update_usb_stats(struct cgpu_info *cgpu);
 int _usb_read(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *processed, unsigned int timeout, const char *end, enum usb_cmds cmd, bool readonce);
+int usb_ftdi_cts(struct cgpu_info *cgpu);
 int _usb_write(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *processed, unsigned int timeout, enum usb_cmds);
 int _usb_transfer(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint32_t *data, int siz, unsigned int timeout, enum usb_cmds cmd);
 int _usb_transfer_read(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, char *buf, int bufsiz, int *amount, unsigned int timeout, enum usb_cmds cmd);