main: Determine ASIC model from NVS

This adds more hardware information to the example config.cvs.
If the model can't be determined at startup, the device will abort.
This commit is contained in:
johnny9
2023-09-21 11:18:38 -04:00
committed by Johnny
parent bc4afd39b7
commit 706ee510ba
10 changed files with 38 additions and 35 deletions

View File

@ -57,7 +57,7 @@ void STRATUM_V1_initialize_buffer();
char *STRATUM_V1_receive_jsonrpc_line(int sockfd); char *STRATUM_V1_receive_jsonrpc_line(int sockfd);
int STRATUM_V1_subscribe(int socket, char **extranonce, int *extranonce2_len); int STRATUM_V1_subscribe(int socket, char ** extranonce, int * extranonce2_len, char * model);
void STRATUM_V1_parse(StratumApiV1Message *message, const char *stratum_json); void STRATUM_V1_parse(StratumApiV1Message *message, const char *stratum_json);

View File

@ -266,11 +266,11 @@ int _parse_stratum_subscribe_result_message(const char *result_json_str,
return 0; return 0;
} }
int STRATUM_V1_subscribe(int socket, char **extranonce, int *extranonce2_len) int STRATUM_V1_subscribe(int socket, char ** extranonce, int * extranonce2_len, char * model)
{ {
// Subscribe // Subscribe
char subscribe_msg[BUFFER_SIZE]; char subscribe_msg[BUFFER_SIZE];
sprintf(subscribe_msg, "{\"id\": %d, \"method\": \"mining.subscribe\", \"params\": [\"bitaxe %s\"]}\n", send_uid++, CONFIG_ASIC_MODEL); sprintf(subscribe_msg, "{\"id\": %d, \"method\": \"mining.subscribe\", \"params\": [\"bitaxe %s\"]}\n", send_uid++, model);
debug_stratum_tx(subscribe_msg); debug_stratum_tx(subscribe_msg);
write(socket, subscribe_msg, strlen(subscribe_msg)); write(socket, subscribe_msg, strlen(subscribe_msg));
char * line; char * line;

View File

@ -8,3 +8,6 @@ stratumuser,data,string,1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa.bitaxe
stratumpass,data,string,x stratumpass,data,string,x
asicfrequency,data,u16,450 asicfrequency,data,u16,450
asicvoltage,data,u16,1400 asicvoltage,data,u16,1400
asicmodel,data,string,BM1366
devicemodel,data,string,ultra
boardversion,data,string,0.11

View File

@ -1,15 +1,15 @@
#ifndef GLOBAL_STATE_H_ #ifndef GLOBAL_STATE_H_
#define GLOBAL_STATE_H_ #define GLOBAL_STATE_H_
#include "work_queue.h"
#include "bm1397.h"
#include "bm1366.h"
#include "system.h"
#include "stratum_api.h"
#include "asic_task.h" #include "asic_task.h"
#include "bm1366.h"
#include "bm1397.h"
#include "common.h"
#include "power_management_task.h" #include "power_management_task.h"
#include "serial.h" #include "serial.h"
#include "common.h" #include "stratum_api.h"
#include "system.h"
#include "work_queue.h"
#define STRATUM_USER CONFIG_STRATUM_USER #define STRATUM_USER CONFIG_STRATUM_USER
@ -24,6 +24,7 @@ typedef struct
typedef struct typedef struct
{ {
char * asic_model;
AsicFunctions ASIC_functions; AsicFunctions ASIC_functions;
double asic_job_frequency_ms; double asic_job_frequency_ms;

View File

@ -258,7 +258,7 @@ static esp_err_t GET_system_info(httpd_req_t * req)
cJSON_AddNumberToObject(root, "sharesAccepted", GLOBAL_STATE->SYSTEM_MODULE.shares_accepted); cJSON_AddNumberToObject(root, "sharesAccepted", GLOBAL_STATE->SYSTEM_MODULE.shares_accepted);
cJSON_AddNumberToObject(root, "sharesRejected", GLOBAL_STATE->SYSTEM_MODULE.shares_rejected); cJSON_AddNumberToObject(root, "sharesRejected", GLOBAL_STATE->SYSTEM_MODULE.shares_rejected);
cJSON_AddNumberToObject(root, "uptimeSeconds", (esp_timer_get_time() - GLOBAL_STATE->SYSTEM_MODULE.start_time) / 1000000); cJSON_AddNumberToObject(root, "uptimeSeconds", (esp_timer_get_time() - GLOBAL_STATE->SYSTEM_MODULE.start_time) / 1000000);
cJSON_AddStringToObject(root, "ASICModel", CONFIG_ASIC_MODEL); cJSON_AddStringToObject(root, "ASICModel", GLOBAL_STATE->asic_model);
cJSON_AddStringToObject(root, "stratumURL", stratumURL); cJSON_AddStringToObject(root, "stratumURL", stratumURL);
cJSON_AddNumberToObject(root, "stratumPort", nvs_config_get_u16(NVS_CONFIG_STRATUM_PORT, CONFIG_STRATUM_PORT)); cJSON_AddNumberToObject(root, "stratumPort", nvs_config_get_u16(NVS_CONFIG_STRATUM_PORT, CONFIG_STRATUM_PORT));
cJSON_AddStringToObject(root, "stratumUser", stratumUser); cJSON_AddStringToObject(root, "stratumUser", stratumUser);

View File

@ -17,8 +17,6 @@
#include "stratum_task.h" #include "stratum_task.h"
#include "user_input_task.h" #include "user_input_task.h"
#define ASIC_MODEL CONFIG_ASIC_MODEL
static GlobalState GLOBAL_STATE = {.extranonce_str = NULL, .extranonce_2_len = 0, .abandon_work = 0, .version_mask = 0}; static GlobalState GLOBAL_STATE = {.extranonce_str = NULL, .extranonce_2_len = 0, .abandon_work = 0, .version_mask = 0};
static const char * TAG = "miner"; static const char * TAG = "miner";
@ -30,7 +28,8 @@ void app_main(void)
ESP_LOGI(TAG, "NVS_CONFIG_ASIC_FREQ %f", (float) nvs_config_get_u16(NVS_CONFIG_ASIC_FREQ, CONFIG_ASIC_FREQUENCY)); ESP_LOGI(TAG, "NVS_CONFIG_ASIC_FREQ %f", (float) nvs_config_get_u16(NVS_CONFIG_ASIC_FREQ, CONFIG_ASIC_FREQUENCY));
GLOBAL_STATE.POWER_MANAGEMENT_MODULE.frequency_value = nvs_config_get_u16(NVS_CONFIG_ASIC_FREQ, CONFIG_ASIC_FREQUENCY); GLOBAL_STATE.POWER_MANAGEMENT_MODULE.frequency_value = nvs_config_get_u16(NVS_CONFIG_ASIC_FREQ, CONFIG_ASIC_FREQUENCY);
if (strcmp(ASIC_MODEL, "BM1366") == 0) { GLOBAL_STATE.asic_model = nvs_config_get_string(NVS_CONFIG_ASIC_MODEL, "");
if (strcmp(GLOBAL_STATE.asic_model, "BM1366") == 0) {
ESP_LOGI(TAG, "ASIC: BM1366"); ESP_LOGI(TAG, "ASIC: BM1366");
AsicFunctions ASIC_functions = {.init_fn = BM1366_init, AsicFunctions ASIC_functions = {.init_fn = BM1366_init,
.receive_result_fn = BM1366_proccess_work, .receive_result_fn = BM1366_proccess_work,
@ -40,7 +39,7 @@ void app_main(void)
GLOBAL_STATE.asic_job_frequency_ms = BM1366_FULLSCAN_MS; GLOBAL_STATE.asic_job_frequency_ms = BM1366_FULLSCAN_MS;
GLOBAL_STATE.ASIC_functions = ASIC_functions; GLOBAL_STATE.ASIC_functions = ASIC_functions;
} else if (strcmp(ASIC_MODEL, "BM1397") == 0) { } else if (strcmp(GLOBAL_STATE.asic_model, "BM1397") == 0) {
ESP_LOGI(TAG, "ASIC: BM1397"); ESP_LOGI(TAG, "ASIC: BM1397");
AsicFunctions ASIC_functions = {.init_fn = BM1397_init, AsicFunctions ASIC_functions = {.init_fn = BM1397_init,
.receive_result_fn = BM1397_proccess_work, .receive_result_fn = BM1397_proccess_work,
@ -53,7 +52,7 @@ void app_main(void)
GLOBAL_STATE.ASIC_functions = ASIC_functions; GLOBAL_STATE.ASIC_functions = ASIC_functions;
} else { } else {
ESP_LOGI(TAG, "Invalid ASIC model"); ESP_LOGE(TAG, "Unable to determine ASIC model. Please make sure the model has been written into NVS.");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }

View File

@ -11,7 +11,9 @@
#define NVS_CONFIG_STRATUM_PASS "stratumpass" #define NVS_CONFIG_STRATUM_PASS "stratumpass"
#define NVS_CONFIG_ASIC_FREQ "asicfrequency" #define NVS_CONFIG_ASIC_FREQ "asicfrequency"
#define NVS_CONFIG_ASIC_VOLTAGE "asicvoltage" #define NVS_CONFIG_ASIC_VOLTAGE "asicvoltage"
#define NVS_CONFIG_ASIC_MODEL "asicModel" #define NVS_CONFIG_ASIC_MODEL "asicmodel"
#define NVS_CONFIG_DEVICE_MODEL "devicemodel"
#define NVS_CONFIG_BOARD_VERSION "boardversion"
char * nvs_config_get_string(const char * key, const char * default_value); char * nvs_config_get_string(const char * key, const char * default_value);
void nvs_config_set_string(const char * key, const char * default_value); void nvs_config_set_string(const char * key, const char * default_value);

View File

@ -29,14 +29,12 @@
static const char * TAG = "SystemModule"; static const char * TAG = "SystemModule";
#define ASIC_MODEL CONFIG_ASIC_MODEL
static void _suffix_string(uint64_t, char *, size_t, int); static void _suffix_string(uint64_t, char *, size_t, int);
static esp_netif_t * netif; static esp_netif_t * netif;
static esp_netif_ip_info_t ip_info; static esp_netif_ip_info_t ip_info;
static void _init_system(SystemModule * module) static void _init_system(GlobalState * global_state, SystemModule * module)
{ {
module->duration_start = 0; module->duration_start = 0;
module->historical_hashrate_rolling_index = 0; module->historical_hashrate_rolling_index = 0;
@ -80,7 +78,7 @@ static void _init_system(SystemModule * module)
// Fan Tests // Fan Tests
EMC2101_init(); EMC2101_init();
if (strcmp(ASIC_MODEL, "BM1366") == 0) { if (strcmp(global_state->asic_model, "BM1366") == 0) {
EMC2101_set_fan_speed(0); EMC2101_set_fan_speed(0);
} else { } else {
EMC2101_set_fan_speed(1); EMC2101_set_fan_speed(1);
@ -336,7 +334,7 @@ void SYSTEM_task(void * pvParameters)
GlobalState * GLOBAL_STATE = (GlobalState *) pvParameters; GlobalState * GLOBAL_STATE = (GlobalState *) pvParameters;
SystemModule * module = &GLOBAL_STATE->SYSTEM_MODULE; SystemModule * module = &GLOBAL_STATE->SYSTEM_MODULE;
_init_system(module); _init_system(GLOBAL_STATE, module);
_clear_display(); _clear_display();
_init_connection(module); _init_connection(module);

View File

@ -20,7 +20,6 @@
#define VOLTAGE_START_THROTTLE 4900 #define VOLTAGE_START_THROTTLE 4900
#define VOLTAGE_MIN_THROTTLE 3500 #define VOLTAGE_MIN_THROTTLE 3500
#define VOLTAGE_RANGE (VOLTAGE_START_THROTTLE - VOLTAGE_MIN_THROTTLE) #define VOLTAGE_RANGE (VOLTAGE_START_THROTTLE - VOLTAGE_MIN_THROTTLE)
#define ASIC_MODEL CONFIG_ASIC_MODEL
static const char * TAG = "power_management"; static const char * TAG = "power_management";
@ -58,7 +57,7 @@ void POWER_MANAGEMENT_task(void * pvParameters)
} }
power_management->fan_speed = EMC2101_get_fan_speed(); power_management->fan_speed = EMC2101_get_fan_speed();
if (strcmp(ASIC_MODEL, "BM1397") == 0) { if (strcmp(GLOBAL_STATE->asic_model, "BM1397") == 0) {
power_management->chip_temp = EMC2101_get_external_temp(); power_management->chip_temp = EMC2101_get_external_temp();
@ -115,7 +114,7 @@ void POWER_MANAGEMENT_task(void * pvParameters)
last_frequency_increase++; last_frequency_increase++;
} }
} }
} else if (strcmp(ASIC_MODEL, "BM1366") == 0) { } else if (strcmp(GLOBAL_STATE->asic_model, "BM1366") == 0) {
power_management->chip_temp = EMC2101_get_internal_temp() + 5; power_management->chip_temp = EMC2101_get_internal_temp() + 5;
if (power_management->fan_speed < 10) { if (power_management->fan_speed < 10) {

View File

@ -93,7 +93,8 @@ void stratum_task(void *pvParameters)
break; break;
} }
STRATUM_V1_subscribe(GLOBAL_STATE->sock, &GLOBAL_STATE->extranonce_str, &GLOBAL_STATE->extranonce_2_len); STRATUM_V1_subscribe(GLOBAL_STATE->sock, &GLOBAL_STATE->extranonce_str, &GLOBAL_STATE->extranonce_2_len,
GLOBAL_STATE->asic_model);
STRATUM_V1_configure_version_rolling(GLOBAL_STATE->sock); STRATUM_V1_configure_version_rolling(GLOBAL_STATE->sock);