From 5d80af7d59c10b7890f0fc862e4efe807ce5fb73 Mon Sep 17 00:00:00 2001 From: Xia Xiaotian Date: Wed, 31 Jul 2019 21:04:35 +0800 Subject: [PATCH] Try to allocate some LWIP memories in SPIRAM first. If failed, try to allocate in internal RAM then. --- src/core/mem.c | 25 +++++++++++++++++++++++++ src/include/lwip/mem.h | 16 ---------------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/core/mem.c b/src/core/mem.c index db3b7cc5..c5f90f55 100644 --- a/src/core/mem.c +++ b/src/core/mem.c @@ -97,12 +97,37 @@ mem_trim(void *mem, mem_size_t size) #ifndef mem_clib_free #define mem_clib_free free #endif +#if ESP_LWIP +/** + * If CONFIG_ALLOC_MEMORY_IN_SPIRAM_FIRST is enabled, Try to + * allocate memory for lwip in SPIRAM firstly. If failed, try to allocate + * internal memory then. + */ +#if CONFIG_WIFI_LWIP_ALLOCATION_FROM_SPIRAM_FIRST +#ifndef mem_clib_malloc +#define mem_clib_malloc(size) heap_caps_malloc_prefer(size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL) +#endif +#ifndef mem_clib_calloc +#define mem_clib_calloc(n, size) heap_caps_calloc_prefer(n, size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL) +#endif +#else /* CONFIG_WIFI_LWIP_ALLOCATION_FROM_SPIRAM_FIRST */ #ifndef mem_clib_malloc #define mem_clib_malloc malloc #endif #ifndef mem_clib_calloc #define mem_clib_calloc calloc #endif +#endif /* CONFIG_WIFI_LWIP_ALLOCATION_FROM_SPIRAM_FIRST */ + +#else /* ESP_LWIP */ + +#ifndef mem_clib_malloc +#define mem_clib_malloc malloc +#endif +#ifndef mem_clib_calloc +#define mem_clib_calloc calloc +#endif +#endif /* ESP_LWIP */ #if LWIP_STATS && MEM_STATS #define MEM_LIBC_STATSHELPER_SIZE LWIP_MEM_ALIGN_SIZE(sizeof(mem_size_t)) diff --git a/src/include/lwip/mem.h b/src/include/lwip/mem.h index 73540f7e..ff208d25 100644 --- a/src/include/lwip/mem.h +++ b/src/include/lwip/mem.h @@ -55,22 +55,6 @@ typedef size_t mem_size_t; typedef u16_t mem_size_t; #define MEM_SIZE_F U16_F -#if ESP_LWIP -/** - * lwip_malloc: if CONFIG_ALLOC_MEMORY_IN_SPIRAM_FIRST is enabled, Try to - * allocate memory for lwip in SPIRAM firstly. If failed, try to allocate - * internal memory then. - */ -#if CONFIG_WIFI_LWIP_ALLOCATION_FROM_SPIRAM_FIRST -#ifndef mem_malloc -#define mem_malloc(size) heap_caps_malloc_prefer(size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL) -#endif -#ifndef mem_calloc -#define mem_calloc(n, size) heap_caps_calloc_prefer(n, size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL) -#endif -#endif -#endif - #else /* MEM_SIZE would have to be aligned, but using 64000 here instead of