soc: espressif: Introduce runtime heap mempool
Add the `CONFIG_ESP_RUNTIME_HEAP` kconfig. This allows the memory pool to be created starting at `z_mapped_end` ending at `_heap_sentry`. Added choice symbol ESP_WIFI_HEAP_* to select which heap to use in the ESP WiFi adapter module. Add file heap.c with code to initialize the runtime heap. Size of the pool is checked during the runtime. Signed-off-by: Marek Matej <marek.matej@espressif.com>
This commit is contained in:
parent
e05d3ba661
commit
15d0189d3e
4 changed files with 78 additions and 2 deletions
|
@ -1,8 +1,11 @@
|
||||||
# Copyright (c) 2023 Espressif Systems (Shanghai) Co., Ltd.
|
# Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd.
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
if(CONFIG_SOC_SERIES_ESP32 OR CONFIG_SOC_SERIES_ESP32S2 OR CONFIG_SOC_SERIES_ESP32S3)
|
if(CONFIG_SOC_SERIES_ESP32 OR CONFIG_SOC_SERIES_ESP32S2 OR CONFIG_SOC_SERIES_ESP32S3)
|
||||||
zephyr_include_directories(include)
|
zephyr_include_directories(include)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
zephyr_sources_ifdef(CONFIG_ESP_SPIRAM psram.c)
|
if(NOT CONFIG_MCUBOOT AND NOT CONFIG_SOC_ESP32_APPCPU AND NOT CONFIG_SOC_ESP32S3_APPCPU)
|
||||||
|
zephyr_sources_ifdef(CONFIG_ESP_SPIRAM psram.c)
|
||||||
|
zephyr_sources_ifdef(CONFIG_ESP_RUNTIME_HEAP heap.c)
|
||||||
|
endif()
|
||||||
|
|
|
@ -24,6 +24,14 @@ config ESP_SIMPLE_BOOT
|
||||||
Please note that this method brings the system up with all memories set-up, but
|
Please note that this method brings the system up with all memories set-up, but
|
||||||
all other features, such as secure boot OTA or slots management are not available.
|
all other features, such as secure boot OTA or slots management are not available.
|
||||||
|
|
||||||
|
config ESP_RUNTIME_HEAP
|
||||||
|
bool
|
||||||
|
default y
|
||||||
|
help
|
||||||
|
Enabling this will allocate SRAM area starting by a last linked data at symbolic `_end`,
|
||||||
|
ending by a last memory location that can be safely accesed (depending on a boot mode).
|
||||||
|
This is a memory pool used in runtime to create a new heap memory.
|
||||||
|
|
||||||
rsource "Kconfig.spiram"
|
rsource "Kconfig.spiram"
|
||||||
rsource "Kconfig.esptool"
|
rsource "Kconfig.esptool"
|
||||||
rsource "Kconfig.flash"
|
rsource "Kconfig.flash"
|
||||||
|
|
|
@ -29,6 +29,23 @@ config ESP32_PHY_MAX_TX_POWER
|
||||||
int
|
int
|
||||||
default ESP32_PHY_MAX_WIFI_TX_POWER
|
default ESP32_PHY_MAX_WIFI_TX_POWER
|
||||||
|
|
||||||
|
choice ESP_WIFI_HEAP
|
||||||
|
prompt "Wifi adapter heap in use"
|
||||||
|
default ESP_WIFI_HEAP_RUNTIME
|
||||||
|
|
||||||
|
config ESP_WIFI_HEAP_RUNTIME
|
||||||
|
bool "Wifi adapter use ESP runtime heap"
|
||||||
|
depends on ESP_RUNTIME_HEAP
|
||||||
|
|
||||||
|
config ESP_WIFI_HEAP_SPIRAM
|
||||||
|
bool "Wifi adapter use SPIRAM heap"
|
||||||
|
depends on ESP_SPIRAM
|
||||||
|
|
||||||
|
config ESP_WIFI_HEAP_SYSTEM
|
||||||
|
bool "Wifi adapter use system heap"
|
||||||
|
|
||||||
|
endchoice # ESP_WIFI_HEAP
|
||||||
|
|
||||||
endmenu # ESP32 Wi-Fi config
|
endmenu # ESP32 Wi-Fi config
|
||||||
|
|
||||||
endif # SOC_FAMILY_ESPRESSIF_ESP32
|
endif # SOC_FAMILY_ESPRESSIF_ESP32
|
||||||
|
|
48
soc/espressif/common/heap.c
Normal file
48
soc/espressif/common/heap.c
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <zephyr/types.h>
|
||||||
|
#include <zephyr/kernel.h>
|
||||||
|
#include <soc.h>
|
||||||
|
#include <esp_err.h>
|
||||||
|
#include "esp_log.h"
|
||||||
|
|
||||||
|
#define TAG "heap"
|
||||||
|
|
||||||
|
/* ESP dynamic pool heap */
|
||||||
|
extern unsigned int z_mapped_end;
|
||||||
|
extern unsigned int _heap_sentry;
|
||||||
|
static void *esp_runtime_heap_init_mem = &z_mapped_end;
|
||||||
|
|
||||||
|
#define ESP_RUNTIME_HEAP_MAX_SIZE ((uintptr_t)&_heap_sentry - (uintptr_t)&z_mapped_end)
|
||||||
|
|
||||||
|
struct k_heap esp_runtime_heap;
|
||||||
|
|
||||||
|
static int esp_runtime_heap_init(void)
|
||||||
|
{
|
||||||
|
ESP_EARLY_LOGI(TAG, "ESP runtime heap init at 0x%x size %d kB.\n",
|
||||||
|
esp_runtime_heap_init_mem, ESP_RUNTIME_HEAP_MAX_SIZE/1024);
|
||||||
|
|
||||||
|
k_heap_init(&esp_runtime_heap, esp_runtime_heap_init_mem, ESP_RUNTIME_HEAP_MAX_SIZE);
|
||||||
|
|
||||||
|
#ifdef CONFIG_ESP_WIFI_HEAP_RUNTIME
|
||||||
|
|
||||||
|
#if defined(CONFIG_WIFI) && defined(CONFIG_BT)
|
||||||
|
assert(ESP_RUNTIME_HEAP_MAX_SIZE > 65535);
|
||||||
|
#elif defined(CONFIG_WIFI)
|
||||||
|
assert(ESP_RUNTIME_HEAP_MAX_SIZE > 51200);
|
||||||
|
#elif defined(CONFIG_BT)
|
||||||
|
assert(ESP_RUNTIME_HEAP_MAX_SIZE > 40960);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* CONFIG_ESP_WIFI_HEAP_RUNTIME */
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
SYS_INIT(esp_runtime_heap_init, PRE_KERNEL_2, CONFIG_KERNEL_INIT_PRIORITY_DEVICE);
|
Loading…
Add table
Add a link
Reference in a new issue