Browse Source

Merge branch 'erupter' into bfgminer

Luke Dashjr 12 years ago
parent
commit
b6a14f1f4f
6 changed files with 95 additions and 115 deletions
  1. 4 0
      Makefile.am
  2. 2 17
      driver-avalon.c
  3. 5 10
      driver-icarus.c
  4. 46 88
      fpgautils.c
  5. 1 0
      fpgautils.h
  6. 37 0
      iospeeds.h

+ 4 - 0
Makefile.am

@@ -156,6 +156,10 @@ endif # HAS_CPUMINE
 
 if NEED_FPGAUTILS
 bfgminer_SOURCES += fpgautils.c fpgautils.h
+if HAVE_WINDOWS
+else
+bfgminer_SOURCES += iospeeds.h
+endif
 endif
 
 if NEED_DYNCLOCK

+ 2 - 17
driver-avalon.c

@@ -458,23 +458,8 @@ static void get_options(int this_option_offset, int *baud, int *miner_count,
 		*(colon++) = '\0';
 
 	tmp = atoi(buf);
-	switch (tmp) {
-	case 115200:
-		*baud = 115200;
-		break;
-	case 57600:
-		*baud = 57600;
-		break;
-	case 38400:
-		*baud = 38400;
-		break;
-	case 19200:
-		*baud = 19200;
-		break;
-	default:
-		quit(1, "Invalid avalon-options for baud (%s) "
-			"must be 115200, 57600, 38400 or 19200", buf);
-	}
+	if (!valid_baud(*baud = tmp))
+		quit(1, "Invalid avalon-options for baud (%s)", buf);
 
 	if (colon && *colon) {
 		colon2 = strchr(colon, ':');

+ 5 - 10
driver-icarus.c

@@ -472,16 +472,8 @@ static void get_options(int this_option_offset, struct ICARUS_INFO *info)
 
 		if (*buf) {
 			tmp = atoi(buf);
-			switch (tmp) {
-			case 115200:
-				*baud = 115200;
-				break;
-			case 57600:
-				*baud = 57600;
-				break;
-			default:
-				quit(1, "Invalid icarus-options for baud (%s) must be 115200 or 57600", buf);
-			}
+			if (!valid_baud(*baud = tmp))
+				quit(1, "Invalid icarus-options for baud (%s)", buf);
 		}
 
 		if (colon && *colon) {
@@ -630,6 +622,9 @@ static bool icarus_detect_one(const char *devpath)
 	if (unlikely(!info))
 		quit(1, "Failed to malloc ICARUS_INFO");
 
+	// TODO: try some higher speeds with the Icarus and BFL to see
+	// if they support them and if setting them makes any difference
+	// N.B. B3000000 doesn't work on Icarus
 	info->baud = ICARUS_IO_SPEED;
 	info->quirk_reopen = 1;
 	info->Hs = ICARUS_REV3_HASH_TIME;

+ 46 - 88
fpgautils.c

@@ -643,68 +643,12 @@ struct device_drv *bfg_claim_usb(struct device_drv * const api, const bool verbo
 int tiospeed(speed_t speed)
 {
 	switch (speed) {
-	case B0:
-		return 0;
-	case B50:
-		return 50;
-	case B75:
-		return 75;
-	case B110:
-		return 110;
-	case B134:
-		return 134;
-	case B150:
-		return 150;
-	case B200:
-		return 200;
-	case B300:
-		return 300;
-	case B600:
-		return 600;
-	case B1200:
-		return 1200;
-	case B1800:
-		return 1800;
-	case B2400:
-		return 2400;
-	case B4800:
-		return 4800;
-	case B9600:
-		return 9600;
-	case B19200:
-		return 19200;
-	case B38400:
-		return 38400;
-	case B57600:
-		return 57600;
-	case B115200:
-		return 115200;
-	case B230400:
-		return 230400;
-	case B460800:
-		return 460800;
-	case B500000:
-		return 500000;
-	case B576000:
-		return 576000;
-	case B921600:
-		return 921600;
-	case B1000000:
-		return 1000000;
-	case B1152000:
-		return 1152000;
-	case B1500000:
-		return 1500000;
-	case B2000000:
-		return 2000000;
-	case B2500000:
-		return 2500000;
-	case B3000000:
-		return 3000000;
-	case B3500000:
-		return 3500000;
-	case B4000000:
-		return 4000000;
+#define IOSPEED(baud)  \
+		case B ## baud:  \
+			return baud;  \
+// END
+#include "iospeeds.h"
+#undef IOSPEED
 	default:
 		return -1;
 	}
@@ -794,8 +738,37 @@ void termios_debug(const char *devpath, struct termios *my_termios, const char *
 #endif
 			);
 }
-#endif
-#endif
+#endif  /* TERMIOS_DEBUG */
+
+speed_t tiospeed_t(int baud)
+{
+	switch (baud) {
+#define IOSPEED(baud)  \
+		case baud:  \
+			return B ## baud;  \
+// END
+#include "iospeeds.h"
+#undef IOSPEED
+	default:
+		return B0;
+	}
+}
+
+#endif  /* WIN32 */
+
+bool valid_baud(int baud)
+{
+	switch (baud) {
+#define IOSPEED(baud)  \
+		case baud:  \
+			return true;  \
+// END
+#include "iospeeds.h"
+#undef IOSPEED
+		default:
+			return false;
+	}
+}
 
 /* NOTE: Linux only supports uint8_t (decisecond) timeouts; limiting it in
  *       this interface buys us warnings when bad constants are passed in.
@@ -868,30 +841,15 @@ int serial_open(const char *devpath, unsigned long baud, uint8_t timeout, bool p
 	termios_debug(devpath, &my_termios, "before");
 #endif
 
-	switch (baud) {
-	case 0:
-		break;
-	case 19200:
-		cfsetispeed(&my_termios, B19200);
-		cfsetospeed(&my_termios, B19200);
-		break;
-	case 38400:
-		cfsetispeed(&my_termios, B38400);
-		cfsetospeed(&my_termios, B38400);
-		break;
-	case 57600:
-		cfsetispeed(&my_termios, B57600);
-		cfsetospeed(&my_termios, B57600);
-		break;
-	case 115200:
-		cfsetispeed(&my_termios, B115200);
-		cfsetospeed(&my_termios, B115200);
-		break;
-	// TODO: try some higher speeds with the Icarus and BFL to see
-	// if they support them and if setting them makes any difference
-	// N.B. B3000000 doesn't work on Icarus
-	default:
-		applog(LOG_WARNING, "Unrecognized baud rate: %lu", baud);
+	{
+		speed_t speed = tiospeed_t(baud);
+		if (speed == B0)
+			applog(LOG_WARNING, "Unrecognized baud rate: %lu", baud);
+		else
+		{
+			cfsetispeed(&my_termios, speed);
+			cfsetospeed(&my_termios, speed);
+		}
 	}
 
 	my_termios.c_cflag &= ~(CSIZE | PARENB);

+ 1 - 0
fpgautils.h

@@ -57,5 +57,6 @@ extern FILE *open_bitstream(const char *dname, const char *filename);
 extern FILE *open_xilinx_bitstream(const char *dname, const char *repr, const char *fwfile, unsigned long *out_len);
 
 extern int get_serial_cts(int fd);
+extern bool valid_baud(int baud);
 
 #endif

+ 37 - 0
iospeeds.h

@@ -0,0 +1,37 @@
+IOSPEED(0)
+IOSPEED(50)
+IOSPEED(110)
+IOSPEED(134)
+IOSPEED(200)
+
+IOSPEED(75)
+IOSPEED(150)
+IOSPEED(300)
+IOSPEED(600)
+IOSPEED(1200)
+IOSPEED(1800)
+IOSPEED(2400)
+IOSPEED(4800)
+IOSPEED(9600)
+IOSPEED(19200)
+IOSPEED(38400)
+
+IOSPEED(57600)
+IOSPEED(115200)
+IOSPEED(230400)
+IOSPEED(460800)
+IOSPEED(921600)
+
+IOSPEED(576000)
+IOSPEED(1152000)
+
+IOSPEED(1500000)
+IOSPEED(3000000)
+
+IOSPEED(500000)
+IOSPEED(1000000)
+IOSPEED(2000000)
+IOSPEED(4000000)
+
+IOSPEED(2500000)
+IOSPEED(3500000)