mirror of
https://github.com/espressif/ESP8266_RTOS_SDK.git
synced 2025-08-06 15:15:15 +08:00
feat(heap): Remove old heap and modify old heap API
This commit is contained in:
@ -29,6 +29,9 @@
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#ifndef BOOTLOADER_BUILD
|
||||
#include "esp_heap_caps.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -73,82 +76,24 @@ int ets_printf(const char *fmt, ...);
|
||||
#define os_printf printf
|
||||
#endif
|
||||
|
||||
/* Note: check_memleak_debug_enable is a weak function inside SDK.
|
||||
* please copy following codes to user_main.c.
|
||||
#include "esp_libc.h"
|
||||
|
||||
bool check_memleak_debug_enable(void)
|
||||
{
|
||||
return MEMLEAK_DEBUG_ENABLE;
|
||||
}
|
||||
*/
|
||||
|
||||
#ifndef MEMLEAK_DEBUG
|
||||
#define MEMLEAK_DEBUG_ENABLE 0
|
||||
#ifndef os_free
|
||||
#define os_free(s) free(s)
|
||||
#define os_free(s) heap_caps_free(s)
|
||||
#endif
|
||||
|
||||
#ifndef os_malloc
|
||||
#define os_malloc(s) malloc(s)
|
||||
#define os_malloc(s) heap_caps_malloc(s, MALLOC_CAP_32BIT)
|
||||
#endif
|
||||
|
||||
#ifndef os_calloc
|
||||
#define os_calloc(p, s) calloc(p, s)
|
||||
#define os_calloc(p, s) heap_caps_calloc(p, s, MALLOC_CAP_32BIT)
|
||||
#endif
|
||||
|
||||
#ifndef os_realloc
|
||||
#define os_realloc(p, s) realloc(p, s)
|
||||
#define os_realloc(p, s) heap_caps_realloc(p, s, MALLOC_CAP_32BIT)
|
||||
#endif
|
||||
|
||||
#ifndef os_zalloc
|
||||
#define os_zalloc(s) zalloc(s)
|
||||
#endif
|
||||
#else
|
||||
#define MEMLEAK_DEBUG_ENABLE 1
|
||||
|
||||
#ifndef os_free
|
||||
#define os_free(s) \
|
||||
do{\
|
||||
vPortFree_trace(s, __FILE__, __LINE__);\
|
||||
}while(0)
|
||||
#endif
|
||||
|
||||
#ifndef os_malloc
|
||||
#define os_malloc(s) \
|
||||
({ \
|
||||
pvPortMalloc_trace(s, __FILE__, __LINE__, false); \
|
||||
})
|
||||
#endif
|
||||
|
||||
#ifndef os_malloc_iram
|
||||
#define os_malloc_iram(s) \
|
||||
({ \
|
||||
pvPortMalloc_trace(s, __FILE__, __LINE__, true); \
|
||||
})
|
||||
#endif
|
||||
|
||||
#ifndef os_calloc
|
||||
#define os_calloc(p, s) \
|
||||
({ \
|
||||
pvPortCalloc_trace(p, s, __FILE__, __LINE__); \
|
||||
})
|
||||
#endif
|
||||
|
||||
#ifndef os_realloc
|
||||
#define os_realloc(p, s) \
|
||||
({ \
|
||||
pvPortRealloc_trace(p, s, __FILE__, __LINE__); \
|
||||
})
|
||||
#endif
|
||||
|
||||
#ifndef os_zalloc
|
||||
#define os_zalloc(s) \
|
||||
({ \
|
||||
pvPortZalloc_trace(s, __FILE__, __LINE__); \
|
||||
})
|
||||
#endif
|
||||
|
||||
#define os_zalloc(s) heap_caps_zalloc(s, MALLOC_CAP_32BIT)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -274,75 +274,61 @@ static bool timer_delete_wrapper(void *timer, uint32_t ticks)
|
||||
|
||||
static void *malloc_wrapper(uint32_t s, uint32_t cap)
|
||||
{
|
||||
bool iram;
|
||||
uint32_t os_caps;
|
||||
void *return_addr = (void *)__builtin_return_address(0);
|
||||
|
||||
if (cap & (OSI_MALLOC_CAP_8BIT | OSI_MALLOC_CAP_DMA))
|
||||
iram = false;
|
||||
os_caps = MALLOC_CAP_8BIT | MALLOC_CAP_DMA;
|
||||
else
|
||||
iram = true;
|
||||
os_caps = MALLOC_CAP_32BIT;
|
||||
|
||||
return pvPortMalloc_trace(s, return_addr, (unsigned)-1, iram);
|
||||
return _heap_caps_malloc(s, os_caps, return_addr, 0);
|
||||
}
|
||||
|
||||
static void *zalloc_wrapper(uint32_t s, uint32_t cap)
|
||||
{
|
||||
bool iram;
|
||||
uint32_t os_caps;
|
||||
void *return_addr = (void *)__builtin_return_address(0);
|
||||
|
||||
if (cap & (OSI_MALLOC_CAP_8BIT | OSI_MALLOC_CAP_DMA))
|
||||
iram = false;
|
||||
os_caps = MALLOC_CAP_8BIT | MALLOC_CAP_DMA;
|
||||
else
|
||||
iram = true;
|
||||
os_caps = MALLOC_CAP_32BIT;
|
||||
|
||||
char *p = pvPortMalloc_trace(s, return_addr, (unsigned)-1, iram);
|
||||
if (p)
|
||||
memset(p, 0, s);
|
||||
|
||||
return p;
|
||||
return _heap_caps_zalloc(s, os_caps, return_addr, 0);
|
||||
}
|
||||
|
||||
static void *realloc_wrapper(void *ptr, uint32_t s, uint32_t cap)
|
||||
{
|
||||
bool iram;
|
||||
uint32_t os_caps;
|
||||
void *return_addr = (void *)__builtin_return_address(0);
|
||||
|
||||
if (cap & (OSI_MALLOC_CAP_8BIT | OSI_MALLOC_CAP_DMA))
|
||||
iram = false;
|
||||
os_caps = MALLOC_CAP_8BIT | MALLOC_CAP_DMA;
|
||||
else
|
||||
iram = true;
|
||||
os_caps = MALLOC_CAP_32BIT;
|
||||
|
||||
void *p = pvPortMalloc_trace(s, return_addr, (unsigned)-1, iram);
|
||||
if (p && ptr) {
|
||||
memcpy(p, ptr, s);
|
||||
vPortFree_trace(ptr, return_addr, (unsigned)-1);
|
||||
}
|
||||
|
||||
return p;
|
||||
return _heap_caps_realloc(ptr, s, os_caps, return_addr, 0);
|
||||
}
|
||||
|
||||
static void *calloc_wrapper(uint32_t cnt, uint32_t s, uint32_t cap)
|
||||
{
|
||||
bool iram;
|
||||
uint32_t os_caps;
|
||||
void *return_addr = (void *)__builtin_return_address(0);
|
||||
|
||||
if (cap & (OSI_MALLOC_CAP_8BIT | OSI_MALLOC_CAP_DMA))
|
||||
iram = false;
|
||||
os_caps = MALLOC_CAP_8BIT | MALLOC_CAP_DMA;
|
||||
else
|
||||
iram = true;
|
||||
os_caps = MALLOC_CAP_32BIT;
|
||||
|
||||
char *p = pvPortMalloc_trace(cnt * s, return_addr, (unsigned)-1, iram);
|
||||
if (p)
|
||||
memset(p, 0, cnt * s);
|
||||
|
||||
return p;
|
||||
return _heap_caps_calloc(cnt , s, os_caps, return_addr, 0);
|
||||
}
|
||||
|
||||
static void free_wrapper(void *ptr)
|
||||
{
|
||||
void *return_addr = (void *)__builtin_return_address(0);
|
||||
|
||||
vPortFree_trace(ptr, return_addr, (unsigned)-1);
|
||||
_heap_caps_free(ptr, return_addr, 0);
|
||||
}
|
||||
|
||||
static void srand_wrapper(uint32_t seed)
|
||||
|
@ -339,7 +339,7 @@ void esp_chip_info(esp_chip_info_t* out_info)
|
||||
*/
|
||||
uint32_t esp_get_free_heap_size(void)
|
||||
{
|
||||
return xPortGetFreeHeapSize();
|
||||
return heap_caps_get_free_size(MALLOC_CAP_32BIT);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -347,5 +347,5 @@ uint32_t esp_get_free_heap_size(void)
|
||||
*/
|
||||
uint32_t esp_get_minimum_free_heap_size(void)
|
||||
{
|
||||
return xPortGetMinimumEverFreeHeapSize();
|
||||
return heap_caps_get_minimum_free_size(MALLOC_CAP_32BIT);
|
||||
}
|
||||
|
Reference in New Issue
Block a user