From 674682e5a885b661c165fdf9e36864f526d0bfca Mon Sep 17 00:00:00 2001 From: rechrtb Date: Sun, 13 Nov 2022 17:57:43 +0800 Subject: [PATCH] Add option to prioritize DRAM allocation over IRAM --- components/heap/Kconfig | 8 ++++++++ components/heap/port/esp8266/esp_heap_init.c | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/components/heap/Kconfig b/components/heap/Kconfig index 551cf58d4..9bc8ce7c1 100644 --- a/components/heap/Kconfig +++ b/components/heap/Kconfig @@ -13,4 +13,12 @@ menu "Heap memory" help Enables heap tracing API. + config HEAP_PRIO_8BIT_RAM + bool "Prioritize allocation of 8-bit access capable RAM" + default n + depends on !HEAP_DISABLE_IRAM + help + Set DRAM region ahead of IRAM region during initialization, so that allocations + can be made against it first. + endmenu diff --git a/components/heap/port/esp8266/esp_heap_init.c b/components/heap/port/esp8266/esp_heap_init.c index 8135911be..5d950adbe 100644 --- a/components/heap/port/esp8266/esp_heap_init.c +++ b/components/heap/port/esp8266/esp_heap_init.c @@ -39,6 +39,23 @@ void heap_caps_init(void) extern char _bss_end; size_t heap_region_num = 0; +#if CONFIG_HEAP_PRIO_8BIT_RAM + g_heap_region[heap_region_num].start_addr = (uint8_t *)&_bss_end; + g_heap_region[heap_region_num].total_size = ((size_t)(0x40000000 - (uint32_t)&_bss_end)); + g_heap_region[heap_region_num].caps = MALLOC_CAP_8BIT | MALLOC_CAP_32BIT | MALLOC_CAP_DMA; + heap_region_num++; + + // CONFIG_HEAP_PRIO_8BIT_RAM is only available when CONFIG_HEAP_DISABLE_IRAM=n + extern char _iram_end; + const size_t iram_size = 0x40100000 + CONFIG_SOC_IRAM_SIZE - ((size_t)&_iram_end); + + if (iram_size > HEAP_REGION_IRAM_MIN && iram_size < HEAP_REGION_IRAM_MAX) { + g_heap_region[heap_region_num].start_addr = (uint8_t *)&_iram_end; + g_heap_region[heap_region_num].total_size = iram_size; + g_heap_region[heap_region_num].caps = MALLOC_CAP_32BIT | MALLOC_CAP_EXEC; + heap_region_num++; + } +#else #ifndef CONFIG_HEAP_DISABLE_IRAM extern char _iram_end; const size_t iram_size = 0x40100000 + CONFIG_SOC_IRAM_SIZE - ((size_t)&_iram_end); @@ -55,6 +72,7 @@ void heap_caps_init(void) g_heap_region[heap_region_num].total_size = ((size_t)(0x40000000 - (uint32_t)&_bss_end)); g_heap_region[heap_region_num].caps = MALLOC_CAP_8BIT | MALLOC_CAP_32BIT | MALLOC_CAP_DMA; heap_region_num++; +#endif esp_heap_caps_init_region(g_heap_region, heap_region_num); }