diff --git a/main/http_server/http_server.c b/main/http_server/http_server.c index d9ff4bb..767bfb9 100644 --- a/main/http_server/http_server.c +++ b/main/http_server/http_server.c @@ -37,6 +37,7 @@ static const char * TAG = "http_server"; static GlobalState * GLOBAL_STATE; static httpd_handle_t server = NULL; QueueHandle_t log_queue = NULL; +StaticQueue_t log_queue_static; static int fd = -1; @@ -381,6 +382,11 @@ static esp_err_t GET_system_info(httpd_req_t * req) cJSON_AddNumberToObject(root, "isUsingFallbackStratum", GLOBAL_STATE->SYSTEM_MODULE.is_using_fallback); cJSON_AddNumberToObject(root, "freeHeap", esp_get_free_heap_size()); + cJSON_AddNumberToObject(root, "freeInternalHeap", esp_get_free_internal_heap_size()); + cJSON_AddNumberToObject(root, "minimumFreeHeap", esp_get_minimum_free_heap_size()); + + cJSON_AddStringToObject(root, "idfVersion", esp_get_idf_version()); + cJSON_AddNumberToObject(root, "coreVoltage", nvs_config_get_u16(NVS_CONFIG_ASIC_VOLTAGE, CONFIG_ASIC_VOLTAGE)); cJSON_AddNumberToObject(root, "coreVoltageActual", VCORE_get_voltage_mv(GLOBAL_STATE)); cJSON_AddNumberToObject(root, "frequency", nvs_config_get_u16(NVS_CONFIG_ASIC_FREQ, CONFIG_ASIC_FREQUENCY)); @@ -567,7 +573,7 @@ int log_to_queue(const char * format, va_list args) va_end(args_copy); // Allocate the buffer dynamically - char * log_buffer = (char *) calloc(needed_size + 2, sizeof(char)); // +2 for potential \n and \0 + char *log_buffer = (char *) heap_caps_calloc(needed_size + 2, sizeof(char), MALLOC_CAP_SPIRAM); if (log_buffer == NULL) { return 0; } @@ -683,11 +689,17 @@ esp_err_t start_rest_server(void * pvParameters) } REST_CHECK(base_path, "wrong base path", err); - rest_server_context_t * rest_context = calloc(1, sizeof(rest_server_context_t)); + + rest_server_context_t *rest_context = (rest_server_context_t*) heap_caps_calloc(1, sizeof(rest_server_context_t), MALLOC_CAP_SPIRAM); + REST_CHECK(rest_context, "No memory for rest context", err); strlcpy(rest_context->base_path, base_path, sizeof(rest_context->base_path)); - log_queue = xQueueCreate(MESSAGE_QUEUE_SIZE, sizeof(char*)); + size_t queue_memory_size = MESSAGE_QUEUE_SIZE * sizeof(char*); + void *queue_memory = heap_caps_malloc(queue_memory_size, MALLOC_CAP_SPIRAM); + REST_CHECK(queue_memory, "No memory for queue memory", err); + log_queue = xQueueCreateStatic(MESSAGE_QUEUE_SIZE, sizeof(char*), queue_memory, &log_queue_static); + REST_CHECK(log_queue, "No memory for log queue", err); httpd_config_t config = HTTPD_DEFAULT_CONFIG(); config.uri_match_fn = httpd_uri_match_wildcard; diff --git a/main/self_test/self_test.c b/main/self_test/self_test.c index 89bab74..1418159 100644 --- a/main/self_test/self_test.c +++ b/main/self_test/self_test.c @@ -358,8 +358,8 @@ void self_test(void * pvParameters) tests_done(GLOBAL_STATE, TESTS_FAILED); } - GLOBAL_STATE->ASIC_TASK_MODULE.active_jobs = malloc(sizeof(bm_job *) * 128); - GLOBAL_STATE->valid_jobs = malloc(sizeof(uint8_t) * 128); + GLOBAL_STATE->ASIC_TASK_MODULE.active_jobs = heap_caps_malloc(sizeof(bm_job *) * 128, MALLOC_CAP_SPIRAM); + GLOBAL_STATE->valid_jobs = heap_caps_malloc(sizeof(uint8_t) * 128, MALLOC_CAP_SPIRAM); for (int i = 0; i < 128; i++) { GLOBAL_STATE->ASIC_TASK_MODULE.active_jobs[i] = NULL; diff --git a/main/tasks/asic_task.c b/main/tasks/asic_task.c index 8314b11..b8a597d 100644 --- a/main/tasks/asic_task.c +++ b/main/tasks/asic_task.c @@ -19,8 +19,8 @@ void ASIC_task(void *pvParameters) //initialize the semaphore GLOBAL_STATE->ASIC_TASK_MODULE.semaphore = xSemaphoreCreateBinary(); - GLOBAL_STATE->ASIC_TASK_MODULE.active_jobs = malloc(sizeof(bm_job *) * 128); - GLOBAL_STATE->valid_jobs = malloc(sizeof(uint8_t) * 128); + GLOBAL_STATE->ASIC_TASK_MODULE.active_jobs = heap_caps_malloc(sizeof(bm_job *) * 128, MALLOC_CAP_SPIRAM); + GLOBAL_STATE->valid_jobs = heap_caps_malloc(sizeof(uint8_t) * 128, MALLOC_CAP_SPIRAM); for (int i = 0; i < 128; i++) { GLOBAL_STATE->ASIC_TASK_MODULE.active_jobs[i] = NULL; diff --git a/main/tasks/create_jobs_task.c b/main/tasks/create_jobs_task.c index 101a0b0..4989475 100644 --- a/main/tasks/create_jobs_task.c +++ b/main/tasks/create_jobs_task.c @@ -98,7 +98,7 @@ static void process_mining_job(GlobalState *GLOBAL_STATE, mining_notify *notific bm_job next_job = construct_bm_job(notification, merkle_root, GLOBAL_STATE->version_mask); - bm_job *queued_next_job = malloc(sizeof(bm_job)); + bm_job *queued_next_job = heap_caps_malloc(sizeof(bm_job), MALLOC_CAP_SPIRAM); if (queued_next_job == NULL) { ESP_LOGE(TAG, "Failed to allocate memory for queued_next_job"); free(extranonce_2_str); @@ -152,7 +152,7 @@ static void generate_additional_work(GlobalState *GLOBAL_STATE, mining_notify *n bm_job next_job = construct_bm_job(notification, merkle_root, GLOBAL_STATE->version_mask); - bm_job *queued_next_job = malloc(sizeof(bm_job)); + bm_job *queued_next_job = heap_caps_malloc(sizeof(bm_job), MALLOC_CAP_SPIRAM); if (queued_next_job == NULL) { ESP_LOGE(TAG, "Failed to allocate memory for queued_next_job"); free(extranonce_2_str); diff --git a/sdkconfig.defaults b/sdkconfig.defaults index 5a9107c..c2fb7be 100644 --- a/sdkconfig.defaults +++ b/sdkconfig.defaults @@ -13,3 +13,7 @@ CONFIG_ESP_WIFI_11KV_SUPPORT=y CONFIG_LV_CONF_SKIP=n CONFIG_BT_ENABLED=n CONFIG_LWIP_MAX_SOCKETS=16 +CONFIG_SPIRAM=y +CONFIG_SPIRAM_MODE_OCT=y +CONFIG_SPIRAM_USE_CAPS_ALLOC=y +CONFIG_SPIRAM_SPEED_80M=y \ No newline at end of file