mirror of
https://github.com/espressif/ESP8266_RTOS_SDK.git
synced 2025-06-01 16:16:54 +08:00
feat(heap): add heap private config to enable/disable using IRAM as heap
This commit is contained in:
@ -14,26 +14,36 @@
|
||||
|
||||
#include "esp_heap_caps.h"
|
||||
|
||||
#define HEAP_REGION_IRAM_MIN 512
|
||||
#define HEAP_REGION_IRAM_MAX 0x00010000
|
||||
|
||||
heap_region_t g_heap_region[HEAP_REGIONS_MAX];
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initialize the capability-aware heap allocator.
|
||||
*/
|
||||
void heap_caps_init(void)
|
||||
{
|
||||
extern char _bss_end;
|
||||
size_t heap_region_num = 0;
|
||||
|
||||
#ifndef CONFIG_SOC_FULL_ICACHE
|
||||
#ifndef CONFIG_HEAP_DISABLE_IRAM
|
||||
extern char _iram_end;
|
||||
const size_t iram_size = 0x40100000 + CONFIG_SOC_IRAM_SIZE - ((size_t)&_iram_end);
|
||||
|
||||
g_heap_region[0].start_addr = (uint8_t *)&_iram_end;
|
||||
g_heap_region[0].total_size = ((size_t)(0x4010C000 - (uint32_t)&_iram_end));
|
||||
g_heap_region[0].caps = MALLOC_CAP_32BIT;
|
||||
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;
|
||||
heap_region_num++;
|
||||
}
|
||||
#endif
|
||||
|
||||
g_heap_region[HEAP_REGIONS_MAX - 1].start_addr = (uint8_t *)&_bss_end;
|
||||
g_heap_region[HEAP_REGIONS_MAX - 1].total_size = ((size_t)(0x40000000 - (uint32_t)&_bss_end));
|
||||
g_heap_region[HEAP_REGIONS_MAX - 1].caps = MALLOC_CAP_8BIT | MALLOC_CAP_32BIT | MALLOC_CAP_DMA;
|
||||
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++;
|
||||
|
||||
esp_heap_caps_init_region(g_heap_region, HEAP_REGIONS_MAX);
|
||||
esp_heap_caps_init_region(g_heap_region, heap_region_num);
|
||||
}
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
#define HEAP_ALIGN_SIZE 4
|
||||
|
||||
#ifdef CONFIG_SOC_FULL_ICACHE
|
||||
#ifdef CONFIG_HEAP_DISABLE_IRAM
|
||||
#define HEAP_REGIONS_MAX 1
|
||||
#else
|
||||
#define HEAP_REGIONS_MAX 2
|
||||
|
@ -103,9 +103,11 @@ static inline size_t blk_link_size(mem_blk_t *blk)
|
||||
static inline size_t get_blk_region(void *ptr)
|
||||
{
|
||||
size_t num;
|
||||
extern heap_region_t g_heap_region[HEAP_REGIONS_MAX];
|
||||
extern size_t g_heap_region_num;
|
||||
extern heap_region_t g_heap_region[];
|
||||
|
||||
for (num = 0; num < HEAP_REGIONS_MAX; num++) {
|
||||
|
||||
for (num = 0; num < g_heap_region_num; num++) {
|
||||
if ((uint8_t *)ptr > (uint8_t *)g_heap_region[num].start_addr
|
||||
&& (uint8_t *)ptr < ((uint8_t *)g_heap_region[num].start_addr + g_heap_region[num].total_size)) {
|
||||
break;
|
||||
|
Reference in New Issue
Block a user