Skip to content

Commit

Permalink
feat(mdns): support allocating mDNS task from SPIRAM
Browse files Browse the repository at this point in the history
  • Loading branch information
zwx1995esp committed Jan 24, 2025
1 parent 813331f commit 6ddcdae
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
10 changes: 10 additions & 0 deletions components/mdns/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ menu "mDNS"
default 0x0 if MDNS_TASK_AFFINITY_CPU0
default 0x1 if MDNS_TASK_AFFINITY_CPU1

choice MDNS_TASK_MEMORY_ALLOC_FROM
prompt "Select mDNS task create on which type of memory"
default MDNS_TASK_CREATE_FROM_INTERNAL
config MDNS_TASK_CREATE_FROM_SPIRAM
bool "mDNS task creates on the SPIRAM"
depends on (SPIRAM_USE_CAPS_ALLOC || SPIRAM_USE_MALLOC)
config MDNS_TASK_CREATE_FROM_INTERNAL
bool "mDNS task creates on the internal RAM"
endchoice

config MDNS_SERVICE_ADD_TIMEOUT_MS
int "mDNS adding service timeout (ms)"
range 10 30000
Expand Down
15 changes: 11 additions & 4 deletions components/mdns/mdns.c
Original file line number Diff line number Diff line change
Expand Up @@ -5418,7 +5418,7 @@ static void _mdns_service_task(void *pvParameters)
}
}
_mdns_service_task_handle = NULL;
vTaskDelete(NULL);
vTaskDeleteWithCaps(NULL);
}

static void _mdns_timer_cb(void *arg)
Expand Down Expand Up @@ -5476,8 +5476,15 @@ static esp_err_t _mdns_service_task_start(void)
return ESP_FAIL;
}
if (!_mdns_service_task_handle) {
xTaskCreatePinnedToCore(_mdns_service_task, "mdns", MDNS_SERVICE_STACK_DEPTH, NULL, MDNS_TASK_PRIORITY,
(TaskHandle_t *const)(&_mdns_service_task_handle), MDNS_TASK_AFFINITY);
ESP_LOGI(TAG, "mDNS task will be created %s", MDNS_TASK_MEMORY_LOG);
xTaskCreatePinnedToCoreWithCaps(_mdns_service_task, "mdns", MDNS_SERVICE_STACK_DEPTH, NULL, MDNS_TASK_PRIORITY,
(TaskHandle_t *const)(&_mdns_service_task_handle), MDNS_TASK_AFFINITY, MDNS_TASK_MEMORY_CAPS);
#ifdef MDNS_ENABLE_DEBUG
StackType_t *mdns_stack_buffer;
StaticTask_t *mdns_task_buffer;
xTaskGetStaticBuffers(_mdns_service_task_handle, &mdns_stack_buffer, &mdns_task_buffer);
_mdns_dbg_printf("mdns_stack_buffer:%p mdns_task_buffer:%p\n", mdns_stack_buffer, mdns_task_buffer);
#endif // MDNS_ENABLE_DEBUG
if (!_mdns_service_task_handle) {
_mdns_stop_timer();
MDNS_SERVICE_UNLOCK();
Expand All @@ -5504,7 +5511,7 @@ static esp_err_t _mdns_service_task_stop(void)
mdns_action_t *a = &action;
action.type = ACTION_TASK_STOP;
if (xQueueSend(_mdns_server->action_queue, &a, (TickType_t)0) != pdPASS) {
vTaskDelete(_mdns_service_task_handle);
vTaskDeleteWithCaps(_mdns_service_task_handle);
_mdns_service_task_handle = NULL;
}
while (_mdns_service_task_handle) {
Expand Down
15 changes: 15 additions & 0 deletions components/mdns/private_include/mdns_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@
#define _mdns_dbg_printf(...) printf(__VA_ARGS__)
#endif

#if CONFIG_MDNS_TASK_CREATE_FROM_SPIRAM
#define MDNS_TASK_MEMORY_CAPS (MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT)
#define MDNS_TASK_MEMORY_LOG "from SPIRAM"
#endif
#if CONFIG_MDNS_TASK_CREATE_FROM_INTERNAL
#define MDNS_TASK_MEMORY_CAPS (MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT)
#define MDNS_TASK_MEMORY_LOG "from internal RAM"
#endif

// Allocate memory from internal heap as default.
#ifndef MDNS_TASK_MEMORY_CAPS
#define MDNS_TASK_MEMORY_CAPS (MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT)
#define MDNS_TASK_MEMORY_LOG "from internal RAM"
#endif

/** Number of predefined interfaces */
#ifndef CONFIG_MDNS_PREDEF_NETIF_STA
#define CONFIG_MDNS_PREDEF_NETIF_STA 0
Expand Down

0 comments on commit 6ddcdae

Please sign in to comment.