Browse Source

Use common bitfury_decnonce for all bitfury-based devices

Luke Dashjr 12 years ago
parent
commit
657bb1a615
4 changed files with 9 additions and 32 deletions
  1. 2 24
      driver-bigpic.c
  2. 2 4
      driver-bitfury.c
  3. 4 4
      libbitfury.c
  4. 1 0
      libbitfury.h

+ 2 - 24
driver-bigpic.c

@@ -16,6 +16,7 @@
 #include "fpgautils.h"
 #include "logging.h"
 
+#include "libbitfury.h"
 #include "deviceapi.h"
 #include "sha2.h"
 
@@ -25,29 +26,6 @@
 
 struct device_drv bigpic_drv;
 
-//------------------------------------------------------------------------------
-uint32_t bigpic_decnonce(uint32_t in)
-{
-	uint32_t out;
-
-	/* First part load */
-	out = (in & 0xFF) << 24; in >>= 8;
-
-	/* Byte reversal */
-	in = (((in & 0xaaaaaaaa) >> 1) | ((in & 0x55555555) << 1));
-	in = (((in & 0xcccccccc) >> 2) | ((in & 0x33333333) << 2));
-	in = (((in & 0xf0f0f0f0) >> 4) | ((in & 0x0f0f0f0f) << 4));
-
-	out |= (in >> 2)&0x3FFFFF;
-
-	/* Extraction */
-	if (in & 1) out |= (1 << 23);
-	if (in & 2) out |= (1 << 22);
-
-	out -= 0x800004;
-	return out;
-}
-
 //------------------------------------------------------------------------------
 int bigpic_rehash(unsigned char *midstate, unsigned m7, unsigned ntime, unsigned nbits, unsigned nnonce)
 {
@@ -255,7 +233,7 @@ static void bigpic_process_results(struct thr_info *thr, struct work *work)
 			continue;
 		}
 
-		uint32_t nonce = bigpic_decnonce(state.nonce);
+		uint32_t nonce = bitfury_decnonce(state.nonce);
 		results[num_results++] = state.nonce;
 
 		//applog(LOG_DEBUG, "%"PRIpreprv": Len: %d Cmd: %c State: %c Switched: %d Nonce: %08X", board->proc_repr, info->rx_len, info->rx_buffer[i], state->state, state->switched, nonce);

+ 2 - 4
driver-bitfury.c

@@ -89,8 +89,6 @@ void *bitfury_just_io(struct bitfury_device * const bitfury)
 	return spi_getrxbuf(spi) + 4 + chip;
 }
 
-extern unsigned decnonce(unsigned);
-
 static
 void bitfury_debug_nonce_array(const struct cgpu_info * const proc, const char *msg, const uint32_t * const inp)
 {
@@ -101,7 +99,7 @@ void bitfury_debug_nonce_array(const struct cgpu_info * const proc, const char *
 	for (int i = 0; i < 0x10; ++i)
 		sp += sprintf(sp, "%c%08lx",
 		              (active == i) ? '>' : ' ',
-		              (unsigned long)decnonce(inp[i]));
+		              (unsigned long)bitfury_decnonce(inp[i]));
 	applog(LOG_DEBUG, "%"PRIpreprv": %s%s (job=%08lx)",
 	       proc->proc_repr, msg, s, (unsigned long)inp[0x10]);
 }
@@ -505,7 +503,7 @@ void bitfury_do_io(struct thr_info *thr)
 	{
 		for (i = 0; i < n; ++i)
 		{
-			nonce = decnonce(newbuf[i]);
+			nonce = bitfury_decnonce(newbuf[i]);
 			if (fudge_nonce(thr->work, &nonce))
 			{
 				applog(LOG_DEBUG, "%"PRIpreprv": nonce %x = %08lx (work=%p)",

+ 4 - 4
libbitfury.c

@@ -41,7 +41,7 @@
 #define BITFURY_REFRESH_DELAY 100
 #define BITFURY_DETECT_TRIES 3000 / BITFURY_REFRESH_DELAY
 
-unsigned decnonce(unsigned in);
+unsigned bitfury_decnonce(unsigned in);
 
 /* Configuration registers - control oscillators and such stuff. PROGRAMMED when magic number is matches, UNPROGRAMMED (default) otherwise */
 void config_reg(struct spi_port *port, int cfgreg, int ena)
@@ -211,7 +211,7 @@ int get_counter(unsigned int *newbuf, unsigned int *oldbuf) {
 	int j;
 	for(j = 0; j < 16; j++) {
 		if (newbuf[j] != oldbuf[j]) {
-			unsigned counter = decnonce(newbuf[j]);
+			unsigned counter = bitfury_decnonce(newbuf[j]);
 			if ((counter & 0xFFC00000) == 0xdf800000) {
 				counter -= 0xdf800000;
 				return counter;
@@ -315,7 +315,7 @@ int libbitfury_detectChips1(struct spi_port *port) {
 }
 
 // in  = 1f 1e 1d 1c 1b 1a 19 18 17 16 15 14 13 12 11 10  f  e  d  c  b  a  9  8  7  6  5  4  3  2  1  0
-unsigned decnonce(unsigned in)
+unsigned bitfury_decnonce(unsigned in)
 {
 	unsigned out;
 
@@ -494,7 +494,7 @@ void libbitfury_sendHashData1(int chip_id, struct bitfury_device *d, struct thr_
 				uint32_t pn;  // possible nonce
 				if ((newbuf[i] & 0xFF) == 0xE0)
 					continue;
-				pn = decnonce(newbuf[i]);
+				pn = bitfury_decnonce(newbuf[i]);
 				if (fudge_nonce(op->midstate, op->m7, op->ntime, op->nbits, &pn))
 				{
 					int k;

+ 1 - 0
libbitfury.h

@@ -68,5 +68,6 @@ extern void send_reinit(struct spi_port *, int slot, int chip_n, int n);
 extern void send_shutdown(struct spi_port *, int slot, int chip_n);
 extern void send_freq(struct spi_port *, int slot, int chip_n, int bits);
 extern int libbitfury_detectChips1(struct spi_port *);
+extern unsigned bitfury_decnonce(unsigned);
 
 #endif /* __LIBBITFURY_H__ */