Commit 1fca632f7cbd659adadc698ce23d02bc5c929969

Con Kolivas 2013-06-24T11:04:02

Add an --avalon-temp option to allow a user specified target temperature.

diff --git a/ASIC-README b/ASIC-README
index de349a6..a3c46e2 100644
--- a/ASIC-README
+++ b/ASIC-README
@@ -77,8 +77,17 @@ a preinstalled version of cgminer as part of the flash firmware, based on the
 most current cgminer version so no configuration should be necessary. It is
 possible to plug a USB cable from a PC into the Avalon device and mine using
 cgminer as per any other device. It will autodetect and hotplug using default
-options. You can customise the avalon behaviour by using the --avalon-options
-command.
+options. You can customise the avalon behaviour by using the avalon-options
+command, and adjust its fan control-temperature relationship with avalon-temp.
+
+eg:
+--avalon-temp 50
+
+This will adjust fanspeed to keep the temperature at or slightly below 50.
+If you wish the fans to run at maximum speed, setting the target temperature
+very low such as 0 will achieve this. This option can be added to the "More
+options" entry in the web interface if you do not have a direct way of setting
+it.
 
 eg:
 --avalon-options 115200:24:10:45:282
@@ -104,9 +113,9 @@ block mining (eg p2pool) but much lower and the device will start creating
 duplicate shares.
 
 Sample settings for valid different frequencies (last 2 values):
-34:375
-36:350
-39:325
+34:375 *
+36:350 *
+39:325 *
 43:300
 45:282 (default)
 47:270
@@ -116,6 +125,9 @@ Frequency:
 This is the clock speed of the devices. Only specific values work, 256, 270,
 282 (default), 300, 325, 350 and 375.
 
+Note that setting a value with an asterisk next to it will be using your
+avalon outside its spec and you do so at your own risk.
+
 If you use the full curses based interface with Avalons you will get this
 information:
 AVA 0: 22/ 46C  2400R
diff --git a/README b/README
index 7cbcad6..51e4d4c 100644
--- a/README
+++ b/README
@@ -233,7 +233,8 @@ See SCRYPT-README for more information regarding litecoin mining.
 ASIC and FPGA mining boards (BFL ASIC, BitForce, Icarus, ModMiner, Ztex)
 only options:
 
---avalon-options    (See ASIC-README)
+--avalon-options <arg> Set avalon options baud:miners:asic:timeout:freq
+--avalon-temp <arg> Set avalon target temperature (default: 45)
 --bfl-range         Use nonce range on bitforce devices if supported
 --icarus-options <arg> Set specific FPGA board configurations - one set of values for all or comma separated
 --icarus-timing <arg> Set how the Icarus timing is calculated - one setting/value for all or comma separated
diff --git a/cgminer.c b/cgminer.c
index 007501c..277f266 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -568,6 +568,11 @@ static char *set_int_0_to_10(const char *arg, int *i)
 	return set_int_range(arg, i, 0, 10);
 }
 
+static char *set_int_0_to_100(const char *arg, int *i)
+{
+	return set_int_range(arg, i, 0, 100);
+}
+
 static char *set_int_1_to_10(const char *arg, int *i)
 {
 	return set_int_range(arg, i, 1, 10);
@@ -1052,7 +1057,10 @@ static struct opt_table opt_config_table[] = {
 #ifdef USE_AVALON
 	OPT_WITH_ARG("--avalon-options",
 		     set_avalon_options, NULL, NULL,
-		     opt_hidden),
+		     "Set avalon options baud:miners:asic:timeout:freq"),
+	OPT_WITH_ARG("--avalon-temp",
+		     set_int_0_to_100, opt_show_intval, &opt_avalon_temp,
+		     "Set avalon target temperature"),
 #endif
 	OPT_WITHOUT_ARG("--load-balance",
 		     set_loadbalance, &pool_strategy,
diff --git a/driver-avalon.c b/driver-avalon.c
index b25b3b4..270b813 100644
--- a/driver-avalon.c
+++ b/driver-avalon.c
@@ -40,6 +40,7 @@
 #include "hexdump.c"
 #include "util.h"
 
+int opt_avalon_temp = AVALON_TEMP_TARGET;
 static int option_offset = -1;
 struct device_drv avalon_drv;
 
@@ -986,15 +987,15 @@ static inline void record_temp_fan(struct avalon_info *info, struct avalon_resul
 
 static void temp_rise(struct avalon_info *info, int temp)
 {
-	if (temp >= AVALON_TEMP_TARGET + AVALON_TEMP_HYSTERESIS * 3) {
+	if (temp >= opt_avalon_temp + AVALON_TEMP_HYSTERESIS * 3) {
 		info->fan_pwm = AVALON_DEFAULT_FAN_MAX_PWM;
 		return;
 	}
-	if (temp >= AVALON_TEMP_TARGET + AVALON_TEMP_HYSTERESIS * 2)
+	if (temp >= opt_avalon_temp + AVALON_TEMP_HYSTERESIS * 2)
 		info->fan_pwm += 10;
-	else if (temp > AVALON_TEMP_TARGET)
+	else if (temp > opt_avalon_temp)
 		info->fan_pwm += 5;
-	else if (temp >= AVALON_TEMP_TARGET - AVALON_TEMP_HYSTERESIS)
+	else if (temp >= opt_avalon_temp - AVALON_TEMP_HYSTERESIS)
 		info->fan_pwm += 1;
 	else
 		return;
@@ -1005,15 +1006,15 @@ static void temp_rise(struct avalon_info *info, int temp)
 
 static void temp_drop(struct avalon_info *info, int temp)
 {
-	if (temp <= AVALON_TEMP_TARGET - AVALON_TEMP_HYSTERESIS * 3) {
+	if (temp <= opt_avalon_temp - AVALON_TEMP_HYSTERESIS * 3) {
 		info->fan_pwm = AVALON_DEFAULT_FAN_MIN_PWM;
 		return;
 	}
-	if (temp <= AVALON_TEMP_TARGET - AVALON_TEMP_HYSTERESIS * 2)
+	if (temp <= opt_avalon_temp - AVALON_TEMP_HYSTERESIS * 2)
 		info->fan_pwm -= 10;
-	else if (temp <= AVALON_TEMP_TARGET - AVALON_TEMP_HYSTERESIS)
+	else if (temp <= opt_avalon_temp - AVALON_TEMP_HYSTERESIS)
 		info->fan_pwm -= 5;
-	else if (temp < AVALON_TEMP_TARGET)
+	else if (temp < opt_avalon_temp)
 		info->fan_pwm -= 1;
 
 	if (info->fan_pwm < AVALON_DEFAULT_FAN_MIN_PWM)
@@ -1032,9 +1033,9 @@ static inline void adjust_fan(struct avalon_info *info)
 		temp_drop(info, temp_new);
 	else {
 		/* temp_new == info->temp_old */
-		if (temp_new > AVALON_TEMP_TARGET)
+		if (temp_new > opt_avalon_temp)
 			temp_rise(info, temp_new);
-		else if (temp_new < AVALON_TEMP_TARGET - AVALON_TEMP_HYSTERESIS)
+		else if (temp_new < opt_avalon_temp - AVALON_TEMP_HYSTERESIS)
 			temp_drop(info, temp_new);
 	}
 	info->temp_old = temp_new;
diff --git a/driver-avalon.h b/driver-avalon.h
index 70c01b6..77c9a73 100644
--- a/driver-avalon.h
+++ b/driver-avalon.h
@@ -138,6 +138,7 @@ struct avalon_info {
 ASSERT1(sizeof(uint32_t) == 4);
 
 extern struct avalon_info **avalon_info;
+extern int opt_avalon_temp;
 
 #endif /* USE_AVALON */
 #endif	/* AVALON_H */