Implement a nanofury txrx with a larger buffer and cycling over data too large to send.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
diff --git a/driver-bitfury.c b/driver-bitfury.c
index d1cc5da..e1a5338 100644
--- a/driver-bitfury.c
+++ b/driver-bitfury.c
@@ -294,7 +294,7 @@ static void spi_clear_buf(struct bitfury_info *info)
static void spi_add_buf(struct bitfury_info *info, const void *buf, const int sz)
{
- if (unlikely(info->spibufsz + sz > MCP2210_BUFFER_LENGTH)) {
+ if (unlikely(info->spibufsz + sz > NF1_SPIBUF_SIZE)) {
applog(LOG_WARNING, "SPI bufsize overflow!");
return;
}
@@ -421,7 +421,6 @@ static bool nf1_set_gpio_output(struct cgpu_info *bitfury, int pin, int val)
static bool nf1_spi_reset(struct cgpu_info *bitfury)
{
char buf[1] = {0x81}; // will send this waveform: - _ _ _ _ _ _ -
- unsigned int length = 1;
int r;
// SCK_OVRRIDE
@@ -429,6 +428,7 @@ static bool nf1_spi_reset(struct cgpu_info *bitfury)
return false;
for (r = 0; r < 16; ++r) {
+ unsigned int length = 1;
if (!mcp2210_spi_transfer(bitfury, buf, &length))
return false;
}
@@ -439,6 +439,40 @@ static bool nf1_spi_reset(struct cgpu_info *bitfury)
return true;
}
+static bool nf1_spi_txrx(struct cgpu_info *bitfury, struct bitfury_info *info)
+{
+ unsigned int length, sendrcv;
+ int offset = 0, roffset = 0;
+
+ if (!nf1_spi_reset(bitfury))
+ return false;
+ length = info->spibufsz;
+ applog(LOG_DEBUG, "%s %d: SPI sending %u bytes", bitfury->drv->name, bitfury->device_id,
+ length);
+ while (length > MCP2210_TRANSFER_MAX) {
+ sendrcv = MCP2210_TRANSFER_MAX;
+ if (!mcp2210_spi_transfer(bitfury, info->spibuf + offset, &sendrcv))
+ return false;
+ if (sendrcv != MCP2210_TRANSFER_MAX) {
+ applog(LOG_DEBUG, "%s %d: Send/Receive size mismatch sent %d received %d",
+ bitfury->drv->name, bitfury->device_id, MCP2210_TRANSFER_MAX, sendrcv);
+ }
+ length -= MCP2210_TRANSFER_MAX;
+ offset += MCP2210_TRANSFER_MAX;
+ roffset += sendrcv;
+ }
+ sendrcv = length;
+ if (!mcp2210_spi_transfer(bitfury, info->spibuf + offset, &sendrcv))
+ return false;
+ if (sendrcv != length) {
+ applog(LOG_WARNING, "%s %d: Send/Receive size mismatch sent %d received %d",
+ bitfury->drv->name, bitfury->device_id, length, sendrcv);
+ }
+ roffset += sendrcv;
+ info->spibufsz = roffset;
+ return true;
+}
+
static void nf1_reinit(struct cgpu_info *bitfury, struct bitfury_info *info)
{
spi_clear_buf(info);
@@ -446,7 +480,7 @@ static void nf1_reinit(struct cgpu_info *bitfury, struct bitfury_info *info)
nf1_set_freq(info);
nf1_send_conf(info);
nf1_send_init(info);
- //nf1_txrx(bitfury, info);
+ nf1_spi_txrx(bitfury, info);
}
static bool nf1_detect_one(struct cgpu_info *bitfury, struct bitfury_info *info)
diff --git a/driver-bitfury.h b/driver-bitfury.h
index bf2677d..6a80e07 100644
--- a/driver-bitfury.h
+++ b/driver-bitfury.h
@@ -29,6 +29,8 @@ extern int opt_bxf_temp_target;
#define NF1_PIN_SCK_OVR 5
#define NF1_PIN_PWR_EN 6
+#define NF1_SPIBUF_SIZE 16384
+
struct bitfury_info {
struct cgpu_info *base_cgpu;
struct thr_info *thr;
@@ -65,8 +67,8 @@ struct bitfury_info {
int submits[2]; // Submitted responses
/* NF1 specific data */
- char spibuf[MCP2210_BUFFER_LENGTH];
- int spibufsz;
+ char spibuf[NF1_SPIBUF_SIZE];
+ unsigned int spibufsz;
int osc6_bits;
};
diff --git a/mcp2210.c b/mcp2210.c
index b9ee4ff..6cc0806 100644
--- a/mcp2210.c
+++ b/mcp2210.c
@@ -299,12 +299,14 @@ bool mcp2210_spi_transfer(struct cgpu_info *cgpu, char *data, unsigned int *leng
char buf[MCP2210_BUFFER_LENGTH];
uint8_t res;
- if (unlikely(*length > 60 || !*length)) {
+ if (unlikely(*length > MCP2210_TRANSFER_MAX || !*length)) {
applog(LOG_ERR, "%s %d: Unable to spi transfer %u bytes", cgpu->drv->name,
cgpu->device_id, *length);
return false;
}
retry:
+ applog(LOG_DEBUG, "%s %d: SPI sending %u bytes", cgpu->drv->name, cgpu->device_id,
+ *length);
memset(buf, 0, MCP2210_BUFFER_LENGTH);
buf[0] = MCP2210_SPI_TRANSFER;
buf[1] = *length;
@@ -317,10 +319,14 @@ retry:
switch(res) {
case MCP2210_SPI_TRANSFER_SUCCESS:
*length = buf[2];
+ applog(LOG_DEBUG, "%s %d: SPI transfer success, received %u bytes",
+ cgpu->drv->name, cgpu->device_id, *length);
if (*length)
memcpy(data, buf + 4, *length);
return true;
case MCP2210_SPI_TRANSFER_ERROR_IP:
+ applog(LOG_DEBUG, "%s %d: SPI transfer error in progress",
+ cgpu->drv->name, cgpu->device_id);
cgsleep_ms(40);
goto retry;
case MCP2210_SPI_TRANSFER_ERROR_NA:
diff --git a/mcp2210.h b/mcp2210.h
index b65cac5..62019c9 100644
--- a/mcp2210.h
+++ b/mcp2210.h
@@ -11,6 +11,7 @@
#define MCP2210_H
#define MCP2210_BUFFER_LENGTH 64
+#define MCP2210_TRANSFER_MAX 60
#define MCP2210_PIN_GPIO 0x0
#define MCP2210_PIN_CS 0x1