Browse Source

bitfury: spi_emit_data: Return address read data will be located at after txrx

Luke Dashjr 12 years ago
parent
commit
76ca59ff0e
3 changed files with 12 additions and 8 deletions
  1. 3 2
      driver-bitfury.c
  2. 8 5
      spidevc.c
  3. 1 1
      spidevc.h

+ 3 - 2
driver-bitfury.c

@@ -80,13 +80,14 @@ void *bitfury_just_io(struct bitfury_device * const bitfury)
 {
 	struct spi_port * const spi = bitfury->spi;
 	const int chip = bitfury->fasync;
+	void *rv;
 	
 	spi_clear_buf(spi);
 	spi_emit_break(spi);
 	spi_emit_fasync(spi, chip);
-	spi_emit_data(spi, 0x3000, &bitfury->atrvec[0], 19 * 4);
+	rv = spi_emit_data(spi, 0x3000, &bitfury->atrvec[0], 19 * 4);
 	spi_txrx(spi);
-	return spi_getrxbuf(spi) + 4 + chip;
+	return rv;
 }
 
 static

+ 8 - 5
spidevc.c

@@ -202,11 +202,12 @@ bool sys_spi_txrx(struct spi_port *port)
 #endif
 
 static
-void spi_emit_buf_reverse(struct spi_port *port, const void *p, size_t sz)
+void *spi_emit_buf_reverse(struct spi_port *port, const void *p, size_t sz)
 {
 	const unsigned char *str = p;
+	void * const rv = &port->spibuf_rx[port->spibufsz];
 	if (port->spibufsz + sz >= SPIMAXSZ)
-		return;
+		return NULL;
 	for (size_t i = 0; i < sz; ++i)
 	{
 		// Reverse bit order in each byte!
@@ -216,6 +217,7 @@ void spi_emit_buf_reverse(struct spi_port *port, const void *p, size_t sz)
 		p = ((p & 0xf0)>>4) | ((p & 0x0f) << 4);
 		port->spibuf[port->spibufsz++] = p;
 	}
+	return rv;
 }
 
 static
@@ -253,15 +255,16 @@ void spi_emit_nop(struct spi_port *port, int n) {
 	}
 }
 
-void spi_emit_data(struct spi_port *port, uint16_t addr, const void *buf, size_t len)
+void *spi_emit_data(struct spi_port *port, uint16_t addr, const void *buf, size_t len)
 {
 	unsigned char otmp[3];
-	if (len < 4 || len > 128) return; /* This cannot be programmed in single frame! */
+	if (len < 4 || len > 128)
+		return NULL;  /* This cannot be programmed in single frame! */
 	len /= 4; /* Strip */
 	otmp[0] = (len - 1) | 0xE0;
 	otmp[1] = (addr >> 8)&0xFF; otmp[2] = addr & 0xFF;
 	spi_emit_buf(port, otmp, 3);
-	spi_emit_buf_reverse(port, buf, len*4);
+	return spi_emit_buf_reverse(port, buf, len*4);
 }
 
 #ifdef HAVE_LINUX_SPI

+ 1 - 1
spidevc.h

@@ -62,7 +62,7 @@ extern void spi_emit_nop(struct spi_port *port, int n);
    buf is buffer to be transmitted, it will go at position spi_getbufsz()+3
    len is length in _bytes_, should be 4 to 128 and be multiple of 4, as smallest
    transmission quantum is 32 bits */
-extern void spi_emit_data(struct spi_port *port, uint16_t addr, const void *buf, size_t len);
+extern void *spi_emit_data(struct spi_port *port, uint16_t addr, const void *buf, size_t len);
 
 static inline
 bool spi_txrx(struct spi_port *port)