|
|
@ -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; |
|
|
|
|
|
|
|
|
|
|
|