Reading actual bitfilename
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
diff --git a/libztex.c b/libztex.c
index 89f5f0e..de76ac4 100644
--- a/libztex.c
+++ b/libztex.c
@@ -192,7 +192,12 @@ static int libztex_configureFpgaLS (struct libztex_device *ztex, const char* fir
int libztex_configureFpga (struct libztex_device *ztex) {
int rv;
- rv = libztex_configureFpgaLS(ztex, "bitstreams/ztex_ufm1_15d3.bit", true, 2);
+ char buf[256] = "bitstreams/";
+ memset(&buf[11], 0, 245);
+ strcpy(&buf[11], ztex->bitFileName);
+ strcpy(&buf[strlen(buf)], ".bit");
+
+ rv = libztex_configureFpgaLS(ztex, buf, true, 2);
//if (rv == 0) {
// libztex_setFreq(ztex, ztex->freqMDefault);
//}
@@ -228,6 +233,7 @@ int libztex_prepare_device (struct libusb_device *dev, struct libztex_device** z
newdev = malloc(sizeof(struct libztex_device));
newdev->valid = false;
newdev->hndl = NULL;
+ newdev->bitFileName = NULL;
*ztex = newdev;
err = libusb_get_device_descriptor(dev, &newdev->descriptor);
@@ -295,9 +301,9 @@ int libztex_prepare_device (struct libusb_device *dev, struct libztex_device** z
return cnt;
}
- if (unlikely(buf[0]) != 4) {
+ if (unlikely(!(buf[0]) == 4)) {
if (unlikely(buf[0]) != 2) {
- applog(LOG_ERR, "Invalid BTCMiner descriptor version. Firmware must be updated.");
+ applog(LOG_ERR, "Invalid BTCMiner descriptor version. Firmware must be updated (%d).", buf[0]);
return 3;
}
applog(LOG_WARNING, "Firmware out of date");
@@ -317,6 +323,10 @@ int libztex_prepare_device (struct libusb_device *dev, struct libztex_device** z
newdev->maxErrorRate[cnt] = 0;
}
+ cnt = strlen(&buf[buf[0]==4?10:8]);
+ newdev->bitFileName = malloc(sizeof(char)*(cnt+1));
+ memcpy(newdev->bitFileName, &buf[buf[0]==4?10:8], cnt+1);
+
newdev->usbbus = libusb_get_bus_number(dev);
newdev->usbaddress = libusb_get_device_address(dev);
sprintf(newdev->repr, "ZTEX %.3d:%.3d-%s", newdev->usbbus, newdev->usbaddress, newdev->snString);
@@ -328,6 +338,9 @@ void libztex_destroy_device (struct libztex_device* ztex) {
if (ztex->hndl != NULL) {
libusb_close(ztex->hndl);
}
+ if (ztex->bitFileName != NULL) {
+ free(ztex->bitFileName);
+ }
free(ztex);
}
diff --git a/libztex.h b/libztex.h
index 4b9c5de..cadd773 100644
--- a/libztex.h
+++ b/libztex.h
@@ -61,6 +61,7 @@ struct libztex_device {
uint8_t freqM;
uint8_t freqMaxM;
uint8_t freqMDefault;
+ char* bitFileName;
double errorCount[256];
double errorWeight[256];
diff --git a/todo_ztex.txt b/todo_ztex.txt
index 8bc8548..ca601a2 100644
--- a/todo_ztex.txt
+++ b/todo_ztex.txt
@@ -1,6 +1,7 @@
- verify setting cgpu.status=DEAD does in fact stop the thread
- make it compile on osx / windows
- read actual bitstream
+- allow configuring bitstream directory
- HS fpga config
- allow configuring LIBZTEX_OVERHEATTHRESHOLD
- hotplug support?