Skip to content

Commit

Permalink
main: Display an error when ASIC model is invalid
Browse files Browse the repository at this point in the history
Instead of aborting right away, the Bitaxe will now display
an error on the oled and keep its AP mode available so a user
can still update their device if they need to.
  • Loading branch information
johnny9 committed Sep 27, 2023
1 parent f7d06a7 commit 6b8a9fa
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"sys.h": "c",
"array": "c",
"string": "c",
"string_view": "c"
"string_view": "c",
"*.tcc": "c"
},
"editor.formatOnSave": true,
"cSpell.words": [
Expand Down
39 changes: 22 additions & 17 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,13 @@ void app_main(void)

GLOBAL_STATE.ASIC_functions = ASIC_functions;
} else {
ESP_LOGE(TAG, "Unable to determine ASIC model. Please make sure the model has been written into NVS at main/asicmodel.");
vTaskDelay(10000 / portTICK_PERIOD_MS);
exit(EXIT_FAILURE);
ESP_LOGI(TAG, "Invalid ASIC model");
AsicFunctions ASIC_functions = {.init_fn = NULL,
.receive_result_fn = NULL,
.set_max_baud_fn = NULL,
.set_difficulty_mask_fn = NULL,
.send_work_fn = NULL};
GLOBAL_STATE.ASIC_functions = ASIC_functions;
}

ESP_LOGI(TAG, "Welcome to the bitaxe!");
Expand Down Expand Up @@ -95,28 +99,29 @@ void app_main(void)
}
}

wifi_softap_off();

free(wifi_ssid);
free(wifi_pass);

queue_init(&GLOBAL_STATE.stratum_queue);
queue_init(&GLOBAL_STATE.ASIC_jobs_queue);

SERIAL_init();

(*GLOBAL_STATE.ASIC_functions.init_fn)(GLOBAL_STATE.POWER_MANAGEMENT_MODULE.frequency_value);

// set the startup_done flag
GLOBAL_STATE.SYSTEM_MODULE.startup_done = true;

xTaskCreate(stratum_task, "stratum admin", 8192, (void *) &GLOBAL_STATE, 5, NULL);
xTaskCreate(create_jobs_task, "stratum miner", 8192, (void *) &GLOBAL_STATE, 10, NULL);
xTaskCreate(USER_INPUT_task, "user input", 8192, (void *) &GLOBAL_STATE, 5, NULL);
xTaskCreate(POWER_MANAGEMENT_task, "power mangement", 8192, (void *) &GLOBAL_STATE, 10, NULL);
xTaskCreate(ASIC_task, "asic", 8192, (void *) &GLOBAL_STATE, 10, NULL);
xTaskCreate(ASIC_result_task, "asic result", 8192, (void *) &GLOBAL_STATE, 15, NULL);

xTaskCreate(USER_INPUT_task, "user input", 8192, (void *) &GLOBAL_STATE, 5, NULL);
if (GLOBAL_STATE.ASIC_functions.init_fn != NULL) {
wifi_softap_off();

queue_init(&GLOBAL_STATE.stratum_queue);
queue_init(&GLOBAL_STATE.ASIC_jobs_queue);

SERIAL_init();
(*GLOBAL_STATE.ASIC_functions.init_fn)(GLOBAL_STATE.POWER_MANAGEMENT_MODULE.frequency_value);

xTaskCreate(stratum_task, "stratum admin", 8192, (void *) &GLOBAL_STATE, 5, NULL);
xTaskCreate(create_jobs_task, "stratum miner", 8192, (void *) &GLOBAL_STATE, 10, NULL);
xTaskCreate(ASIC_task, "asic", 8192, (void *) &GLOBAL_STATE, 10, NULL);
xTaskCreate(ASIC_result_task, "asic result", 8192, (void *) &GLOBAL_STATE, 15, NULL);
}
}

void MINER_set_wifi_status(wifi_status_t status, uint16_t retry_count)
Expand Down
14 changes: 11 additions & 3 deletions main/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,14 @@ static void _update_system_performance(GlobalState * GLOBAL_STATE)
}
}

static void show_ap_information()
static void show_ap_information(const char * error)
{
if (OLED_status()) {
_clear_display();
OLED_writeString(0, 0, "connect to ssid:");
if (error != NULL) {
OLED_writeString(0, 0, error);
}
OLED_writeString(0, 1, "connect to ssid:");
char ap_ssid[13];
generate_ssid(ap_ssid);
OLED_writeString(0, 2, ap_ssid);
Expand Down Expand Up @@ -353,12 +356,17 @@ void SYSTEM_task(void * pvParameters)
wifi_mode_t wifi_mode;
esp_err_t result;

while (GLOBAL_STATE->ASIC_functions.init_fn == NULL) {
show_ap_information("ASIC MODEL INVALID");
vTaskDelay(5000 / portTICK_PERIOD_MS);
}

// show the connection screen
while (!module->startup_done) {
result = esp_wifi_get_mode(&wifi_mode);
if (result == ESP_OK && (wifi_mode == WIFI_MODE_APSTA || wifi_mode == WIFI_MODE_AP) &&
strcmp(module->wifi_status, "Failed to connect") == 0) {
show_ap_information(module);
show_ap_information(NULL);
vTaskDelay(5000 / portTICK_PERIOD_MS);
} else {
_update_connection(module);
Expand Down

0 comments on commit 6b8a9fa

Please sign in to comment.