Browse Source

Fix the buffer statu

Xiangfu 13 years ago
parent
commit
e45523c2e8
2 changed files with 46 additions and 50 deletions
  1. 30 30
      driver-avalon.c
  2. 16 20
      driver-avalon.h

+ 30 - 30
driver-avalon.c

@@ -72,8 +72,7 @@ static int avalon_init_task(struct avalon_task *at,
 	at->chip_num = (chip_num ? chip_num : AVALON_DEFAULT_CHIP_NUM);
 	at->miner_num = (miner_num ? miner_num : AVALON_DEFAULT_MINER_NUM);
 
-	/* Only send nonce_elf after RESET checkout the avalon_reset() */
-	at->nonce_elf = (reset ? 1 : 0);	/* 1: nonce_range*/
+	at->nonce_elf = 1;
 
 	return 0;
 }
@@ -92,34 +91,35 @@ static int avalon_send_task(int fd, const struct avalon_task *at)
 	uint8_t *buff;
 	int nr_len;
 
-	if (unlikely(at->reset)) {
-		nr_len = AVALON_WRITE_SIZE + 4 * at->miner_num;
-		buff = calloc(1, AVALON_WRITE_SIZE + nr_len);
-		if (!buff)
-			return AVA_SEND_ERROR;
-
-		memcpy(buff, at, AVALON_WRITE_SIZE);
-		if (opt_debug) {
-			applog(LOG_DEBUG, "Avalon: Sent:");
-			hexdump((uint8_t *)buff, nr_len);
-		}
-		ret = write(fd, buff, nr_len);
-		free(buff);
-		if (unlikely(ret != nr_len))
-			return AVA_SEND_ERROR;
-
-	} else {
-		buff = (uint8_t *)at;
-		ret = write(fd, (uint8_t *)at, AVALON_WRITE_SIZE);
-
-		if (opt_debug) {
-			applog(LOG_DEBUG, "Avalon: Sent:");
-			hexdump((uint8_t *)at, AVALON_WRITE_SIZE);
-		}
-
-		if (unlikely(ret != AVALON_WRITE_SIZE))
-			return AVA_SEND_ERROR;
+	nr_len = AVALON_WRITE_SIZE + 4 * at->chip_num;
+	buff = calloc(1, AVALON_WRITE_SIZE + nr_len);
+	if (!buff)
+		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]);
+#endif
+	if (at->reset)
+		buff[0] = 0x1d;
+	buff[2] = 0x3c;
+	buff[4] = 0x01;
+	if (opt_debug) {
+		applog(LOG_DEBUG, "Avalon: Sent(%d):", nr_len);
+		hexdump((uint8_t *)buff, nr_len);
 	}
+	ret = write(fd, buff, nr_len);
+	free(buff);
+	if (unlikely(ret != nr_len))
+		return AVA_SEND_ERROR;
 
 	p.tv_sec = 0;
 	p.tv_nsec = AVALON_SEND_WORK_PITCH;
@@ -663,6 +663,7 @@ static int64_t avalon_scanhash(struct thr_info *thr, struct work **bulk_work,
 	bulk0 = bulk1;
 	bulk1 = bulk2;
 	bulk2 = bulk_work;
+	i = 0;
 	while (true) {
 		avalon_init_default_task(&at);
 		avalon_create_task(&at, work[i++]);
@@ -677,7 +678,6 @@ static int64_t avalon_scanhash(struct thr_info *thr, struct work **bulk_work,
 			dev_error(avalon, REASON_DEV_COMMS_ERROR);
 			return 0;	/* This should never happen */
 		}
-		break;
 		if (ret == AVA_SEND_BUFFER_FULL) {
 			break;
 		}

+ 16 - 20
driver-avalon.h

@@ -32,7 +32,7 @@ struct avalon_result {
 	uint32_t nonce;
 	uint8_t data[12];
 	uint8_t midstate[32];
-	uint8_t reserved[8];
+	uint8_t reserved[16];
 } __attribute__((packed));
 
 struct AVALON_HISTORY {
@@ -79,12 +79,12 @@ struct AVALON_INFO {
 };
 
 #define AVALON_MINER_THREADS 1
-#define AVALON_GET_WORK_COUNT 1 // 24
+#define AVALON_GET_WORK_COUNT 3 // 24
 
 #define AVALON_IO_SPEED 19200 // 115200
 #define AVALON_SEND_WORK_PITCH 4000 /* 4ms */
 
-#define AVALON_DEFAULT_MINER_NUM 0x18
+#define AVALON_DEFAULT_MINER_NUM AVALON_GET_WORK_COUNT
 #define AVALON_DEFAULT_CHIP_NUM 0xA
 #define AVALON_DEFAULT_FAN_PWM 0x98
 #define AVALON_DEFAULT_TIMEOUT 0x27
@@ -99,20 +99,16 @@ ASSERT1(sizeof(uint32_t) == 4);
 #define AVALON_READ_TIME(baud) ((double)AVALON_READ_SIZE * (double)8.0 / (double)(baud))
 
 #define TIME_FACTOR 10
-
 #define AVALON_RESET_FAULT_DECISECONDS 1
-
 #define AVALON_READ_COUNT_TIMING	(5 * TIME_FACTOR)
 
 //#define AVALON_HASH_TIME 0.0000000000155
 #define AVALON_HASH_TIME (0.0000000026316)
-
 #define NANOSEC 1000000000.0
 
 #define HISTORY_SEC 60
 #define MIN_DATA_COUNT 5
 #define MAX_MIN_DATA_COUNT 100
-
 #define END_CONDITION 0x0000ffff
 
 #define AVA_GETS_ERROR -1
@@ -128,24 +124,24 @@ ASSERT1(sizeof(uint32_t) == 4);
 #define avalon_open2(devpath, baud, purge)  serial_open(devpath, baud, AVALON_RESET_FAULT_DECISECONDS, purge)
 #define avalon_open(devpath, baud)  avalon_open2(devpath, baud, true)
 
-#define avalon_init_default_task(at) avalon_init_task(at, 0, 0, 0, 0, 0, 0)
+#define avalon_init_default_task(at) avalon_init_task(at, 0, 0, 0, 0x3c, 1, 3)
 #define avalon_close(fd) close(fd)
 
-#define AVA_BUFFER_FULL 1
-#define AVA_BUFFER_EMPTY 0
+#define AVA_BUFFER_FULL 0
+#define AVA_BUFFER_EMPTY 1
 #define avalon_buffer_full(fd)	get_serial_cts(fd)
 
-static void rev(unsigned char *s, size_t l)
+static inline uint8_t rev8(uint8_t d)
 {
-	size_t i, j;
-	unsigned char t;
-
-	for (i = 0, j = l - 1; i < j; i++, j--) {
-		t = s[i];
-		s[i] = s[j];
-		s[j] = t;
-	}
-}
+    int i;
+    uint8_t out = 0;
+
+    /* (from left to right) */
+    for (i = 0; i < 8; i++)
+        if (d & (1 << i))
+            out |= (1 << (7 - i));
 
+    return out;
+}
 
 #endif	/* AVALON_H */