Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions main/global_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ typedef struct
char *message;
char *result;
char *finished;
esp_err_t system_init_ret;
} SelfTestModule;

typedef struct
Expand Down
69 changes: 40 additions & 29 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,22 @@ void app_main(void)
wifi_init(&GLOBAL_STATE);
}

SYSTEM_init_peripherals(&GLOBAL_STATE);

if (xTaskCreate(POWER_MANAGEMENT_task, "power management", 8192, (void *) &GLOBAL_STATE, 10, NULL) != pdPASS) {
ESP_LOGE(TAG, "Error creating power management task");
esp_err_t system_init_ret = SYSTEM_init_peripherals(&GLOBAL_STATE);

if (system_init_ret == ESP_OK) {
if (xTaskCreate(POWER_MANAGEMENT_task, "power management", 8192, (void *) &GLOBAL_STATE, 10, NULL) != pdPASS) {
ESP_LOGE(TAG, "Error creating power management task");
}
if (!GLOBAL_STATE.SELF_TEST_MODULE.is_active) {
if (xTaskCreate(FAN_CONTROLLER_task, "fan_controller", 8192, (void *) &GLOBAL_STATE, 5, NULL) != pdPASS) {
ESP_LOGE(TAG, "Error creating fan controller task");
}
}
} else {
ESP_LOGE(TAG, "Critical peripheral initialization failure (%s). Entering degraded mode.", esp_err_to_name(GLOBAL_STATE.SELF_TEST_MODULE.system_init_ret));
}

if (!GLOBAL_STATE.SELF_TEST_MODULE.is_active) {
if (xTaskCreate(FAN_CONTROLLER_task, "fan_controller", 8192, (void *) &GLOBAL_STATE, 5, NULL) != pdPASS) {
ESP_LOGE(TAG, "Error creating fan controller task");
}
// start the API for AxeOS
start_rest_server((void *) &GLOBAL_STATE);
}
Expand All @@ -116,32 +122,37 @@ void app_main(void)

queue_init(&GLOBAL_STATE.stratum_queue);

if (asic_initialize(&GLOBAL_STATE, ASIC_INIT_COLD_BOOT, 0) == 0) {
return;
}
if (system_init_ret == ESP_OK) {
if (asic_initialize(&GLOBAL_STATE, ASIC_INIT_COLD_BOOT, 0) == 0) {
return;
}

if (xTaskCreate(create_jobs_task, "stratum miner", 8192, (void *) &GLOBAL_STATE, 20, NULL) != pdPASS) {
ESP_LOGE(TAG, "Error creating stratum miner task");
}
if (xTaskCreate(ASIC_result_task, "asic result", 8192, (void *) &GLOBAL_STATE, 15, NULL) != pdPASS) {
ESP_LOGE(TAG, "Error creating asic result task");
}
if (xTaskCreate(create_jobs_task, "stratum miner", 8192, (void *) &GLOBAL_STATE, 20, NULL) != pdPASS) {
ESP_LOGE(TAG, "Error creating stratum miner task");
}
if (xTaskCreate(ASIC_result_task, "asic result", 8192, (void *) &GLOBAL_STATE, 15, NULL) != pdPASS) {
ESP_LOGE(TAG, "Error creating asic result task");
}

if (!GLOBAL_STATE.SELF_TEST_MODULE.is_active) {
if (xTaskCreate(stratum_task, "stratum admin", 8192, (void *) &GLOBAL_STATE, 5, NULL) != pdPASS) {
ESP_LOGE(TAG, "Error creating stratum admin task");
if (!GLOBAL_STATE.SELF_TEST_MODULE.is_active) {
if (xTaskCreate(stratum_task, "stratum admin", 8192, (void *) &GLOBAL_STATE, 5, NULL) != pdPASS) {
ESP_LOGE(TAG, "Error creating stratum admin task");
}
}
} else {
if (xTaskCreate(self_test_task, "self_test", 8192, (void *) &GLOBAL_STATE, 10, NULL) != pdPASS) {
ESP_LOGE(TAG, "Error creating self test task");

if (xTaskCreateWithCaps(hashrate_monitor_task, "hashrate monitor", 8192, (void *) &GLOBAL_STATE, 5, NULL, MALLOC_CAP_SPIRAM) !=
pdPASS) {
ESP_LOGE(TAG, "Error creating hashrate monitor task");
}
if (xTaskCreateWithCaps(statistics_task, "statistics", 8192, (void *) &GLOBAL_STATE, 3, NULL, MALLOC_CAP_SPIRAM) != pdPASS) {
ESP_LOGE(TAG, "Error creating statistics task");
}
}

if (xTaskCreateWithCaps(hashrate_monitor_task, "hashrate monitor", 8192, (void *) &GLOBAL_STATE, 5, NULL, MALLOC_CAP_SPIRAM) !=
pdPASS) {
ESP_LOGE(TAG, "Error creating hashrate monitor task");
}
if (xTaskCreateWithCaps(statistics_task, "statistics", 8192, (void *) &GLOBAL_STATE, 3, NULL, MALLOC_CAP_SPIRAM) != pdPASS) {
ESP_LOGE(TAG, "Error creating statistics task");
if (GLOBAL_STATE.SELF_TEST_MODULE.is_active) {
GLOBAL_STATE.SELF_TEST_MODULE.system_init_ret = system_init_ret;
if (xTaskCreate(self_test_task, "self_test", 8192, (void *) &GLOBAL_STATE, 10, NULL) != pdPASS) {
ESP_LOGE(TAG, "Error creating self test task");
}
}
}
8 changes: 1 addition & 7 deletions main/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ static uint64_t current_work_received;
static int8_t current_rssi_value;
static int current_block_height;

static bool self_test_finished;

static screen_t get_current_screen() {
lv_obj_t * active_screen = lv_screen_active();
for (screen_t scr = 0; scr < MAX_SCREENS; scr++) {
Expand Down Expand Up @@ -134,10 +132,7 @@ static lv_obj_t * create_scr_self_test() {

self_test_message_label = lv_label_create(scr);
self_test_result_label = lv_label_create(scr);

self_test_finished_label = lv_label_create(scr);
lv_obj_set_width(self_test_finished_label, LV_HOR_RES);
lv_label_set_long_mode(self_test_finished_label, LV_LABEL_LONG_SCROLL_CIRCULAR);

return scr;
}
Expand Down Expand Up @@ -449,8 +444,7 @@ static void screen_update_cb(lv_timer_t * timer)

lv_label_set_text(self_test_message_label, self_test->message);

if (self_test->is_finished && !self_test_finished) {
self_test_finished = true;
if (self_test->is_finished) {
lv_label_set_text(self_test_result_label, self_test->result);
lv_label_set_text(self_test_finished_label, self_test->finished);
}
Expand Down
17 changes: 7 additions & 10 deletions main/self_test/self_test.c
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
#include <string.h>

// #include "freertos/event_groups.h"
// #include "freertos/timers.h"
#include "driver/gpio.h"

#include "esp_log.h"
#include "esp_timer.h"
#include "esp_check.h"
#include "esp_psram.h"

#include "DS4432U.h"
#include "thermal.h"
#include "vcore.h"
#include "power.h"
#include "nvs_config.h"
#include "global_state.h"

#include "asic.h"
#include "asic_reset.h"
#include "device_config.h"
#include "hashrate_monitor_task.h"
Expand Down Expand Up @@ -219,7 +212,7 @@ void self_test_task(void * pvParameters)
if (!GLOBAL_STATE->SELF_TEST_MODULE.is_active) return;

// Check if we already have an error message from peripheral initialization
if (GLOBAL_STATE->SELF_TEST_MODULE.message != NULL && strlen(GLOBAL_STATE->SELF_TEST_MODULE.message) > 0) {
if (GLOBAL_STATE->SELF_TEST_MODULE.system_init_ret != ESP_OK) {
ESP_LOGE(TAG, "Aborting self-test due to initialization failure: %s", GLOBAL_STATE->SELF_TEST_MODULE.message);
tests_done(GLOBAL_STATE, false);
}
Expand Down Expand Up @@ -422,8 +415,12 @@ static void tests_done(GlobalState * GLOBAL_STATE, bool isTestPassed)
}
ESP_LOGI(TAG, "SELF-TEST PASS! -- Restarting in 10 seconds.");
GLOBAL_STATE->SELF_TEST_MODULE.result = "SELF-TEST PASS!";
GLOBAL_STATE->SELF_TEST_MODULE.finished = "Restarting in 10 seconds.";
vTaskDelay(10000 / portTICK_PERIOD_MS);
char logString[21];
for (int i = 10; i > 0; i--) {
snprintf(logString, sizeof(logString), "Restarting in %d...", i);
GLOBAL_STATE->SELF_TEST_MODULE.finished = logString;
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
esp_restart();
} else {
// isTestFailed
Expand Down
4 changes: 3 additions & 1 deletion main/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ esp_err_t SYSTEM_init_peripherals(GlobalState * GLOBAL_STATE) {
if (ret != ESP_OK) {
self_test_show_message(GLOBAL_STATE, "FILESYS:FAIL");
ESP_LOGE(TAG, "Filesystem init failed");
return ret;
if (GLOBAL_STATE->SELF_TEST_MODULE.is_active) {
return ret;
}
}

// Initialize the core voltage regulator
Expand Down
Loading