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/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ SRCS
"display.c"
"screen.c"
"input.c"
"filesystem.c"
"system.c"
"work_queue.c"
"lv_font_portfolio-6x8.c"
Expand Down
39 changes: 39 additions & 0 deletions main/filesystem.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "filesystem.h"
#include "global_state.h"
#include "esp_log.h"
#include "esp_spiffs.h"
#include "esp_vfs.h"

static const char * TAG = "filesystem";

esp_err_t filesystem_init(void * pvParameters)
{
GlobalState * GLOBAL_STATE = (GlobalState *) pvParameters;

esp_vfs_spiffs_conf_t conf = {.base_path = "", .partition_label = NULL, .max_files = 5, .format_if_mount_failed = false};
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

afaik ESP-IDF does require a non empty path starting with "/" e.g. "/spiffs"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is just moved out of http_server.c, unchanged?

esp_err_t ret = esp_vfs_spiffs_register(&conf);

if (ret != ESP_OK) {
if (ret == ESP_FAIL) {
ESP_LOGE(TAG, "Failed to mount or format filesystem");
} else if (ret == ESP_ERR_NOT_FOUND) {
ESP_LOGE(TAG, "Failed to find SPIFFS partition");
} else {
ESP_LOGE(TAG, "Failed to initialize SPIFFS (%s)", esp_err_to_name(ret));
}
return ESP_FAIL;
}

GLOBAL_STATE->filesystem_is_available = true;

size_t total = 0, used = 0;
ret = esp_spiffs_info(NULL, &total, &used);
if (ret != ESP_OK) {
// This shouldn't happen
ESP_LOGE(TAG, "Failed to get SPIFFS partition information (%s)", esp_err_to_name(ret));
} else {
ESP_LOGI(TAG, "Partition size: total: %d, used: %d", total, used);
}

return ESP_OK;
}
16 changes: 16 additions & 0 deletions main/filesystem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef FILESYSTEM_H_
#define FILESYSTEM_H_

#include "esp_err.h"

/**
* @brief Initialize the SPIFFS filesystem
*
* This function mounts the SPIFFS partition and can be used
* independently of the REST server for self-test mode.
*
* @return ESP_OK on success, ESP_FAIL on failure
*/
esp_err_t filesystem_init(void * pvParameters);

#endif /* FILESYSTEM_H_ */
1 change: 1 addition & 0 deletions main/global_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ typedef struct

bool ASIC_initalized;
bool psram_is_available;
bool filesystem_is_available;

int block_height;
char scriptsig[128];
Expand Down
36 changes: 1 addition & 35 deletions main/http_server/http_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,33 +302,6 @@ esp_err_t is_network_allowed(httpd_req_t * req)
return ESP_FAIL;
}

esp_err_t init_fs(void)
{
esp_vfs_spiffs_conf_t conf = {.base_path = "", .partition_label = NULL, .max_files = 5, .format_if_mount_failed = false};
esp_err_t ret = esp_vfs_spiffs_register(&conf);

if (ret != ESP_OK) {
if (ret == ESP_FAIL) {
ESP_LOGE(TAG, "Failed to mount or format filesystem");
} else if (ret == ESP_ERR_NOT_FOUND) {
ESP_LOGE(TAG, "Failed to find SPIFFS partition");
} else {
ESP_LOGE(TAG, "Failed to initialize SPIFFS (%s)", esp_err_to_name(ret));
}
return ESP_FAIL;
}

size_t total = 0, used = 0;
ret = esp_spiffs_info(NULL, &total, &used);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "Failed to get SPIFFS partition information (%s)", esp_err_to_name(ret));
} else {
ESP_LOGI(TAG, "Partition size: total: %d, used: %d", total, used);
}

return ESP_OK;
}

/* Function for stopping the webserver */
void stop_webserver(httpd_handle_t server)
{
Expand Down Expand Up @@ -1293,13 +1266,6 @@ esp_err_t start_rest_server(void * pvParameters)
asic_api_init(GLOBAL_STATE);
const char * base_path = "";

bool enter_recovery = false;
if (init_fs() != ESP_OK) {
// Unable to initialize the web app filesystem.
// Enter recovery mode
enter_recovery = true;
}

REST_CHECK(base_path, "wrong base path", err);
rest_server_context_t * rest_context = calloc(1, sizeof(rest_server_context_t));
REST_CHECK(rest_context, "No memory for rest context", err);
Expand Down Expand Up @@ -1426,7 +1392,7 @@ esp_err_t start_rest_server(void * pvParameters)
};
httpd_register_uri_handler(server, &ws);

if (enter_recovery) {
if (!GLOBAL_STATE->filesystem_is_available) {
/* Make default route serve Recovery */
httpd_uri_t recovery_implicit_get_uri = {
.uri = "/*", .method = HTTP_GET,
Expand Down
37 changes: 26 additions & 11 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include "connect.h"
#include "asic_reset.h"
#include "asic_init.h"
#include "filesystem.h"
#include "input.h"

static GlobalState GLOBAL_STATE;

Expand Down Expand Up @@ -73,25 +75,30 @@ void app_main(void)
return;
}

if (self_test(&GLOBAL_STATE))
if (self_test_init(&GLOBAL_STATE) != ESP_OK) {
ESP_LOGE(TAG, "Failed to init self test");
return;
}

SYSTEM_init_system(&GLOBAL_STATE);

// init AP and connect to wifi
wifi_init(&GLOBAL_STATE);
if (!GLOBAL_STATE.SELF_TEST_MODULE.is_active) {
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");
}
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);
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);
}

// After mounting SPIFFS
SYSTEM_init_versions(&GLOBAL_STATE);
Expand All @@ -113,15 +120,23 @@ void app_main(void)
return;
}

if (xTaskCreate(stratum_task, "stratum admin", 8192, (void *) &GLOBAL_STATE, 5, NULL) != pdPASS) {
ESP_LOGE(TAG, "Error creating stratum admin 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");
}
} 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");
Expand Down
Loading
Loading