Browse Source

gridseed: Refactor code to clean up and organize

Nate Woolls 11 years ago
parent
commit
b8b29fd9c5
3 changed files with 35 additions and 35 deletions
  1. 33 31
      driver-gridseed.c
  2. 1 3
      gc3355.c
  3. 1 1
      gc3355.h

+ 33 - 31
driver-gridseed.c

@@ -67,6 +67,38 @@ void gridseed_empty_work(int fd)
 	gc3355_read(fd, (char *)buf, GC3355_READ_SIZE);
 }
 
+static
+struct thr_info *gridseed_thread_by_chip(const struct cgpu_info * const device, uint32_t const chip)
+{
+	const struct cgpu_info *proc = device_proc_by_id(device, chip);
+	if (unlikely(!proc))
+		proc = device;
+	return proc->thr[0];
+}
+
+static
+int64_t gridseed_calculate_chip_hashes(struct thr_info *thr)
+{
+	struct cgpu_info *device = thr->cgpu;
+	struct gc3355_info *info = device->device_data;
+	struct timeval old_scanhash_time = info->scanhash_time;
+
+	timer_set_now(&info->scanhash_time);
+	int elapsed_ms = ms_tdiff(&info->scanhash_time, &old_scanhash_time);
+
+	return GRIDSEED_HASH_SPEED * (double)elapsed_ms * (double)(info->freq);
+}
+
+static
+void gridseed_hashes_done(struct thr_info *thr)
+{
+	struct cgpu_info *device = thr->cgpu;
+	int64_t chip_hashes = gridseed_calculate_chip_hashes(thr);
+
+	for (struct cgpu_info *proc = device; proc; proc = proc->next_proc)
+		hashes_done2(proc->thr[0], chip_hashes, NULL);
+}
+
 /*
  * device detection
  */
@@ -198,43 +230,16 @@ void gridseed_submit_nonce(struct thr_info * const thr, const unsigned char buf[
 	nonce = le32toh(nonce);
 	uint32_t chip = nonce / ((uint32_t)0xffffffff / device->procs);
 	
-	const struct cgpu_info *proc = device_proc_by_id(device, chip);
-	if (unlikely(!proc))
-		proc = device;
-	struct thr_info *proc_thr = proc->thr[0];
+	struct thr_info *proc_thr = gridseed_thread_by_chip(device, chip);
 	
 	submit_nonce(proc_thr, work, nonce);
 }
 
-static
-int64_t gridseed_calculate_chip_hashes(struct thr_info *thr)
-{
-	struct cgpu_info *device = thr->cgpu;
-	struct gc3355_info *info = device->device_data;
-	struct timeval old_scanhash_time = info->scanhash_time;
-
-	timer_set_now(&info->scanhash_time);
-	int elapsed_ms = ms_tdiff(&info->scanhash_time, &old_scanhash_time);
-
-	return GRIDSEED_HASH_SPEED * (double)elapsed_ms * (double)(info->freq);
-}
-
-static
-void gridseed_hashes_done(struct thr_info *thr)
-{
-	struct cgpu_info *device = thr->cgpu;
-	int64_t chip_hashes = gridseed_calculate_chip_hashes(thr);
-	
-	for (struct cgpu_info *proc = device; proc; proc = proc->next_proc)
-		hashes_done2(proc->thr[0], chip_hashes, NULL);
-}
-
 // read from device for nonce or command
 static
 int64_t gridseed_scanhash(struct thr_info *thr, struct work *work, int64_t __maybe_unused max_nonce)
 {
 	struct cgpu_info *device = thr->cgpu;
-
 	unsigned char buf[GC3355_READ_SIZE];
 	int read = 0;
 	int fd = device->device_fd;
@@ -242,10 +247,7 @@ int64_t gridseed_scanhash(struct thr_info *thr, struct work *work, int64_t __may
 	while (!thr->work_restart && (read = gc3355_read(fd, (char *)buf, GC3355_READ_SIZE)) > 0)
 	{
 		if ((buf[0] == 0x55) && (buf[1] == 0x20))
-		{
-			// LTC result
 			gridseed_submit_nonce(thr, buf, work);
-		}
 		else
 		{
 			applog(LOG_ERR, "%"PRIpreprv": Unrecognized response", device->proc_repr);

+ 1 - 3
gc3355.c

@@ -388,7 +388,7 @@ void gc3355_log_protocol(int fd, const char *buf, size_t size, const char *prefi
 	       GC3355_CHIP_NAME, fd, prefix, (unsigned long)size, hex);
 }
 
-int gc3355_read(int fd, char *buf, size_t size)
+ssize_t gc3355_read(int fd, char *buf, size_t size)
 {
 	size_t read;
 	int tries = 20;
@@ -621,9 +621,7 @@ int64_t gc3355_get_firmware_version(int fd)
 	
 	// firmware response begins with 55aac000 90909090
 	if (memcmp(buf, "\x55\xaa\xc0\x00\x90\x90\x90\x90", GC3355_READ_SIZE - 4) != 0)
-	{
 		return -1;
-	}
 	
 	uint32_t fw_version = be32toh(*(uint32_t *)(buf + 8));
 	

+ 1 - 1
gc3355.h

@@ -41,7 +41,7 @@ struct gc3355_info
 #define gc3355_open(path)  serial_open(path, 115200, 1, true)
 #define gc3355_close(fd)  serial_close(fd)
 
-extern int gc3355_read(int fd, char *buf, size_t size);
+extern ssize_t gc3355_read(int fd, char *buf, size_t size);
 extern ssize_t gc3355_write(int fd, const void * const buf, const size_t size);
 
 extern void gc3355_init_miner(int fd, int pll_freq);