FPGA - allow long or short device names in detect code + style police
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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
diff --git a/README b/README
index fd29dc8..36de306 100644
--- a/README
+++ b/README
@@ -239,6 +239,7 @@ The official supplied binaries are compiled with support for all FPGAs.
To force the code to only attempt detection with a specific driver,
prepend the argument with the driver name followed by a colon.
For example, "icarus:/dev/ttyUSB0" or "bitforce:\\.\COM5"
+or using the short name: "ica:/dev/ttyUSB0" or "bfl:\\.\COM5"
For other FPGA details see the FPGA-README
diff --git a/driver-bitforce.c b/driver-bitforce.c
index c1107fe..ded9e92 100644
--- a/driver-bitforce.c
+++ b/driver-bitforce.c
@@ -45,8 +45,8 @@ enum {
#endif /* WIN32 */
#include "compat.h"
-#include "fpgautils.h"
#include "miner.h"
+#include "fpgautils.h"
#define BITFORCE_SLEEP_MS 500
#define BITFORCE_TIMEOUT_S 7
@@ -230,7 +230,7 @@ static int bitforce_detect_auto(void)
static void bitforce_detect(void)
{
- serial_detect_auto(bitforce_api.dname, bitforce_detect_one, bitforce_detect_auto);
+ serial_detect_auto(&bitforce_api, bitforce_detect_one, bitforce_detect_auto);
}
static void get_bitforce_statline_before(char *buf, struct cgpu_info *bitforce)
diff --git a/driver-icarus.c b/driver-icarus.c
index 33b875d..4214c31 100644
--- a/driver-icarus.c
+++ b/driver-icarus.c
@@ -49,8 +49,8 @@
#endif
#include "elist.h"
-#include "fpgautils.h"
#include "miner.h"
+#include "fpgautils.h"
// The serial I/O speed - Linux uses a define 'B115200' in bits/termios.h
#define ICARUS_IO_SPEED 115200
@@ -598,7 +598,7 @@ static bool icarus_detect_one(const char *devpath)
static void icarus_detect()
{
- serial_detect(icarus_api.dname, icarus_detect_one);
+ serial_detect(&icarus_api, icarus_detect_one);
}
static bool icarus_prepare(struct thr_info *thr)
diff --git a/driver-modminer.c b/driver-modminer.c
index 750f9ec..d735983 100644
--- a/driver-modminer.c
+++ b/driver-modminer.c
@@ -13,9 +13,9 @@
#include <stdio.h>
#include <unistd.h>
-#include "fpgautils.h"
#include "logging.h"
#include "miner.h"
+#include "fpgautils.h"
#define BITSTREAM_FILENAME "fpgaminer_top_fixed7_197MHz.ncd"
#define BISTREAM_USER_ID "\2\4$B"
@@ -103,7 +103,7 @@ modminer_detect_auto()
static void
modminer_detect()
{
- serial_detect_auto(modminer_api.dname, modminer_detect_one, modminer_detect_auto);
+ serial_detect_auto(&modminer_api, modminer_detect_one, modminer_detect_auto);
}
#define bailout(...) return _bailout(-1, modminer, __VA_ARGS__);
diff --git a/fpgautils.c b/fpgautils.c
index 287f277..de9d93e 100644
--- a/fpgautils.c
+++ b/fpgautils.c
@@ -33,13 +33,12 @@
#endif
#include "elist.h"
-#include "fpgautils.h"
#include "logging.h"
#include "miner.h"
+#include "fpgautils.h"
#ifdef HAVE_LIBUDEV
-int
-serial_autodetect_udev(detectone_func_t detectone, const char*prodname)
+int serial_autodetect_udev(detectone_func_t detectone, const char*prodname)
{
struct udev *udev = udev_new();
struct udev_enumerate *enumerate = udev_enumerate_new(udev);
@@ -69,15 +68,13 @@ serial_autodetect_udev(detectone_func_t detectone, const char*prodname)
return found;
}
#else
-int
-serial_autodetect_udev(__maybe_unused detectone_func_t detectone, __maybe_unused const char*prodname)
+int serial_autodetect_udev(__maybe_unused detectone_func_t detectone, __maybe_unused const char*prodname)
{
return 0;
}
#endif
-int
-serial_autodetect_devserial(detectone_func_t detectone, const char*prodname)
+int serial_autodetect_devserial(detectone_func_t detectone, const char*prodname)
{
#ifndef WIN32
DIR *D;
@@ -107,30 +104,32 @@ serial_autodetect_devserial(detectone_func_t detectone, const char*prodname)
#endif
}
-int
-_serial_detect(const char*dname, detectone_func_t detectone, autoscan_func_t autoscan, bool forceauto)
+int _serial_detect(struct device_api *api, detectone_func_t detectone, autoscan_func_t autoscan, bool forceauto)
{
struct string_elist *iter, *tmp;
- const char*s, *p;
+ const char *dev, *colon;
bool inhibitauto = false;
char found = 0;
- size_t dnamel = strlen(dname);
+ size_t namel = strlen(api->name);
+ size_t dnamel = strlen(api->dname);
list_for_each_entry_safe(iter, tmp, &scan_devices, list) {
- s = iter->string;
- if ((p = strchr(s, ':')) && p[1] != '\0') {
- size_t plen = p - s;
- if (plen != dnamel || strncasecmp(s, dname, plen))
+ dev = iter->string;
+ if ((colon = strchr(dev, ':')) && colon[1] != '\0') {
+ size_t idlen = colon - dev;
+
+ // allow either name:device or dname:device
+ if ((idlen != namel || strncasecmp(dev, api->name, idlen))
+ && (idlen != dnamel || strncasecmp(dev, api->dname, idlen)))
continue;
- s = p + 1;
+
+ dev = colon + 1;
}
- if (!strcmp(s, "auto"))
+ if (!strcmp(dev, "auto"))
forceauto = true;
- else
- if (!strcmp(s, "noauto"))
+ else if (!strcmp(dev, "noauto"))
inhibitauto = true;
- else
- if (detectone(s)) {
+ else if (detectone(dev)) {
string_elist_del(iter);
inhibitauto = true;
++found;
@@ -311,8 +310,7 @@ void termios_debug(const char *devpath, struct termios *my_termios, const char *
#endif
#endif
-int
-serial_open(const char*devpath, unsigned long baud, signed short timeout, bool purge)
+int serial_open(const char *devpath, unsigned long baud, signed short timeout, bool purge)
{
#ifdef WIN32
HANDLE hSerial = CreateFile(devpath, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
@@ -429,8 +427,7 @@ serial_open(const char*devpath, unsigned long baud, signed short timeout, bool p
#endif
}
-ssize_t
-_serial_read(int fd, char *buf, size_t bufsiz, char *eol)
+ssize_t _serial_read(int fd, char *buf, size_t bufsiz, char *eol)
{
ssize_t len, tlen = 0;
while (bufsiz) {
@@ -446,8 +443,7 @@ _serial_read(int fd, char *buf, size_t bufsiz, char *eol)
return tlen;
}
-static FILE*
-_open_bitstream(const char*path, const char*subdir, const char*filename)
+static FILE *_open_bitstream(const char *path, const char *subdir, const char *filename)
{
char fullpath[PATH_MAX];
strcpy(fullpath, path);
@@ -471,8 +467,7 @@ _open_bitstream(const char*path, const char*subdir, const char*filename)
_open_bitstream(path, NULL); \
} while(0)
-FILE*
-open_bitstream(const char*dname, const char*filename)
+FILE *open_bitstream(const char *dname, const char *filename)
{
FILE *f;
diff --git a/fpgautils.h b/fpgautils.h
index 5b743bc..5c8b6bf 100644
--- a/fpgautils.h
+++ b/fpgautils.h
@@ -16,24 +16,24 @@
typedef bool(*detectone_func_t)(const char*);
typedef int(*autoscan_func_t)();
-extern int _serial_detect(const char*dname, detectone_func_t, autoscan_func_t, bool force_autoscan);
-#define serial_detect_fauto(dname, detectone, autoscan) \
- _serial_detect(dname, detectone, autoscan, true)
-#define serial_detect_auto(dname, detectone, autoscan) \
- _serial_detect(dname, detectone, autoscan, false)
-#define serial_detect(dname, detectone) \
- _serial_detect(dname, detectone, NULL, false)
-extern int serial_autodetect_devserial(detectone_func_t, const char*prodname);
-extern int serial_autodetect_udev (detectone_func_t, const char*prodname);
+extern int _serial_detect(struct device_api *api, detectone_func_t, autoscan_func_t, bool force_autoscan);
+#define serial_detect_fauto(api, detectone, autoscan) \
+ _serial_detect(api, detectone, autoscan, true)
+#define serial_detect_auto(api, detectone, autoscan) \
+ _serial_detect(api, detectone, autoscan, false)
+#define serial_detect(api, detectone) \
+ _serial_detect(api, detectone, NULL, false)
+extern int serial_autodetect_devserial(detectone_func_t, const char *prodname);
+extern int serial_autodetect_udev(detectone_func_t, const char *prodname);
-extern int serial_open(const char*devpath, unsigned long baud, signed short timeout, bool purge);
-extern ssize_t _serial_read(int fd, char *buf, size_t buflen, char*eol);
+extern int serial_open(const char *devpath, unsigned long baud, signed short timeout, bool purge);
+extern ssize_t _serial_read(int fd, char *buf, size_t buflen, char *eol);
#define serial_read(fd, buf, count) \
_serial_read(fd, (char*)(buf), count, NULL)
#define serial_read_line(fd, buf, bufsiz, eol) \
- _serial_read(fd, buf, count, &eol)
+ _serial_read(fd, buf, bufsiz, &eol)
#define serial_close(fd) close(fd)
-extern FILE*open_bitstream(const char*dname, const char*filename);
+extern FILE *open_bitstream(const char *dname, const char *filename);
#endif