Browse Source

lowl-spi: linux_spi_txrx2 to include device protocol dumping

Luke Dashjr 11 years ago
parent
commit
7c2a4f1d73
2 changed files with 30 additions and 0 deletions
  1. 29 0
      lowl-spi.c
  2. 1 0
      lowl-spi.h

+ 29 - 0
lowl-spi.c

@@ -50,6 +50,8 @@
 
 
 #include "logging.h"
 #include "logging.h"
 #include "lowl-spi.h"
 #include "lowl-spi.h"
+#include "miner.h"
+#include "util.h"
 
 
 #ifdef HAVE_LINUX_SPI
 #ifdef HAVE_LINUX_SPI
 bool sys_spi_txrx(struct spi_port *port);
 bool sys_spi_txrx(struct spi_port *port);
@@ -253,6 +255,33 @@ bool linux_spi_txrx(struct spi_port * const spi)
 	return (ioctl(fd, SPI_IOC_MESSAGE(1), &xf) > 0);
 	return (ioctl(fd, SPI_IOC_MESSAGE(1), &xf) > 0);
 }
 }
 
 
+bool linux_spi_txrx2(struct spi_port * const spi)
+{
+	const size_t bufsz = spi_getbufsz(spi);
+	
+	if (opt_dev_protocol)
+	{
+		const void * const txbuf = spi_gettxbuf(spi);
+		char hex[(bufsz * 2) + 1];
+		bin2hex(hex, txbuf, bufsz);
+		applog(LOG_DEBUG, "%s: %cX %s", spi->repr, 'T', hex);
+	}
+	bool rv = linux_spi_txrx(spi);
+	if (opt_dev_protocol)
+	{
+		if (likely(rv))
+		{
+			void * const rxbuf = spi_getrxbuf(spi);
+			char hex[(bufsz * 2) + 1];
+			bin2hex(hex, rxbuf, bufsz);
+			applog(LOG_DEBUG, "%s: %cX %s", spi->repr, 'R', hex);
+		}
+		else
+			applog(LOG_DEBUG, "%s: SPI ERROR", spi->repr);
+	}
+	return rv;
+}
+
 #endif
 #endif
 
 
 static
 static

+ 1 - 0
lowl-spi.h

@@ -91,6 +91,7 @@ bool spi_txrx(struct spi_port *port)
 extern int spi_open(struct spi_port *, const char *);
 extern int spi_open(struct spi_port *, const char *);
 extern bool sys_spi_txrx(struct spi_port *);
 extern bool sys_spi_txrx(struct spi_port *);
 extern bool linux_spi_txrx(struct spi_port *);
 extern bool linux_spi_txrx(struct spi_port *);
+extern bool linux_spi_txrx2(struct spi_port *);
 
 
 void spi_bfsb_select_bank(int bank);
 void spi_bfsb_select_bank(int bank);