Browse Source

FPGA - allow long or short device names in detect code + style police

nfactor-troky
Kano 12 years ago
parent
commit
ad7aa2b382
  1. 1
      README
  2. 4
      driver-bitforce.c
  3. 4
      driver-icarus.c
  4. 4
      driver-modminer.c
  5. 53
      fpgautils.c
  6. 26
      fpgautils.h

1
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, To force the code to only attempt detection with a specific driver,
prepend the argument with the driver name followed by a colon. prepend the argument with the driver name followed by a colon.
For example, "icarus:/dev/ttyUSB0" or "bitforce:\\.\COM5" 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 For other FPGA details see the FPGA-README

4
driver-bitforce.c

@ -45,8 +45,8 @@ enum {
#endif /* WIN32 */ #endif /* WIN32 */
#include "compat.h" #include "compat.h"
#include "fpgautils.h"
#include "miner.h" #include "miner.h"
#include "fpgautils.h"
#define BITFORCE_SLEEP_MS 500 #define BITFORCE_SLEEP_MS 500
#define BITFORCE_TIMEOUT_S 7 #define BITFORCE_TIMEOUT_S 7
@ -230,7 +230,7 @@ static int bitforce_detect_auto(void)
static void bitforce_detect(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) static void get_bitforce_statline_before(char *buf, struct cgpu_info *bitforce)

4
driver-icarus.c

@ -49,8 +49,8 @@
#endif #endif
#include "elist.h" #include "elist.h"
#include "fpgautils.h"
#include "miner.h" #include "miner.h"
#include "fpgautils.h"
// The serial I/O speed - Linux uses a define 'B115200' in bits/termios.h // The serial I/O speed - Linux uses a define 'B115200' in bits/termios.h
#define ICARUS_IO_SPEED 115200 #define ICARUS_IO_SPEED 115200
@ -598,7 +598,7 @@ static bool icarus_detect_one(const char *devpath)
static void icarus_detect() 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) static bool icarus_prepare(struct thr_info *thr)

4
driver-modminer.c

@ -13,9 +13,9 @@
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include "fpgautils.h"
#include "logging.h" #include "logging.h"
#include "miner.h" #include "miner.h"
#include "fpgautils.h"
#define BITSTREAM_FILENAME "fpgaminer_top_fixed7_197MHz.ncd" #define BITSTREAM_FILENAME "fpgaminer_top_fixed7_197MHz.ncd"
#define BISTREAM_USER_ID "\2\4$B" #define BISTREAM_USER_ID "\2\4$B"
@ -103,7 +103,7 @@ modminer_detect_auto()
static void static void
modminer_detect() 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__); #define bailout(...) return _bailout(-1, modminer, __VA_ARGS__);

53
fpgautils.c

@ -33,13 +33,12 @@
#endif #endif
#include "elist.h" #include "elist.h"
#include "fpgautils.h"
#include "logging.h" #include "logging.h"
#include "miner.h" #include "miner.h"
#include "fpgautils.h"
#ifdef HAVE_LIBUDEV #ifdef HAVE_LIBUDEV
int int serial_autodetect_udev(detectone_func_t detectone, const char*prodname)
serial_autodetect_udev(detectone_func_t detectone, const char*prodname)
{ {
struct udev *udev = udev_new(); struct udev *udev = udev_new();
struct udev_enumerate *enumerate = udev_enumerate_new(udev); struct udev_enumerate *enumerate = udev_enumerate_new(udev);
@ -69,15 +68,13 @@ serial_autodetect_udev(detectone_func_t detectone, const char*prodname)
return found; return found;
} }
#else #else
int int serial_autodetect_udev(__maybe_unused detectone_func_t detectone, __maybe_unused const char*prodname)
serial_autodetect_udev(__maybe_unused detectone_func_t detectone, __maybe_unused const char*prodname)
{ {
return 0; return 0;
} }
#endif #endif
int int serial_autodetect_devserial(detectone_func_t detectone, const char*prodname)
serial_autodetect_devserial(detectone_func_t detectone, const char*prodname)
{ {
#ifndef WIN32 #ifndef WIN32
DIR *D; DIR *D;
@ -107,30 +104,32 @@ serial_autodetect_devserial(detectone_func_t detectone, const char*prodname)
#endif #endif
} }
int int _serial_detect(struct device_api *api, detectone_func_t detectone, autoscan_func_t autoscan, bool forceauto)
_serial_detect(const char*dname, detectone_func_t detectone, autoscan_func_t autoscan, bool forceauto)
{ {
struct string_elist *iter, *tmp; struct string_elist *iter, *tmp;
const char*s, *p; const char *dev, *colon;
bool inhibitauto = false; bool inhibitauto = false;
char found = 0; 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) { list_for_each_entry_safe(iter, tmp, &scan_devices, list) {
s = iter->string; dev = iter->string;
if ((p = strchr(s, ':')) && p[1] != '\0') { if ((colon = strchr(dev, ':')) && colon[1] != '\0') {
size_t plen = p - s; size_t idlen = colon - dev;
if (plen != dnamel || strncasecmp(s, dname, plen))
// allow either name:device or dname:device
if ((idlen != namel || strncasecmp(dev, api->name, idlen))
&& (idlen != dnamel || strncasecmp(dev, api->dname, idlen)))
continue; continue;
s = p + 1;
dev = colon + 1;
} }
if (!strcmp(s, "auto")) if (!strcmp(dev, "auto"))
forceauto = true; forceauto = true;
else else if (!strcmp(dev, "noauto"))
if (!strcmp(s, "noauto"))
inhibitauto = true; inhibitauto = true;
else else if (detectone(dev)) {
if (detectone(s)) {
string_elist_del(iter); string_elist_del(iter);
inhibitauto = true; inhibitauto = true;
++found; ++found;
@ -311,8 +310,7 @@ void termios_debug(const char *devpath, struct termios *my_termios, const char *
#endif #endif
#endif #endif
int int serial_open(const char *devpath, unsigned long baud, signed short timeout, bool purge)
serial_open(const char*devpath, unsigned long baud, signed short timeout, bool purge)
{ {
#ifdef WIN32 #ifdef WIN32
HANDLE hSerial = CreateFile(devpath, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); 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 #endif
} }
ssize_t ssize_t _serial_read(int fd, char *buf, size_t bufsiz, char *eol)
_serial_read(int fd, char *buf, size_t bufsiz, char *eol)
{ {
ssize_t len, tlen = 0; ssize_t len, tlen = 0;
while (bufsiz) { while (bufsiz) {
@ -446,8 +443,7 @@ _serial_read(int fd, char *buf, size_t bufsiz, char *eol)
return tlen; return tlen;
} }
static FILE* static FILE *_open_bitstream(const char *path, const char *subdir, const char *filename)
_open_bitstream(const char*path, const char*subdir, const char*filename)
{ {
char fullpath[PATH_MAX]; char fullpath[PATH_MAX];
strcpy(fullpath, path); strcpy(fullpath, path);
@ -471,8 +467,7 @@ _open_bitstream(const char*path, const char*subdir, const char*filename)
_open_bitstream(path, NULL); \ _open_bitstream(path, NULL); \
} while(0) } while(0)
FILE* FILE *open_bitstream(const char *dname, const char *filename)
open_bitstream(const char*dname, const char*filename)
{ {
FILE *f; FILE *f;

26
fpgautils.h

@ -16,24 +16,24 @@
typedef bool(*detectone_func_t)(const char*); typedef bool(*detectone_func_t)(const char*);
typedef int(*autoscan_func_t)(); typedef int(*autoscan_func_t)();
extern int _serial_detect(const char*dname, detectone_func_t, autoscan_func_t, bool force_autoscan); extern int _serial_detect(struct device_api *api, detectone_func_t, autoscan_func_t, bool force_autoscan);
#define serial_detect_fauto(dname, detectone, autoscan) \ #define serial_detect_fauto(api, detectone, autoscan) \
_serial_detect(dname, detectone, autoscan, true) _serial_detect(api, detectone, autoscan, true)
#define serial_detect_auto(dname, detectone, autoscan) \ #define serial_detect_auto(api, detectone, autoscan) \
_serial_detect(dname, detectone, autoscan, false) _serial_detect(api, detectone, autoscan, false)
#define serial_detect(dname, detectone) \ #define serial_detect(api, detectone) \
_serial_detect(dname, detectone, NULL, false) _serial_detect(api, detectone, NULL, false)
extern int serial_autodetect_devserial(detectone_func_t, const char*prodname); 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_autodetect_udev(detectone_func_t, const char *prodname);
extern int serial_open(const char*devpath, unsigned long baud, signed short timeout, bool purge); 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 ssize_t _serial_read(int fd, char *buf, size_t buflen, char *eol);
#define serial_read(fd, buf, count) \ #define serial_read(fd, buf, count) \
_serial_read(fd, (char*)(buf), count, NULL) _serial_read(fd, (char*)(buf), count, NULL)
#define serial_read_line(fd, buf, bufsiz, eol) \ #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) #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 #endif

Loading…
Cancel
Save