mirror of
https://github.com/lvgl/lvgl.git
synced 2026-05-21 22:52:46 +08:00
feat(tlsf): add memory pool expansion support (#3757)
Co-authored-by: pengyiqiang <pengyiqiang@xiaomi.com>
This commit is contained in:
@@ -58,13 +58,18 @@ menu "LVGL configuration"
|
||||
|
||||
menu "Memory settings"
|
||||
config LV_MEM_CUSTOM
|
||||
bool "If true use custom malloc/free, otherwise use the built-in `lv_mem_alloc()` and `lv_mem_free()`"
|
||||
bool "If true use custom malloc/free, otherwise use the built-in `lv_malloc()` and `lv_free()`"
|
||||
|
||||
config LV_MEM_SIZE_KILOBYTES
|
||||
int "Size of the memory used by `lv_mem_alloc` in kilobytes (>= 2kB)"
|
||||
int "Size of the memory used by `lv_malloc()` in kilobytes (>= 2kB)"
|
||||
default 32
|
||||
depends on !LV_MEM_CUSTOM
|
||||
|
||||
config LV_MEM_POOL_EXPAND_SIZE_KILOBYTES
|
||||
int "Size of the memory expand for `lv_malloc()` in kilobytes"
|
||||
default 0
|
||||
depends on !LV_MEM_CUSTOM
|
||||
|
||||
config LV_MEM_ADDR
|
||||
hex "Address for the memory pool instead of allocating it as a normal array"
|
||||
default 0x0
|
||||
|
||||
@@ -38,6 +38,9 @@
|
||||
/*Size of the memory available for `lv_malloc()` in bytes (>= 2kB)*/
|
||||
#define LV_MEM_SIZE (128U * 1024U) /*[bytes]*/
|
||||
|
||||
/*Size of the memory expand for `lv_malloc()` in bytes*/
|
||||
#define LV_MEM_POOL_EXPAND_SIZE 0
|
||||
|
||||
/*Set an address for the memory pool instead of allocating it as a normal array. Can be in external SRAM too.*/
|
||||
#define LV_MEM_ADR 0 /*0: unused*/
|
||||
/*Instead of an address give a memory allocator that will be called to get a memory pool for LVGL. E.g. my_malloc*/
|
||||
|
||||
@@ -104,6 +104,15 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*Size of the memory expand for `lv_malloc()` in bytes*/
|
||||
#ifndef LV_MEM_POOL_EXPAND_SIZE
|
||||
#ifdef CONFIG_LV_MEM_POOL_EXPAND_SIZE
|
||||
#define LV_MEM_POOL_EXPAND_SIZE CONFIG_LV_MEM_POOL_EXPAND_SIZE
|
||||
#else
|
||||
#define LV_MEM_POOL_EXPAND_SIZE 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*Set an address for the memory pool instead of allocating it as a normal array. Can be in external SRAM too.*/
|
||||
#ifndef LV_MEM_ADR
|
||||
#ifdef CONFIG_LV_MEM_ADR
|
||||
|
||||
@@ -45,6 +45,10 @@ extern "C" {
|
||||
# define CONFIG_LV_MEM_SIZE (CONFIG_LV_MEM_SIZE_KILOBYTES * 1024U)
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LV_MEM_POOL_EXPAND_SIZE_KILOBYTES
|
||||
# define CONFIG_LV_MEM_POOL_EXPAND_SIZE (CONFIG_LV_MEM_POOL_EXPAND_SIZE_KILOBYTES * 1024U)
|
||||
#endif
|
||||
|
||||
/*------------------
|
||||
* MONITOR POSITION
|
||||
*-----------------*/
|
||||
|
||||
@@ -94,6 +94,16 @@ void lv_mem_deinit_builtin(void)
|
||||
lv_mem_init_builtin();
|
||||
}
|
||||
|
||||
lv_mem_builtin_pool_t * lv_mem_builtin_add_pool(void * mem, size_t bytes)
|
||||
{
|
||||
return lv_tlsf_add_pool(tlsf, mem, bytes);
|
||||
}
|
||||
|
||||
void lv_mem_builtin_remove_pool(lv_mem_builtin_pool_t * pool)
|
||||
{
|
||||
lv_tlsf_remove_pool(tlsf, pool);
|
||||
}
|
||||
|
||||
void lv_mem_monitor_builtin(lv_mem_monitor_t * mon_p)
|
||||
{
|
||||
/*Init the data*/
|
||||
|
||||
@@ -24,6 +24,8 @@ extern "C" {
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
typedef void * lv_mem_builtin_pool_t;
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
@@ -38,6 +40,20 @@ void lv_mem_init_builtin(void);
|
||||
*/
|
||||
void lv_mem_deinit_builtin(void);
|
||||
|
||||
/**
|
||||
* Add a new memory block to the builtin memory pool.
|
||||
* @param mem pointer to a new block of memory
|
||||
* @param bytes memory block size
|
||||
* @return pointer to lv_mem_builtin_pool handle
|
||||
*/
|
||||
lv_mem_builtin_pool_t * lv_mem_builtin_add_pool(void * mem, size_t bytes);
|
||||
|
||||
/**
|
||||
* Remove the memory pool.
|
||||
* @param lv_mem_builtin_pool_t pointer to lv_mem_builtin_pool handle
|
||||
*/
|
||||
void lv_mem_builtin_remove_pool(lv_mem_builtin_pool_t * pool);
|
||||
|
||||
void * lv_malloc_builtin(size_t size);
|
||||
void * lv_realloc_builtin(void * p, size_t new_size);
|
||||
void lv_free_builtin(void * p);
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@
|
||||
#undef printf
|
||||
#define printf LV_LOG_ERROR
|
||||
|
||||
#define TLSF_MAX_POOL_SIZE LV_MEM_SIZE
|
||||
#define TLSF_MAX_POOL_SIZE (LV_MEM_SIZE + LV_MEM_POOL_EXPAND_SIZE)
|
||||
|
||||
#if !defined(_DEBUG)
|
||||
#define _DEBUG 0
|
||||
|
||||
Reference in New Issue
Block a user