http_download needs a bigger stack for cspot which required to move it to EXTRAM

This commit is contained in:
philippe44
2023-09-23 22:20:01 -07:00
parent b413780048
commit 90f53db953
8 changed files with 100 additions and 36 deletions

View File

@@ -948,7 +948,7 @@ CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION=y
CONFIG_FREERTOS_CHECK_STACKOVERFLOW_CANARY=y
# CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK is not set
CONFIG_FREERTOS_INTERRUPT_BACKTRACE=y
CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=1
CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=2
# CONFIG_FREERTOS_ASSERT_FAIL_ABORT is not set
CONFIG_FREERTOS_ASSERT_DISABLE=y
CONFIG_FREERTOS_ISR_STACKSIZE=2096

View File

@@ -907,7 +907,7 @@ CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION=y
CONFIG_FREERTOS_CHECK_STACKOVERFLOW_CANARY=y
# CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK is not set
CONFIG_FREERTOS_INTERRUPT_BACKTRACE=y
CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=1
CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=2
# CONFIG_FREERTOS_ASSERT_FAIL_ABORT is not set
CONFIG_FREERTOS_ASSERT_DISABLE=y
CONFIG_FREERTOS_ISR_STACKSIZE=2096

View File

@@ -918,7 +918,7 @@ CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION=y
CONFIG_FREERTOS_CHECK_STACKOVERFLOW_CANARY=y
# CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK is not set
CONFIG_FREERTOS_INTERRUPT_BACKTRACE=y
CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=1
CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=2
# CONFIG_FREERTOS_ASSERT_FAIL_ABORT is not set
CONFIG_FREERTOS_ASSERT_DISABLE=y
CONFIG_FREERTOS_ISR_STACKSIZE=2096

View File

@@ -26,7 +26,7 @@
#include "cJSON.h"
#include "tools.h"
#define PSEUDO_IDLE_STACK_SIZE (8*1024)
#define PSEUDO_IDLE_STACK_SIZE (6*1024)
#define MONITOR_TIMER (10*1000)
#define SCRATCH_SIZE 256

View File

@@ -136,10 +136,8 @@ static bool cmd_handler(cspot_event_t event, ...) {
displayer_timer(DISPLAYER_ELAPSED, va_arg(args, int), -1);
break;
case CSPOT_TRACK_INFO: {
uint32_t duration = va_arg(args, int);
uint32_t offset = va_arg(args, int);
char *artist = va_arg(args, char*), *album = va_arg(args, char*), *title = va_arg(args, char*);
char *artwork = va_arg(args, char*);
uint32_t duration = va_arg(args, int), offset = va_arg(args, int);
char *artist = va_arg(args, char*), *album = va_arg(args, char*), *title = va_arg(args, char*), *artwork = va_arg(args, char*);
if (artwork && displayer_can_artwork()) {
ESP_LOGI(TAG, "requesting artwork %s", artwork);
http_download(artwork, 128*1024, got_artwork, NULL);

View File

@@ -742,6 +742,7 @@ static void IRAM_ATTR spdif_convert(ISAMPLE_T *src, size_t frames, u32_t *dst) {
register u16_t aux;
#endif
// we assume frame == 0 as well...
if (!src) {
count = 192;
vu = VUCP24[0];

View File

@@ -20,6 +20,10 @@
#include "esp_log.h"
#include "tools.h"
#if CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS < 2
#error CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS must be at least 2
#endif
const static char TAG[] = "tools";
/****************************************************************************************
@@ -177,6 +181,55 @@ char * strdup_psram(const char * source){
return ptr;
}
/****************************************************************************************
* Task manager
*/
#define TASK_TLS_INDEX 1
typedef struct {
StaticTask_t *xTaskBuffer;
StackType_t *xStack;
} task_context_t;
static void task_cleanup(int index, task_context_t *context) {
free(context->xTaskBuffer);
free(context->xStack);
free(context);
}
BaseType_t xTaskCreateEXTRAM( TaskFunction_t pvTaskCode,
const char * const pcName,
configSTACK_DEPTH_TYPE usStackDepth,
void *pvParameters,
UBaseType_t uxPriority,
TaskHandle_t *pxCreatedTask) {
// create the worker task as a static
task_context_t *context = calloc(1, sizeof(task_context_t));
context->xTaskBuffer = (StaticTask_t*) heap_caps_malloc(sizeof(StaticTask_t), (MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT));
context->xStack = heap_caps_malloc(usStackDepth,(MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT));
TaskHandle_t handle = xTaskCreateStatic(pvTaskCode, pcName, usStackDepth, pvParameters, uxPriority, context->xStack, context->xTaskBuffer);
// store context in TCB or free everything in case of failure
if (!handle) {
free(context->xTaskBuffer);
free(context->xStack);
free(context);
} else {
vTaskSetThreadLocalStoragePointerAndDelCallback( handle, TASK_TLS_INDEX, context, (TlsDeleteCallbackFunction_t) task_cleanup);
}
if (pxCreatedTask) *pxCreatedTask = handle;
return handle != NULL ? pdPASS : pdFAIL;
}
void vTaskDeleteEXTRAM(TaskHandle_t xTask) {
/* At this point we leverage FreeRTOS extension to have callbacks on task deletion.
* If not, we need to have here our own deletion implementation that include delayed
* free for when this is called with NULL (self-deletion)
*/
vTaskDelete(xTask);
}
/****************************************************************************************
* URL download
*/
@@ -207,7 +260,7 @@ void http_download(char *url, size_t max, http_download_cb_t callback, void *con
http_context->max = max;
http_context->client = esp_http_client_init(&config);
xTaskCreate(http_downloader, "downloader", 4*1024, http_context, ESP_TASK_PRIO_MIN + 1, NULL);
xTaskCreateEXTRAM(http_downloader, "downloader", 8*1024, http_context, ESP_TASK_PRIO_MIN + 1, NULL);
}
static void http_downloader(void *arg) {
@@ -217,7 +270,7 @@ static void http_downloader(void *arg) {
esp_http_client_cleanup(http_context->client);
free(http_context);
vTaskDelete(NULL);
vTaskDeleteEXTRAM(NULL);
}
static esp_err_t http_event_handler(esp_http_client_event_t *evt) {
@@ -244,7 +297,7 @@ static esp_err_t http_event_handler(esp_http_client_event_t *evt) {
if (!http_context->data) {
if ((http_context->data = (uint8_t*) malloc(len)) == NULL) {
http_context->abort = true;
ESP_LOGE(TAG, "gailed to allocate memory for output buffer %zu", len);
ESP_LOGE(TAG, "failed to allocate memory for output buffer %zu", len);
return ESP_FAIL;
}
}

View File

@@ -56,6 +56,18 @@ const char* str_or_null(const char * str);
typedef void (*http_download_cb_t)(uint8_t* data, size_t len, void *context);
void http_download(char *url, size_t max, http_download_cb_t callback, void *context);
/* Use these to dynamically create tasks whose stack is on EXTRAM. Be aware that it
* requires configNUM_THREAD_LOCAL_STORAGE_POINTERS to bet set to 2 at least (index 0
* is used by pthread and this uses index 1, obviously
*/
BaseType_t xTaskCreateEXTRAM( TaskFunction_t pvTaskCode,
const char * const pcName,
configSTACK_DEPTH_TYPE usStackDepth,
void *pvParameters,
UBaseType_t uxPriority,
TaskHandle_t *pxCreatedTask);
void vTaskDeleteEXTRAM(TaskHandle_t xTask);
extern const char unknown_string_placeholder[];
#ifdef __cplusplus