Create and destroy a basic bxf read thread.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
diff --git a/driver-bitfury.c b/driver-bitfury.c
index 993ec7d..eec35dc 100644
--- a/driver-bitfury.c
+++ b/driver-bitfury.c
@@ -232,6 +232,54 @@ static void bitfury_detect(bool __maybe_unused hotplug)
usb_detect(&bitfury_drv, bitfury_detect_one);
}
+static void *bxf_get_results(void *userdata)
+{
+ struct cgpu_info *bitfury = userdata;
+ struct bitfury_info *info = bitfury->device_data;
+ char threadname[24];
+
+ snprintf(threadname, 24, "bxf_recv/%d", bitfury->device_id);
+
+ while (likely(!bitfury->shutdown)) {
+ int err, amount;
+ char buf[512];
+
+ if (unlikely(bitfury->usbinfo.nodev))
+ break;
+
+ err = usb_read_nl(bitfury, buf, 512, &amount, C_BXF_READ);
+ if (err) {
+ if (err != LIBUSB_ERROR_TIMEOUT)
+ break;
+ continue;
+ }
+ }
+ return NULL;
+}
+
+static bool bxf_prepare(struct cgpu_info *bitfury, struct bitfury_info *info)
+{
+ mutex_init(&info->lock);
+ if (pthread_create(&info->read_thr, NULL, bxf_get_results, (void *)bitfury))
+ quit(1, "Failed to create bxf read_thr");
+ return true;
+}
+
+static bool bitfury_prepare(struct thr_info *thr)
+{
+ struct cgpu_info *bitfury = thr->cgpu;
+ struct bitfury_info *info = bitfury->device_data;
+
+ switch(info->ident) {
+ case IDENT_BXF:
+ return bxf_prepare(bitfury, info);
+ break;
+ case IDENT_BF1:
+ default:
+ return true;
+ }
+}
+
static uint32_t decnonce(uint32_t in)
{
uint32_t out;
@@ -448,6 +496,12 @@ static void bitfury_init(struct cgpu_info *bitfury)
}
}
+static void bxf_close(struct bitfury_info *info)
+{
+ pthread_join(info->read_thr, NULL);
+ mutex_destroy(&info->lock);
+}
+
static void bitfury_shutdown(struct thr_info *thr)
{
struct cgpu_info *bitfury = thr->cgpu;
@@ -458,6 +512,8 @@ static void bitfury_shutdown(struct thr_info *thr)
bf1_close(bitfury);
break;
case IDENT_BXF:
+ bxf_close(info);
+ break;
default:
break;
}
@@ -469,6 +525,7 @@ struct device_drv bitfury_drv = {
.dname = "bitfury",
.name = "BF1",
.drv_detect = bitfury_detect,
+ .thread_prepare = bitfury_prepare,
.hash_work = &hash_driver_work,
.scanwork = bitfury_scanwork,
.get_api_stats = bitfury_api_stats,
diff --git a/driver-bitfury.h b/driver-bitfury.h
index dc16e50..cb75341 100644
--- a/driver-bitfury.h
+++ b/driver-bitfury.h
@@ -26,6 +26,10 @@ struct bitfury_info {
char product[8];
uint32_t serial;
struct timeval tv_start;
+
+ /* BXF specific data */
+ pthread_mutex_t lock;
+ pthread_t read_thr;
};
#endif /* BITFURY_H */
diff --git a/usbutils.h b/usbutils.h
index 3fbc9cb..2ab4733 100644
--- a/usbutils.h
+++ b/usbutils.h
@@ -343,6 +343,7 @@ struct cg_usb_info {
USB_ADD_COMMAND(C_BF1_FLUSH, "BF1Flush") \
USB_ADD_COMMAND(C_BF1_IFLUSH, "BF1InterruptFlush") \
USB_ADD_COMMAND(C_BF1_IDENTIFY, "BF1Identify") \
+ USB_ADD_COMMAND(C_BXF_READ, "BXFRead") \
USB_ADD_COMMAND(C_HF_RESET, "HFReset") \
USB_ADD_COMMAND(C_HF_PLL_CONFIG, "HFPLLConfig") \
USB_ADD_COMMAND(C_HF_ADDRESS, "HFAddress") \