use board_version for hardware driver selection

This commit is contained in:
macphyter 2024-02-06 19:22:05 -07:00
parent e9cbf90132
commit e6a3c80c50
3 changed files with 17 additions and 18 deletions

View File

@ -13,11 +13,6 @@
#define STRATUM_USER CONFIG_STRATUM_USER
/* Use platform ID to decide which drivers to use */
#define PLATFORM_BITAXE 0x01
#define PLATFORM_ULTRA 0x02
#define PLATFORM_HEX 0x03
typedef struct
{
void (*init_fn)(u_int64_t);
@ -29,8 +24,6 @@ typedef struct
typedef struct
{
int platform_id;
char * asic_model;
AsicFunctions ASIC_functions;
double asic_job_frequency_ms;
@ -38,6 +31,8 @@ typedef struct
work_queue stratum_queue;
work_queue ASIC_jobs_queue;
char * device_name;
int board_version;
bm1397Module BM1397_MODULE;
SystemModule SYSTEM_MODULE;
AsicTaskModule ASIC_TASK_MODULE;
@ -58,3 +53,4 @@ typedef struct
} GlobalState;
#endif /* GLOBAL_STATE_H_ */

View File

@ -25,11 +25,12 @@ void app_main(void)
{
ESP_ERROR_CHECK(nvs_flash_init());
/* we need to populate the platform_id here, but it doesn't exist in NVS yet */
/* TODO read the platform ID from the NVS */
/* TODO bitaxetool will need to be modified to include it */
/* use hard-coded value for now */
GLOBAL_STATE.platform_id = PLATFORM_HEX;
/* Use device_name/board_version to decide how to handle the hardware drivers */
/* TODO What should the default values be? */
GLOBAL_STATE.device_name = nvs_config_get_string(NVS_CONFIG_DEVICE_MODEL, "hex");
GLOBAL_STATE.board_version = atoi(nvs_config_get_string(NVS_CONFIG_BOARD_VERSION, "000"));
ESP_LOGI(TAG, "Found Device Model: %s", GLOBAL_STATE.device_name);
ESP_LOGI(TAG, "Found Board Version: %d", GLOBAL_STATE.board_version);
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);

View File

@ -77,18 +77,20 @@ static void _init_system(GlobalState * global_state, SystemModule * module)
ADC_init();
/* perform platform init based on the platform ID */
/* perform platform init based on the device name */
/* TODO add other platforms besides HEX */
switch (global_state->platform_id) {
case PLATFORM_BITAXE:
case PLATFORM_ULTRA:
switch (global_state->board_version) {
case 201: /* ULTRA */
case 202:
case 203:
case 204:
// DS4432U tests
DS4432U_set_vcore(nvs_config_get_u16(NVS_CONFIG_ASIC_VOLTAGE, CONFIG_ASIC_VOLTAGE) / 1000.0);
EMC2101_init(nvs_config_get_u16(NVS_CONFIG_INVERT_FAN_POLARITY, 1));
EMC2101_set_fan_speed(1);
break;
case PLATFORM_HEX:
case 302: /* HEX */
// Initialize the core voltage regulator
TPS546_init();
// Fan Tests
@ -97,7 +99,7 @@ static void _init_system(GlobalState * global_state, SystemModule * module)
EMC2302_set_fan_speed(1, (float) nvs_config_get_u16(NVS_CONFIG_FAN_SPEED, 100) / 100);
break;
default:
ESP_LOGI(TAG, "ERROR- invalid platform ID");
ESP_LOGI(TAG, "ERROR- invalid board version");
}
vTaskDelay(500 / portTICK_PERIOD_MS);