Browse Source

Bugfix: bitfury: Fix more warnings

Luke Dashjr 12 years ago
parent
commit
ed29ac1c5c
5 changed files with 29 additions and 34 deletions
  1. 10 14
      driver-bitfury.c
  2. 12 17
      libbitfury.c
  3. 3 1
      libbitfury.h
  4. 4 0
      tm_i2c.c
  5. 0 2
      tm_i2c.h

+ 10 - 14
driver-bitfury.c

@@ -39,7 +39,6 @@ double shares_to_ghashes(int shares, int seconds);
 static void bitfury_detect(void)
 {
 	int chip_n;
-	int i;
 	struct cgpu_info *bitfury_info;
 
 	bitfury_info = calloc(1, sizeof(struct cgpu_info));
@@ -66,14 +65,12 @@ static int64_t bitfury_scanHash(struct thr_info *thr)
 	int chip;
 	uint64_t hashes = 0;
 	struct timeval now;
-	unsigned char line[2048];
+	char line[2048];
 	int short_stat = 10;
 	static time_t short_out_t;
 	int long_stat = 1800;
 	static time_t long_out_t;
-	int long_long_stat = 60 * 30;
-	static time_t long_long_out_t;
-	static first = 0; //TODO Move to detect()
+	static int first = 0; //TODO Move to detect()
 	int i;
 
 	devices = thr->cgpu->devices;
@@ -150,9 +147,9 @@ static int64_t bitfury_scanHash(struct thr_info *thr)
 
 	if (now.tv_sec - short_out_t > short_stat) {
 		int shares_first = 0, shares_last = 0, shares_total = 0;
-		char stat_lines[32][256] = {0};
+		char stat_lines[32][256] = {{0}};
 		int len, k;
-		double gh[32][8] = {0};
+		double gh[32][8] = {{0}};
 		double ghsum = 0, gh1h = 0, gh2h = 0;
 
 		for (chip = 0; chip < chip_n; chip++) {
@@ -174,7 +171,7 @@ static int64_t bitfury_scanHash(struct thr_info *thr)
 			shares_last += chip > 3 ? shares_found : 0;
 		}
 		sprintf(line, "vvvvwww SHORT stat %ds: wwwvvvv", short_stat);
-		applog(LOG_WARNING, line);
+		applog(LOG_WARNING, "%s", line);
 		for(i = 0; i < 32; i++)
 			if(strlen(stat_lines[i])) {
 				len = strlen(stat_lines[i]);
@@ -187,16 +184,16 @@ static int64_t bitfury_scanHash(struct thr_info *thr)
 					ghsum += gh[i][k] + gh[i][k+4];
 				}
 				snprintf(stat_lines[i] + len, 256 - len, "- %2.1f + %2.1f = %2.1f slot %i ", gh1h, gh2h, ghsum, i);
-				applog(LOG_WARNING, stat_lines[i]);
+				applog(LOG_WARNING, "%s", stat_lines[i]);
 			}
 		short_out_t = now.tv_sec;
 	}
 
 	if (now.tv_sec - long_out_t > long_stat) {
 		int shares_first = 0, shares_last = 0, shares_total = 0;
-		char stat_lines[32][256] = {0};
+		char stat_lines[32][256] = {{0}};
 		int len, k;
-		double gh[32][8] = {0};
+		double gh[32][8] = {{0}};
 		double ghsum = 0, gh1h = 0, gh2h = 0;
 
 		for (chip = 0; chip < chip_n; chip++) {
@@ -212,7 +209,7 @@ static int64_t bitfury_scanHash(struct thr_info *thr)
 			shares_last += chip > 3 ? shares_found : 0;
 		}
 		sprintf(line, "!!!_________ LONG stat %ds: ___________!!!", long_stat);
-		applog(LOG_WARNING, line);
+		applog(LOG_WARNING, "%s", line);
 		for(i = 0; i < 32; i++)
 			if(strlen(stat_lines[i])) {
 				len = strlen(stat_lines[i]);
@@ -225,7 +222,7 @@ static int64_t bitfury_scanHash(struct thr_info *thr)
 					ghsum += gh[i][k] + gh[i][k+4];
 				}
 				snprintf(stat_lines[i] + len, 256 - len, "- %2.1f + %2.1f = %2.1f slot %i ", gh1h, gh2h, ghsum, i);
-				applog(LOG_WARNING, stat_lines[i]);
+				applog(LOG_WARNING, "%s", stat_lines[i]);
 			}
 		long_out_t = now.tv_sec;
 	}
@@ -261,7 +258,6 @@ static bool bitfury_prepare(struct thr_info *thr)
 static void bitfury_shutdown(struct thr_info *thr)
 {
 	int chip_n;
-	int i;
 
 	chip_n = thr->cgpu->chip_n;
 

+ 12 - 17
libbitfury.c

@@ -201,7 +201,6 @@ void send_init() {
 void set_freq(int bits) {
 	uint64_t freq;
 	unsigned char *osc6;
-	int i;
 
 	osc6 = (unsigned char *)&freq;
 	freq = (1ULL << bits) - 1ULL;
@@ -248,10 +247,9 @@ unsigned int c_diff(unsigned ocounter, unsigned counter) {
 
 int get_counter(unsigned int *newbuf, unsigned int *oldbuf) {
 	int j;
-	unsigned counter;
 	for(j = 0; j < 16; j++) {
 		if (newbuf[j] != oldbuf[j]) {
-			int counter = decnonce(newbuf[j]);
+			unsigned counter = decnonce(newbuf[j]);
 			if ((counter & 0xFFC00000) == 0xdf800000) {
 				counter -= 0xdf800000;
 				return counter;
@@ -266,7 +264,7 @@ int detect_chip(int chip_n) {
 	unsigned newbuf[17], oldbuf[17];
 	unsigned ocounter;
 	int odiff;
-	struct timespec t1, t2, td;
+	struct timespec t1;
 
 	memset(newbuf, 0, 17 * 4);
 	memset(oldbuf, 0, 17 * 4);
@@ -288,7 +286,6 @@ int detect_chip(int chip_n) {
 
 	ocounter = 0;
 	for (i = 0; i < BITFURY_DETECT_TRIES; i++) {
-		int j;
 		int counter;
 
 		spi_clear_buf();
@@ -302,16 +299,12 @@ int detect_chip(int chip_n) {
 		counter = get_counter(newbuf, oldbuf);
 		if (ocounter) {
 			unsigned int cdiff = c_diff(ocounter, counter);
-			unsigned per_ms;
 
-			td = t_diff(t2, t1);
-			per_ms = cdiff / (td.tv_nsec / 1000);
 			if (cdiff > 5000 && cdiff < 100000 && odiff > 5000 && odiff < 100000)
 				return 1;
 			odiff = cdiff;
 		}
 		ocounter = counter;
-		t2 = t1;
 		if (newbuf[16] != 0 && newbuf[16] != 0xFFFFFFFF) {
 			return 0;
 		}
@@ -324,7 +317,7 @@ int detect_chip(int chip_n) {
 int libbitfury_detectChips(struct bitfury_device *devices) {
 	int n = 0;
 	int i;
-	static slot_on[32];
+	static bool slot_on[32];
 	struct timespec t1, t2;
 
 	if (tm_i2c_init() < 0) {
@@ -366,7 +359,7 @@ int libbitfury_detectChips(struct bitfury_device *devices) {
 	//return 1;
 }
 
-int libbitfury_shutdownChips(struct bitfury_device *devices, int chip_n) {
+void libbitfury_shutdownChips(struct bitfury_device *devices, int chip_n) {
 	int i;
 	for (i = 0; i < chip_n; i++) {
 		send_shutdown(devices[i].slot, devices[i].fasync);
@@ -400,12 +393,13 @@ int rehash(unsigned char *midstate, unsigned m7,
 			unsigned ntime, unsigned nbits, unsigned nnonce) {
 	unsigned char in[16];
 	unsigned int *in32 = (unsigned int *)in;
-	char hex[65];
 	unsigned int *mid32 = (unsigned int *)midstate;
 	unsigned out32[8];
 	unsigned char *out = (unsigned char *) out32;
+#ifdef BITFURY_REHASH_DEBUG
 	static unsigned history[512];
 	static unsigned history_p;
+#endif
 	sha256_ctx ctx;
 
 
@@ -425,10 +419,13 @@ int rehash(unsigned char *midstate, unsigned m7,
 	sha256(out, 32, out);
 
 	if (out32[7] == 0) {
+#ifdef BITFURY_REHASH_DEBUG
+		char hex[65];
 		bin2hex(hex, out, 32);
-//		applog(LOG_INFO, "! MS0: %08x, m7: %08x, ntime: %08x, nbits: %08x, nnonce: %08x\n\t\t\t out: %s\n", mid32[0], m7, ntime, nbits, nnonce, hex);
-//		history[history_p] = nnonce;
-//		history_p++; history_p &= 512 - 1;
+		applog(LOG_INFO, "! MS0: %08x, m7: %08x, ntime: %08x, nbits: %08x, nnonce: %08x\n\t\t\t out: %s\n", mid32[0], m7, ntime, nbits, nnonce, hex);
+		history[history_p] = nnonce;
+		history_p++; history_p &= 512 - 1;
+#endif
 		return 1;
 	}
 	return 0;
@@ -460,7 +457,6 @@ void libbitfury_sendHashData(struct bitfury_device *bf, int chip_n) {
 		struct timespec d_time;
 		struct timespec time;
 		int smart = 0;
-		int i;
 		int chip = d->fasync;
 		int slot = d->slot;
 
@@ -506,7 +502,6 @@ void libbitfury_sendHashData(struct bitfury_device *bf, int chip_n) {
 				if (oldbuf[i] != newbuf[i] && op && o2p) {
 					unsigned pn; //possible nonce
 					unsigned int s = 0; //TODO zero may be solution
-					unsigned int old_f = 0;
 					if ((newbuf[i] & 0xFF) == 0xE0)
 						continue;
 					pn = decnonce(newbuf[i]);

+ 3 - 1
libbitfury.h

@@ -53,7 +53,9 @@ int libbitfury_readHashData(unsigned int *res);
 void libbitfury_sendHashData(struct bitfury_device *bf, int chip_n);
 void work_to_payload(struct bitfury_payload *p, struct work *w);
 struct timespec t_diff(struct timespec start, struct timespec end);
+extern void send_reinit(int slot, int chip_n, int n);
+extern void send_freq(int slot, int chip_n, int bits);
 int libbitfury_detectChips(struct bitfury_device *devices);
-int libbitfury_shutdownChips(struct bitfury_device *devices, int chip_n);
+void libbitfury_shutdownChips(struct bitfury_device *devices, int chip_n);
 
 #endif /* __LIBBITFURY_H__ */

+ 4 - 0
tm_i2c.c

@@ -1,9 +1,13 @@
 #include <fcntl.h>
 #include <sys/ioctl.h>
+#include <unistd.h>
+
 #include <linux/i2c.h>
 #include <linux/i2c-dev.h>
 #include "tm_i2c.h"
 
+static int tm_i2c_fd;
+
 float tm_i2c_Data2Temp(unsigned int ans) {
 	float t = ans;
 	return (t / 1023.0 * 3.3 * 2-2.73) * 100.0;

+ 0 - 2
tm_i2c.h

@@ -22,8 +22,6 @@
 #define TM_MODE_AUTO    0
 #define TM_MODE_MANUAL  1
 
-static int tm_i2c_fd;
-
 typedef struct {
 	unsigned char cmd;
 	unsigned char data_lsb;