Browse Source

Merge commit 'ad7aa2b' into cgmerges

Conflicts:
	driver-icarus.c
	fpgautils.c
	fpgautils.h
Luke Dashjr 13 years ago
parent
commit
69f6a94230
8 changed files with 52 additions and 54 deletions
  1. 1 0
      README
  2. 2 2
      driver-bitforce.c
  3. 1 1
      driver-cairnsmore.c
  4. 2 2
      driver-icarus.c
  5. 2 2
      driver-modminer.c
  6. 1 1
      driver-ztex.c
  7. 26 31
      fpgautils.c
  8. 17 15
      fpgautils.h

+ 1 - 0
README

@@ -246,6 +246,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
 

+ 2 - 2
driver-bitforce.c

@@ -19,8 +19,8 @@
 #include "config.h"
 
 #include "compat.h"
-#include "fpgautils.h"
 #include "miner.h"
+#include "fpgautils.h"
 
 #define BITFORCE_SLEEP_MS 500
 #define BITFORCE_TIMEOUT_S 7
@@ -126,7 +126,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)

+ 1 - 1
driver-cairnsmore.c

@@ -51,7 +51,7 @@ static int cairnsmore_detect_auto(void)
 static void cairnsmore_detect()
 {
 	// Actual serial detection is handled by Icarus driver
-	serial_detect_auto_byname(cairnsmore_api.dname, cairnsmore_detect_one, cairnsmore_detect_auto);
+	serial_detect_auto_byname(&cairnsmore_api, cairnsmore_detect_one, cairnsmore_detect_auto);
 }
 
 void convert_icarus_to_cairnsmore(struct cgpu_info *cm1)

+ 2 - 2
driver-icarus.c

@@ -55,9 +55,9 @@
 #endif
 
 #include "elist.h"
-#include "fpgautils.h"
 #include "icarus-common.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
@@ -633,7 +633,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);
 }
 
 struct icarus_state {

+ 2 - 2
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"
@@ -138,7 +138,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__);

+ 1 - 1
driver-ztex.c

@@ -118,7 +118,7 @@ static int ztex_autodetect(void)
 static void ztex_detect()
 {
 	// This wrapper ensures users can specify -S ztex:noauto to disable it
-	noserial_detect(ztex_api.dname, ztex_autodetect);
+	noserial_detect(&ztex_api, ztex_autodetect);
 }
 
 static bool ztex_updateFreq(struct libztex_device* ztex)

+ 26 - 31
fpgautils.c

@@ -51,13 +51,12 @@ enum {
 #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);
@@ -87,15 +86,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;
@@ -208,32 +205,35 @@ int serial_autodetect_ftdi(__maybe_unused detectone_func_t detectone, __maybe_un
 
 struct device_api *serial_claim(const char *devpath, struct device_api *api);
 
-int
-_serial_detect(const char*dname, detectone_func_t detectone, autoscan_func_t autoscan, int flags)
+int _serial_detect(struct device_api *api, detectone_func_t detectone, autoscan_func_t autoscan, int flags)
 {
 	struct string_elist *iter, *tmp;
-	const char*s, *p;
+	const char *dev, *colon;
 	bool inhibitauto = false;
 	char found = 0;
 	bool forceauto = flags & 1;
 	bool hasname;
-	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;
 			hasname = true;
 		}
 		else
 			hasname = false;
-		if (!strcmp(s, "auto"))
+		if (!strcmp(dev, "auto"))
 			forceauto = true;
-		else
-		if (!strcmp(s, "noauto"))
+		else if (!strcmp(dev, "noauto"))
 			inhibitauto = true;
 		else
 		if ((flags & 2) && !hasname)
@@ -242,13 +242,12 @@ _serial_detect(const char*dname, detectone_func_t detectone, autoscan_func_t aut
 		if (!detectone)
 		{}  // do nothing
 		else
-		if (serial_claim(s, NULL))
+		if (serial_claim(dev, NULL))
 		{
-			applog(LOG_DEBUG, "%s is already claimed... skipping probes", s);
+			applog(LOG_DEBUG, "%s is already claimed... skipping probes", dev);
 			string_elist_del(iter);
 		}
-		else
-		if (detectone(s)) {
+		else if (detectone(dev)) {
 			string_elist_del(iter);
 			inhibitauto = true;
 			++found;
@@ -482,8 +481,7 @@ void termios_debug(const char *devpath, struct termios *my_termios, const char *
 /* NOTE: Linux only supports uint8_t (decisecond) timeouts; limiting it in
  *       this interface buys us warnings when bad constants are passed in.
  */
-int
-serial_open(const char*devpath, unsigned long baud, uint8_t timeout, bool purge)
+int serial_open(const char *devpath, unsigned long baud, uint8_t timeout, bool purge)
 {
 #ifdef WIN32
 	HANDLE hSerial = CreateFile(devpath, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
@@ -600,8 +598,7 @@ serial_open(const char*devpath, unsigned long baud, uint8_t timeout, bool purge)
 #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) {
@@ -617,8 +614,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);
@@ -642,8 +638,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;
 

+ 17 - 15
fpgautils.h

@@ -15,34 +15,36 @@
 #include <stdio.h>
 #include <unistd.h>
 
+struct device_api;
+
 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, int flags);
-#define serial_detect_fauto(dname, detectone, autoscan)  \
-	_serial_detect(dname, detectone, autoscan, 1)
-#define serial_detect_auto(dname, detectone, autoscan)  \
-	_serial_detect(dname, detectone, autoscan, 0)
-#define serial_detect_auto_byname(dname, detectone, autoscan)  \
-	_serial_detect(dname, detectone, autoscan, 2)
-#define serial_detect(dname, detectone)  \
-	_serial_detect(dname, detectone,     NULL, 0)
-#define noserial_detect(dname, autoscan)  \
-	_serial_detect(dname, NULL     , autoscan, 0)
+extern int _serial_detect(struct device_api *api, detectone_func_t, autoscan_func_t, int flags);
+#define serial_detect_fauto(api, detectone, autoscan)  \
+	_serial_detect(api, detectone, autoscan, 1)
+#define serial_detect_auto(api, detectone, autoscan)  \
+	_serial_detect(api, detectone, autoscan, 0)
+#define serial_detect_auto_byname(api, detectone, autoscan)  \
+	_serial_detect(api, detectone, autoscan, 2)
+#define serial_detect(api, detectone)  \
+	_serial_detect(api, detectone,     NULL, 0)
+#define noserial_detect(api, autoscan)  \
+	_serial_detect(api, NULL     , autoscan, 0)
 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_ftdi     (detectone_func_t, const char*needle, const char *needle2);
 
 extern struct device_api *serial_claim(const char *devpath, struct device_api *);
 
-extern int serial_open(const char*devpath, unsigned long baud, uint8_t 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, uint8_t 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