Browse Source

fix the BIG_ENDIAN issue

Xiangfu 13 years ago
parent
commit
f871230153
2 changed files with 17 additions and 22 deletions
  1. 16 21
      driver-avalon.c
  2. 1 1
      driver-avalon.h

+ 16 - 21
driver-avalon.c

@@ -88,36 +88,31 @@ static int avalon_send_task(int fd, const struct avalon_task *at)
 	size_t ret;
 	size_t ret;
 	int full;
 	int full;
 	struct timespec p;
 	struct timespec p;
-	uint8_t *buff;
+	uint8_t *buf;
 	int nr_len;
 	int nr_len;
 
 
 	nr_len = AVALON_WRITE_SIZE + 4 * at->chip_num;
 	nr_len = AVALON_WRITE_SIZE + 4 * at->chip_num;
-	buff = calloc(1, AVALON_WRITE_SIZE + nr_len);
-	if (!buff)
+	buf = calloc(1, AVALON_WRITE_SIZE + nr_len);
+	if (!buf)
 		return AVA_SEND_ERROR;
 		return AVA_SEND_ERROR;
 
 
-	memcpy(buff, at, AVALON_WRITE_SIZE);
-	/* FIXME: */
-#if defined (__BIG_ENDIAN__) || defined(MIPSEB)
-	uint8_t t = 0;
-	t = (buff[0] & 0xf0) >> 4;
-	t |= ((buff[0] & (0x1 << 0)) >> 0);
-	t |= ((buff[0] & (0x1 << 1)) >> 1);
-	t |= ((buff[0] & (0x1 << 2)) >> 2);
-	t |= ((buff[0] & (0x1 << 3)) >> 3);
-	buff[0] = t;
-	buff[4] = rev8(buff[4]);
+	memcpy(buf, at, AVALON_WRITE_SIZE);
+#if defined(__BIG_ENDIAN__) || defined(MIPSEB)
+	uint8_t tt = 0;
+	tt = (buf[0] & 0x0f) << 4;
+	tt |= ((buf[0] & 0x10) ? (1 << 3) : 0);
+	tt |= ((buf[0] & 0x20) ? (1 << 2) : 0);
+	tt |= ((buf[0] & 0x40) ? (1 << 1) : 0);
+	tt |= ((buf[0] & 0x80) ? (1 << 0) : 0);
+	buf[0] = tt;
+	buf[4] = rev8(buf[4]);
 #endif
 #endif
-	if (at->reset)
-		buff[0] = 0x1d;
-	buff[2] = 0x3c;
-	buff[4] = 0x01;
 	if (opt_debug) {
 	if (opt_debug) {
 		applog(LOG_DEBUG, "Avalon: Sent(%d):", nr_len);
 		applog(LOG_DEBUG, "Avalon: Sent(%d):", nr_len);
-		hexdump((uint8_t *)buff, nr_len);
+		hexdump((uint8_t *)buf, nr_len);
 	}
 	}
-	ret = write(fd, buff, nr_len);
-	free(buff);
+	ret = write(fd, buf, nr_len);
+	free(buf);
 	if (unlikely(ret != nr_len))
 	if (unlikely(ret != nr_len))
 		return AVA_SEND_ERROR;
 		return AVA_SEND_ERROR;
 
 

+ 1 - 1
driver-avalon.h

@@ -82,7 +82,7 @@ struct AVALON_INFO {
 #define AVALON_GET_WORK_COUNT 3 // 24
 #define AVALON_GET_WORK_COUNT 3 // 24
 
 
 #define AVALON_IO_SPEED 19200 // 115200
 #define AVALON_IO_SPEED 19200 // 115200
-#define AVALON_SEND_WORK_PITCH 4000 /* 4ms */
+#define AVALON_SEND_WORK_PITCH 40000000 /* 4ms */
 
 
 #define AVALON_DEFAULT_MINER_NUM AVALON_GET_WORK_COUNT
 #define AVALON_DEFAULT_MINER_NUM AVALON_GET_WORK_COUNT
 #define AVALON_DEFAULT_CHIP_NUM 0xA
 #define AVALON_DEFAULT_CHIP_NUM 0xA