2023-07-28 21:46:31 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 Jan Van Winkel <jan.van_winkel@dxplore.eu>
|
|
|
|
* Copyright (c) 2020 Intel Corporation
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "lvgl_mem.h"
|
|
|
|
#include <zephyr/kernel.h>
|
|
|
|
#include <zephyr/init.h>
|
|
|
|
#include <zephyr/sys/sys_heap.h>
|
|
|
|
|
2024-03-21 16:40:25 +08:00
|
|
|
#ifdef CONFIG_LV_Z_MEMORY_POOL_CUSTOM_SECTION
|
|
|
|
#define HEAP_MEM_ATTRIBUTES Z_GENERIC_SECTION(.lvgl_heap) __aligned(8)
|
|
|
|
#else
|
|
|
|
#define HEAP_MEM_ATTRIBUTES __aligned(8)
|
|
|
|
#endif /* CONFIG_LV_Z_MEMORY_POOL_CUSTOM_SECTION */
|
|
|
|
static char lvgl_heap_mem[CONFIG_LV_Z_MEM_POOL_SIZE] HEAP_MEM_ATTRIBUTES;
|
|
|
|
|
2023-07-28 21:46:31 +08:00
|
|
|
static struct sys_heap lvgl_heap;
|
|
|
|
static struct k_spinlock lvgl_heap_lock;
|
|
|
|
|
|
|
|
void *lvgl_malloc(size_t size)
|
|
|
|
{
|
|
|
|
k_spinlock_key_t key;
|
|
|
|
void *ret;
|
|
|
|
|
|
|
|
key = k_spin_lock(&lvgl_heap_lock);
|
|
|
|
ret = sys_heap_alloc(&lvgl_heap, size);
|
|
|
|
k_spin_unlock(&lvgl_heap_lock, key);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *lvgl_realloc(void *ptr, size_t size)
|
|
|
|
{
|
|
|
|
k_spinlock_key_t key;
|
|
|
|
void *ret;
|
|
|
|
|
|
|
|
key = k_spin_lock(&lvgl_heap_lock);
|
|
|
|
ret = sys_heap_realloc(&lvgl_heap, ptr, size);
|
|
|
|
k_spin_unlock(&lvgl_heap_lock, key);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void lvgl_free(void *ptr)
|
|
|
|
{
|
|
|
|
k_spinlock_key_t key;
|
|
|
|
|
|
|
|
key = k_spin_lock(&lvgl_heap_lock);
|
|
|
|
sys_heap_free(&lvgl_heap, ptr);
|
|
|
|
k_spin_unlock(&lvgl_heap_lock, key);
|
|
|
|
}
|
|
|
|
|
|
|
|
void lvgl_print_heap_info(bool dump_chunks)
|
|
|
|
{
|
|
|
|
k_spinlock_key_t key;
|
|
|
|
|
|
|
|
key = k_spin_lock(&lvgl_heap_lock);
|
|
|
|
sys_heap_print_info(&lvgl_heap, dump_chunks);
|
|
|
|
k_spin_unlock(&lvgl_heap_lock, key);
|
|
|
|
}
|
|
|
|
|
2023-09-08 02:29:15 +08:00
|
|
|
void lvgl_heap_init(void)
|
2023-07-28 21:46:31 +08:00
|
|
|
{
|
2023-09-26 21:26:07 +08:00
|
|
|
sys_heap_init(&lvgl_heap, &lvgl_heap_mem[0], CONFIG_LV_Z_MEM_POOL_SIZE);
|
2023-07-28 21:46:31 +08:00
|
|
|
}
|