Commit efd179fd736f597712f6a49e1251f964fc6bef2b

Con Kolivas 2014-01-03T11:42:44

Create a generic mcp2210 send_rcv function.

diff --git a/mcp2210.c b/mcp2210.c
index 2edf4d2..0d4ae5c 100644
--- a/mcp2210.c
+++ b/mcp2210.c
@@ -6,4 +6,33 @@
  * Software Foundation; either version 3 of the License, or (at your option)
  * any later version.  See COPYING for more details.
  */
+#include "miner.h"
+#include "usbutils.h"
+#include "mcp2210.h"
 
+bool mcp2210_send_recv(struct cgpu_info *cgpu, char *buf, enum usb_cmds send_cmd,
+		       enum usb_cmds recv_cmd)
+{
+	int amount, err;
+
+	if (unlikely(cgpu->usbinfo.nodev))
+		return false;
+
+	err = usb_write(cgpu, buf, MCP2210_BUFFER_LENGTH, &amount, send_cmd);
+	if (err || amount != MCP2210_BUFFER_LENGTH) {
+		applog(LOG_WARNING, "%s %d: Error %d sending %s sent %d of %d",
+		       cgpu->drv->name, cgpu->device_id, err, usb_cmdname(send_cmd),
+		       amount, MCP2210_BUFFER_LENGTH);
+		return false;
+	}
+
+	err = usb_read(cgpu, buf, MCP2210_BUFFER_LENGTH, &amount, recv_cmd);
+	if (err || amount != MCP2210_BUFFER_LENGTH) {
+		applog(LOG_WARNING, "%s %d: Error %d receiving %s received %d of %d",
+		       cgpu->drv->name, cgpu->device_id, err, usb_cmdname(recv_cmd),
+		       amount, MCP2210_BUFFER_LENGTH);
+		return false;
+	}
+
+	return true;
+}
diff --git a/mcp2210.h b/mcp2210.h
index 53d2a34..937a978 100644
--- a/mcp2210.h
+++ b/mcp2210.h
@@ -29,4 +29,6 @@
 #define MCP2210_SPI_TRANSFER_ERROR_NA	0xF7	// SPI not available due to external owner
 #define MCP2210_SPI_TRANSFER_ERROR_IP	0xF8	// SPI not available due to transfer in progress
 
+bool mcp2210_send_recv(struct cgpu_info *cgpu, char *buf, enum usb_cmds send_cmd,
+		       enum usb_cmds recv_cmd);
 #endif /* MCP2210_H */