Browse Source

dualminer: No need to parse strings for SHA2 unit counts

Nate Woolls 12 years ago
parent
commit
abf3826935
3 changed files with 38 additions and 41 deletions
  1. 17 1
      driver-dualminer.c
  2. 14 36
      gc3355.c
  3. 7 4
      gc3355.h

+ 17 - 1
driver-dualminer.c

@@ -42,6 +42,9 @@
 #define DUALMINER_SCRYPT_READ_COUNT 48  // 4.8s to read
 #define DUALMINER_SCRYPT_READ_COUNT 48  // 4.8s to read
 #define DUALMINER_SHA2_READ_COUNT	16  // 1.6s to read
 #define DUALMINER_SHA2_READ_COUNT	16  // 1.6s to read
 
 
+#define DUALMINER_0_9V_SHA2_UNITS  60
+#define DUALMINER_1_2V_SHA2_UNITS   0
+
 static
 static
 const char sha2_golden_ob[] =
 const char sha2_golden_ob[] =
 	"55aa0f00a08701004a548fe471fa3a9a"
 	"55aa0f00a08701004a548fe471fa3a9a"
@@ -122,7 +125,20 @@ void dualminer_init_firstrun(struct cgpu_info *icarus)
 	if (opt_scrypt)
 	if (opt_scrypt)
 		set_serial_rts(fd, BGV_HIGH);
 		set_serial_rts(fd, BGV_HIGH);
 
 
-	gc3355_init(fd, opt_dualminer_sha2_gating, !opt_dual_mode);
+	if (opt_sha2_units == -1)
+	{
+		if (gc3355_get_cts_status(fd) == 1)
+		{
+			//1.2v - Scrypt mode
+			opt_sha2_units = DUALMINER_1_2V_SHA2_UNITS;
+		}
+		else
+		{
+			//0.9v - Scrypt + SHA mode
+			opt_sha2_units = DUALMINER_0_9V_SHA2_UNITS;
+		}
+	}
+	gc3355_init(fd, opt_sha2_units, !opt_dual_mode);
 	applog(LOG_DEBUG, "%"PRIpreprv": scrypt: %d, scrypt only: %d\n", icarus->proc_repr, opt_scrypt, opt_scrypt);
 	applog(LOG_DEBUG, "%"PRIpreprv": scrypt: %d, scrypt only: %d\n", icarus->proc_repr, opt_scrypt, opt_scrypt);
 
 
 	if (gc3355_get_cts_status(fd) != 1)
 	if (gc3355_get_cts_status(fd) != 1)

+ 14 - 36
gc3355.c

@@ -26,8 +26,10 @@
   #include <io.h>
   #include <io.h>
 #endif
 #endif
 
 
-#define DEFAULT_0_9V_sha2 "60"
-#define DEFAULT_1_2V_sha2 "0"
+// options configurable by the end-user
+
+int opt_sha2_units = -1;
+
 
 
 // SHA-2 commands
 // SHA-2 commands
 
 
@@ -224,7 +226,6 @@ const char *scrypt_only_init_cmd[] =
 	NULL
 	NULL
 };
 };
 
 
-char *opt_dualminer_sha2_gating = NULL;
 int opt_pll_freq = 0; // default is set in gc3355_set_pll_freq
 int opt_pll_freq = 0; // default is set in gc3355_set_pll_freq
 int opt_sha2_number = 160;
 int opt_sha2_number = 160;
 bool opt_dual_mode = false;
 bool opt_dual_mode = false;
@@ -424,25 +425,21 @@ void gc3355_open_sha2_unit(int fd, char *opt_sha2_gating)
 }
 }
 
 
 static
 static
-void gc3355_open_sha2_unit_one_by_one(int fd, char *opt_sha2_gating)
+void gc3355_open_sha2_units(int fd, int sha2_units)
 {
 {
 	int unit_count = 0;
 	int unit_count = 0;
 	unsigned char ob_bin[8];
 	unsigned char ob_bin[8];
 	int i;
 	int i;
 
 
-	unit_count = atoi(opt_sha2_gating);
-
-	if (unit_count < 0)
-		unit_count = 0;
-	if (unit_count > 160)
-		unit_count = 160;
+	// should be 0 - 160
+	unit_count = sha2_units < 0 ? 0 : sha2_units > 160 ? 160 : sha2_units;
 
 
-	if (unit_count > 0 && unit_count <= 160)
+	if (unit_count > 0)
 	{
 	{
 		for(i = 0; i <= unit_count; i++)
 		for(i = 0; i <= unit_count; i++)
 		{
 		{
 			hex2bin(ob_bin, sha2_open_cmd[i], sizeof(ob_bin));
 			hex2bin(ob_bin, sha2_open_cmd[i], sizeof(ob_bin));
-			icarus_write(fd, ob_bin, 8);
+			gc3355_write(fd, ob_bin, 8);
 			cgsleep_ms(GC3355_COMMAND_DELAY_MS);
 			cgsleep_ms(GC3355_COMMAND_DELAY_MS);
 		}
 		}
 		opt_sha2_number = unit_count;
 		opt_sha2_number = unit_count;
@@ -521,34 +518,15 @@ void gc3355_dualminer_init(int fd)
 		gc3355_set_pll_freq(fd, opt_pll_freq);
 		gc3355_set_pll_freq(fd, opt_pll_freq);
 }
 }
 
 
-void gc3355_init(int fd, char *sha2_unit, bool is_scrypt_only)
+void gc3355_init(int fd, int sha2_units, bool is_scrypt_only)
 {
 {
-	if (gc3355_get_cts_status(fd) == 1)
+	if (opt_scrypt)
 	{
 	{
-		//1.2v - Scrypt mode
-		if (opt_scrypt)
-		{
-			if (is_scrypt_only)
-				gc3355_opt_scrypt_only_init(fd);
-		}
-		else
-		{
-			((sha2_unit == NULL) ? gc3355_open_sha2_unit_one_by_one(fd, DEFAULT_1_2V_sha2) : gc3355_open_sha2_unit_one_by_one(fd, sha2_unit));
-		}
+		if (is_scrypt_only)
+			gc3355_opt_scrypt_only_init(fd);
 	}
 	}
 	else
 	else
-	{
-		//0.9v - Scrypt + SHA mode
-		if (opt_scrypt)
-		{
-			if (is_scrypt_only)
-				gc3355_opt_scrypt_only_init(fd);
-		}
-		else
-		{
-			((sha2_unit == NULL) ? gc3355_open_sha2_unit_one_by_one(fd, DEFAULT_0_9V_sha2) : gc3355_open_sha2_unit_one_by_one(fd, sha2_unit));
-		}
-	}
+		gc3355_open_sha2_units(fd, sha2_units);
 }
 }
 
 
 void gc3355_scrypt_prepare_work(unsigned char cmd[156], struct work *work)
 void gc3355_scrypt_prepare_work(unsigned char cmd[156], struct work *work)

+ 7 - 4
gc3355.h

@@ -16,14 +16,17 @@
 
 
 #include "miner.h"
 #include "miner.h"
 
 
+// options configurable by the end-user
+
+extern int opt_sha2_units;
+
+// GridSeed common code begins here
+
 #define GC3355_COMMAND_DELAY_MS 20
 #define GC3355_COMMAND_DELAY_MS 20
 
 
 #define SCRYPT_UNIT_OPEN  0
 #define SCRYPT_UNIT_OPEN  0
 #define SCRYPT_UNIT_CLOSE 1
 #define SCRYPT_UNIT_CLOSE 1
 
 
-extern
-char *opt_dualminer_sha2_gating;
-
 extern
 extern
 int opt_pll_freq;
 int opt_pll_freq;
 
 
@@ -51,7 +54,7 @@ extern
 void gc3355_scrypt_only_reset(int fd);
 void gc3355_scrypt_only_reset(int fd);
 
 
 extern
 extern
-void gc3355_init(int fd, char *sha2_unit, bool is_scrypt_only);
+void gc3355_init(int fd, int sha2_units, bool is_scrypt_only);
 
 
 extern
 extern
 void gc3355_open_sha2_unit(int fd, char *opt_sha2_gating);
 void gc3355_open_sha2_unit(int fd, char *opt_sha2_gating);