Browse Source

Merge pull request #273 from kanoi/bfl

BFL force all code to timeout to avoid hanging
nfactor-troky
Con Kolivas 12 years ago
parent
commit
458fbeb5b4
  1. 16
      driver-bitforce.c
  2. 10
      fpgautils.c

16
driver-bitforce.c

@ -34,13 +34,15 @@
struct device_api bitforce_api; struct device_api bitforce_api;
#define BFopen(devpath) serial_open(devpath, 0, -1, true) // Code must deal with a timeout
#define BFopen(devpath) serial_open(devpath, 0, 1, true)
static void BFgets(char *buf, size_t bufLen, int fd) static void BFgets(char *buf, size_t bufLen, int fd)
{ {
do do {
buf[0] = '\0';
--bufLen; --bufLen;
while (likely(bufLen && read(fd, buf, 1) == 1 && (buf++)[0] != '\n')); } while (likely(bufLen && read(fd, buf, 1) == 1 && (buf++)[0] != '\n'));
buf[0] = '\0'; buf[0] = '\0';
} }
@ -72,7 +74,7 @@ static bool bitforce_detect_one(const char *devpath)
BFwrite(fdDev, "ZGX", 3); BFwrite(fdDev, "ZGX", 3);
BFgets(pdevbuf, sizeof(pdevbuf), fdDev); BFgets(pdevbuf, sizeof(pdevbuf), fdDev);
if (unlikely(!pdevbuf[0])) { if (unlikely(!pdevbuf[0])) {
applog(LOG_ERR, "BFL: Error reading (ZGX)"); applog(LOG_ERR, "BFL: Error reading/timeout (ZGX)");
return 0; return 0;
} }
@ -200,7 +202,7 @@ void bitforce_init(struct cgpu_info *bitforce)
if (unlikely(!pdevbuf[0])) { if (unlikely(!pdevbuf[0])) {
mutex_unlock(&bitforce->device_mutex); mutex_unlock(&bitforce->device_mutex);
applog(LOG_ERR, "BFL%i: Error reading (ZGX)", bitforce->device_id); applog(LOG_ERR, "BFL%i: Error reading/timeout (ZGX)", bitforce->device_id);
return; return;
} }
@ -240,7 +242,7 @@ static bool bitforce_get_temp(struct cgpu_info *bitforce)
mutex_unlock(&bitforce->device_mutex); mutex_unlock(&bitforce->device_mutex);
if (unlikely(!pdevbuf[0])) { if (unlikely(!pdevbuf[0])) {
applog(LOG_ERR, "BFL%i: Error: Get temp returned empty string", bitforce->device_id); applog(LOG_ERR, "BFL%i: Error: Get temp returned empty string/timed out", bitforce->device_id);
bitforce->temp = 0; bitforce->temp = 0;
return false; return false;
} }
@ -328,7 +330,7 @@ re_send:
} }
if (unlikely(!pdevbuf[0])) { if (unlikely(!pdevbuf[0])) {
applog(LOG_ERR, "BFL%i: Error: Send block data returned empty string", bitforce->device_id); applog(LOG_ERR, "BFL%i: Error: Send block data returned empty string/timed out", bitforce->device_id);
return false; return false;
} }

10
fpgautils.c

@ -178,7 +178,8 @@ serial_open(const char*devpath, unsigned long baud, signed short timeout, bool p
SetCommConfig(hSerial, &comCfg, sizeof(comCfg)); SetCommConfig(hSerial, &comCfg, sizeof(comCfg));
const DWORD ctoms = (timeout == -1) ? 30000 : (timeout * 100); // Code must specify a valid timeout value (0 means don't timeout)
const DWORD ctoms = (timeout * 100);
COMMTIMEOUTS cto = {ctoms, 0, ctoms, 0, ctoms}; COMMTIMEOUTS cto = {ctoms, 0, ctoms, 0, ctoms};
SetCommTimeouts(hSerial, &cto); SetCommTimeouts(hSerial, &cto);
@ -230,10 +231,9 @@ serial_open(const char*devpath, unsigned long baud, signed short timeout, bool p
my_termios.c_oflag &= ~OPOST; my_termios.c_oflag &= ~OPOST;
my_termios.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); my_termios.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
if (timeout >= 0) { // Code must specify a valid timeout value (0 means don't timeout)
my_termios.c_cc[VTIME] = (cc_t)timeout; my_termios.c_cc[VTIME] = (cc_t)timeout;
my_termios.c_cc[VMIN] = 0; my_termios.c_cc[VMIN] = 0;
}
tcsetattr(fdDev, TCSANOW, &my_termios); tcsetattr(fdDev, TCSANOW, &my_termios);
if (purge) if (purge)

Loading…
Cancel
Save