[feat] remove pmem_heap
This commit is contained in:
parent
78447ffd81
commit
cd3c5062f7
@ -1,7 +1,3 @@
|
|||||||
if(CONFIG_FREERTOS)
|
|
||||||
add_definitions(-DCONFIG_FREERTOS)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
enable_language(ASM)
|
enable_language(ASM)
|
||||||
|
|
||||||
add_library(sdk STATIC)
|
add_library(sdk STATIC)
|
||||||
|
|||||||
@ -13,8 +13,13 @@ target_link_libraries(${TARGET} INTERFACE printf)
|
|||||||
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/os os)
|
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/os os)
|
||||||
target_link_libraries(${TARGET} INTERFACE os)
|
target_link_libraries(${TARGET} INTERFACE os)
|
||||||
|
|
||||||
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/shell shell)
|
|
||||||
target_link_libraries(${TARGET} INTERFACE shell)
|
|
||||||
|
if (${CONFIG_SHELL})
|
||||||
|
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/shell shell)
|
||||||
|
target_link_libraries(${TARGET} INTERFACE shell)
|
||||||
|
set(CONFIG_TLSF 1)
|
||||||
|
endif()
|
||||||
|
|
||||||
if (${CONFIG_TLSF})
|
if (${CONFIG_TLSF})
|
||||||
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/mm mm)
|
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/mm mm)
|
||||||
|
|||||||
@ -32,7 +32,6 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
struct mem_heap_s g_kmemheap;
|
struct mem_heap_s g_kmemheap;
|
||||||
struct mem_heap_s g_pmemheap;
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Function Prototypes
|
* Private Function Prototypes
|
||||||
@ -125,23 +124,6 @@ void *kcalloc(size_t size, size_t len)
|
|||||||
return port_calloc(KMEM_HEAP, size, len);
|
return port_calloc(KMEM_HEAP, size, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: pmem_init
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* Allocate memory from the user heap.
|
|
||||||
*
|
|
||||||
* Input Parameters:
|
|
||||||
*
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
void pmem_init(void *heapstart, size_t heapsize)
|
|
||||||
{
|
|
||||||
MEM_LOG("Heap: start=%p size=%u\r\n", heapstart, heapsize);
|
|
||||||
|
|
||||||
port_mem_init(PMEM_HEAP, heapstart, heapsize);
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: malloc
|
* Name: malloc
|
||||||
*
|
*
|
||||||
@ -160,7 +142,7 @@ void *malloc(size_t size)
|
|||||||
{
|
{
|
||||||
MEM_LOG("malloc %d\r\n", size);
|
MEM_LOG("malloc %d\r\n", size);
|
||||||
|
|
||||||
return port_malloc(PMEM_HEAP, size);
|
return port_malloc(KMEM_HEAP, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -180,7 +162,7 @@ void *malloc(size_t size)
|
|||||||
|
|
||||||
void *realloc(void *old, size_t newlen)
|
void *realloc(void *old, size_t newlen)
|
||||||
{
|
{
|
||||||
return port_realloc(PMEM_HEAP, old, newlen);
|
return port_realloc(KMEM_HEAP, old, newlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -199,7 +181,7 @@ void *realloc(void *old, size_t newlen)
|
|||||||
|
|
||||||
void *calloc(size_t size, size_t len)
|
void *calloc(size_t size, size_t len)
|
||||||
{
|
{
|
||||||
return port_calloc(PMEM_HEAP, size, len);
|
return port_calloc(KMEM_HEAP, size, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -217,7 +199,7 @@ void *calloc(size_t size, size_t len)
|
|||||||
|
|
||||||
void *memalign(size_t align, size_t size)
|
void *memalign(size_t align, size_t size)
|
||||||
{
|
{
|
||||||
return port_malloc_align(PMEM_HEAP, align, size);
|
return port_malloc_align(KMEM_HEAP, align, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -233,7 +215,7 @@ void free(void *addr)
|
|||||||
{
|
{
|
||||||
MEM_LOG("free %p\r\n", addr);
|
MEM_LOG("free %p\r\n", addr);
|
||||||
|
|
||||||
port_free(PMEM_HEAP, addr);
|
port_free(KMEM_HEAP, addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -253,54 +235,3 @@ uint32_t kfree_size(void)
|
|||||||
|
|
||||||
return info.free_size;
|
return info.free_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t pfree_size(void)
|
|
||||||
{
|
|
||||||
#if defined(CONFIG_PSRAM) && defined(BL616) // only for bl618
|
|
||||||
struct meminfo info;
|
|
||||||
|
|
||||||
port_mem_usage(PMEM_HEAP, &info);
|
|
||||||
|
|
||||||
return info.free_size;
|
|
||||||
#else
|
|
||||||
return 0;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef CONFIG_SHELL
|
|
||||||
#include <shell.h>
|
|
||||||
|
|
||||||
int cmd_free(int argc, char **argv)
|
|
||||||
{
|
|
||||||
const char *Header = "total free alloc mxblk frnode alnode \r\n";
|
|
||||||
struct meminfo info;
|
|
||||||
char *mem;
|
|
||||||
|
|
||||||
mem = malloc(64);
|
|
||||||
port_mem_usage(KMEM_HEAP, &info);
|
|
||||||
|
|
||||||
snprintf(mem, 64, "%-8d%-8d%-8d%-8d%-8d%-8d\r\n", info.total_size, info.free_size, info.used_size, info.max_free_size,
|
|
||||||
info.free_node, info.used_node);
|
|
||||||
|
|
||||||
printf(Header);
|
|
||||||
printf(mem);
|
|
||||||
|
|
||||||
free(mem);
|
|
||||||
|
|
||||||
#if defined(CONFIG_PSRAM) && defined(BL616) // only for bl618
|
|
||||||
mem = malloc(64);
|
|
||||||
port_mem_usage(PMEM_HEAP, &info);
|
|
||||||
|
|
||||||
snprintf(mem, 64, "%-8d%-8d%-8d%-8d%-8d%-8d\r\n", info.total_size, info.free_size, info.used_size, info.max_free_size,
|
|
||||||
info.free_node, info.used_node);
|
|
||||||
|
|
||||||
printf(Header);
|
|
||||||
printf(mem);
|
|
||||||
|
|
||||||
free(mem);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
SHELL_CMD_EXPORT_ALIAS(cmd_free, free, show memory usage);
|
|
||||||
#endif
|
|
||||||
|
|||||||
@ -48,11 +48,6 @@
|
|||||||
#define MEM_IS_VALID(heap) ((heap) != NULL && (heap)->mem_impl != NULL)
|
#define MEM_IS_VALID(heap) ((heap) != NULL && (heap)->mem_impl != NULL)
|
||||||
|
|
||||||
#define KMEM_HEAP &g_kmemheap
|
#define KMEM_HEAP &g_kmemheap
|
||||||
#if defined(CONFIG_PSRAM) && (!defined(CONFIG_HEAP_ALWAYS_ON_KMEM))
|
|
||||||
#define PMEM_HEAP &g_pmemheap
|
|
||||||
#else
|
|
||||||
#define PMEM_HEAP &g_kmemheap
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Types
|
* Public Types
|
||||||
@ -89,7 +84,6 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
EXTERN struct mem_heap_s g_kmemheap;
|
EXTERN struct mem_heap_s g_kmemheap;
|
||||||
EXTERN struct mem_heap_s g_pmemheap;
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Function Prototypes
|
* Public Function Prototypes
|
||||||
@ -101,9 +95,6 @@ void *kcalloc(size_t size, size_t len);
|
|||||||
void kfree(void *addr);
|
void kfree(void *addr);
|
||||||
uint32_t kfree_size(void);
|
uint32_t kfree_size(void);
|
||||||
|
|
||||||
void pmem_init(void *heapstart, size_t heapsize);
|
|
||||||
uint32_t pfree_size(void);
|
|
||||||
|
|
||||||
/* private api for mm*/
|
/* private api for mm*/
|
||||||
|
|
||||||
void port_mem_init(struct mem_heap_s *heap, void *heapstart, size_t heapsize);
|
void port_mem_init(struct mem_heap_s *heap, void *heapstart, size_t heapsize);
|
||||||
|
|||||||
@ -7,15 +7,6 @@ add_library(${TARGET} STATIC ${FILELIST})
|
|||||||
|
|
||||||
target_include_directories(${TARGET} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
target_include_directories(${TARGET} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
|
|
||||||
if(CONFIG_FREERTOS)
|
|
||||||
target_sources(${TARGET} PRIVATE shell_freertos.c)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
target_compile_definitions(${TARGET} PRIVATE -DCONFIG_SHELL)
|
|
||||||
if(CONFIG_SHELL_EXEC_THREAD)
|
|
||||||
target_compile_definitions(${TARGET} PRIVATE -DCONFIG_SHELL_EXEC_THREAD)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(CONFIG_SHELL_CMD_SIZE)
|
if(CONFIG_SHELL_CMD_SIZE)
|
||||||
target_compile_definitions(${TARGET} PRIVATE -DSHELL_CMD_SIZE=${CONFIG_SHELL_CMD_SIZE})
|
target_compile_definitions(${TARGET} PRIVATE -DSHELL_CMD_SIZE=${CONFIG_SHELL_CMD_SIZE})
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@ -1,183 +0,0 @@
|
|||||||
#include "shell.h"
|
|
||||||
#include <FreeRTOS.h>
|
|
||||||
#include "semphr.h"
|
|
||||||
#include "ring_buffer.h"
|
|
||||||
#include "bflb_uart.h"
|
|
||||||
#include "mem.h"
|
|
||||||
|
|
||||||
#if defined(CONFIG_SHELL_EXEC_THREAD) && CONFIG_SHELL_EXEC_THREAD
|
|
||||||
static int shell_exec_argc;
|
|
||||||
static char *shell_exec_argv[SHELL_ARG_NUM + 1];
|
|
||||||
static char shell_exec_line[SHELL_CMD_SIZE];
|
|
||||||
static ptrdiff_t shell_exec_line_diff;
|
|
||||||
TaskHandle_t shell_exec_handle;
|
|
||||||
static ATTR_NOCACHE_RAM_SECTION volatile bool shell_exec_end = true;
|
|
||||||
|
|
||||||
static void shell_exec_task(void *pvParameters)
|
|
||||||
{
|
|
||||||
shell_exec_end = false;
|
|
||||||
__ASM volatile("fence");
|
|
||||||
((cmd_function_t)(pvParameters))(shell_exec_argc, shell_exec_argv);
|
|
||||||
shell_exec_end = true;
|
|
||||||
__ASM volatile("fence");
|
|
||||||
vTaskDelete(shell_exec_handle);
|
|
||||||
shell_exec_handle = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void shell_dup_line(char *cmd, uint32_t length)
|
|
||||||
{
|
|
||||||
memcpy(shell_exec_line, cmd, length + 1);
|
|
||||||
shell_exec_line_diff = shell_exec_line - cmd;
|
|
||||||
}
|
|
||||||
|
|
||||||
void shell_abort_exec(int sig)
|
|
||||||
{
|
|
||||||
(void)sig;
|
|
||||||
if (shell_exec_end == false) {
|
|
||||||
shell_exec_end = true;
|
|
||||||
__ASM volatile("fence");
|
|
||||||
vTaskDelete(shell_exec_handle);
|
|
||||||
shell_exec_handle = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int shell_start_exec(cmd_function_t func, int argc, char *argv[])
|
|
||||||
{
|
|
||||||
BaseType_t xReturned;
|
|
||||||
shell_abort_exec(SHELL_SIGINT);
|
|
||||||
shell_exec_argc = argc;
|
|
||||||
|
|
||||||
for (uint8_t i = 0; i < argc; i++) {
|
|
||||||
shell_exec_argv[i] = argv[i] + shell_exec_line_diff;
|
|
||||||
}
|
|
||||||
shell_exec_argv[argc] = NULL;
|
|
||||||
|
|
||||||
__ASM volatile("fence");
|
|
||||||
xReturned = xTaskCreate(shell_exec_task, (char *)"shell_exec_task", SHELL_EXEC_THREAD_STACK_SIZE, func, SHELL_EXEC_THREAD_PRIO, &shell_exec_handle);
|
|
||||||
|
|
||||||
if (xReturned == pdPASS) {
|
|
||||||
return 0;
|
|
||||||
} else {
|
|
||||||
shell_exec_end = true;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static TaskHandle_t shell_handle;
|
|
||||||
SemaphoreHandle_t sem_shell = NULL;
|
|
||||||
|
|
||||||
Ring_Buffer_Type shell_rb;
|
|
||||||
|
|
||||||
uint8_t shell_buffer[512];
|
|
||||||
|
|
||||||
void shell_release_sem(void)
|
|
||||||
{
|
|
||||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
|
||||||
|
|
||||||
if (xPortIsInsideInterrupt()) {
|
|
||||||
int ret = xSemaphoreGiveFromISR(sem_shell, &xHigherPriorityTaskWoken);
|
|
||||||
if (ret == pdPASS) {
|
|
||||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
xSemaphoreGive(sem_shell);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct bflb_device_s *uart_shell = NULL;
|
|
||||||
|
|
||||||
void uart_shell_isr(int irq, void *arg)
|
|
||||||
{
|
|
||||||
uint32_t intstatus = bflb_uart_get_intstatus(uart_shell);
|
|
||||||
if (intstatus & UART_INTSTS_RX_FIFO) {
|
|
||||||
while (bflb_uart_rxavailable(uart_shell)) {
|
|
||||||
Ring_Buffer_Write_Byte(&shell_rb, bflb_uart_getchar(uart_shell));
|
|
||||||
}
|
|
||||||
shell_release_sem();
|
|
||||||
}
|
|
||||||
if (intstatus & UART_INTSTS_RTO) {
|
|
||||||
while (bflb_uart_rxavailable(uart_shell)) {
|
|
||||||
Ring_Buffer_Write_Byte(&shell_rb, bflb_uart_getchar(uart_shell));
|
|
||||||
}
|
|
||||||
shell_release_sem();
|
|
||||||
bflb_uart_int_clear(uart_shell, UART_INTCLR_RTO);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void shell_task(void *pvParameters)
|
|
||||||
{
|
|
||||||
uint8_t data;
|
|
||||||
uint32_t len;
|
|
||||||
|
|
||||||
bflb_uart_feature_control(uart_shell, UART_CMD_CLR_RX_FIFO, 0);
|
|
||||||
bflb_uart_rxint_mask(uart_shell, false);
|
|
||||||
bflb_irq_attach(uart_shell->irq_num, uart_shell_isr, NULL);
|
|
||||||
bflb_irq_enable(uart_shell->irq_num);
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
if (xSemaphoreTake(sem_shell, portMAX_DELAY) == pdTRUE) {
|
|
||||||
len = Ring_Buffer_Get_Length(&shell_rb);
|
|
||||||
for (uint32_t i = 0; i < len; i++) {
|
|
||||||
Ring_Buffer_Read_Byte(&shell_rb, &data);
|
|
||||||
shell_handler(data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void shell_init_with_task(struct bflb_device_s *shell)
|
|
||||||
{
|
|
||||||
vSemaphoreCreateBinary(sem_shell);
|
|
||||||
uart_shell = shell;
|
|
||||||
|
|
||||||
Ring_Buffer_Init(&shell_rb, shell_buffer, sizeof(shell_buffer), NULL, NULL);
|
|
||||||
|
|
||||||
shell_init();
|
|
||||||
xTaskCreate(shell_task, (char *)"shell_task", SHELL_THREAD_STACK_SIZE, NULL, SHELL_THREAD_PRIO, &shell_handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
void shell_exe_cmd(uint8_t *cmd, uint16_t len)
|
|
||||||
{
|
|
||||||
Ring_Buffer_Write(&shell_rb, cmd, len);
|
|
||||||
shell_release_sem();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ps_cmd(int argc, char **argv)
|
|
||||||
{
|
|
||||||
char *pcWriteBuffer, *info;
|
|
||||||
const char *const pcHeader = "State Priority Stack # Base\r\n********************************************************\r\n";
|
|
||||||
BaseType_t xSpacePadding;
|
|
||||||
|
|
||||||
info = malloc(1536);
|
|
||||||
if (NULL == info) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
pcWriteBuffer = info;
|
|
||||||
|
|
||||||
/* Generate a table of task stats. */
|
|
||||||
if (strlcpy(pcWriteBuffer, "Task", 1536) >= 1536)
|
|
||||||
printf("[OS]: strlcpy truncated \r\n");
|
|
||||||
pcWriteBuffer += strlen(pcWriteBuffer);
|
|
||||||
|
|
||||||
/* Minus three for the null terminator and half the number of characters in
|
|
||||||
"Task" so the column lines up with the centre of the heading. */
|
|
||||||
for (xSpacePadding = strlen("Task"); xSpacePadding < (configMAX_TASK_NAME_LEN - 3); xSpacePadding++) {
|
|
||||||
/* Add a space to align columns after the task's name. */
|
|
||||||
*pcWriteBuffer = ' ';
|
|
||||||
pcWriteBuffer++;
|
|
||||||
|
|
||||||
/* Ensure always terminated. */
|
|
||||||
*pcWriteBuffer = 0x00;
|
|
||||||
}
|
|
||||||
if (strlcpy(pcWriteBuffer, pcHeader, 1536 - (pcWriteBuffer - info)) >=
|
|
||||||
1536 - (pcWriteBuffer - info))
|
|
||||||
printf("[OS]: strlcpy truncated \r\n");
|
|
||||||
vTaskList(pcWriteBuffer + strlen(pcHeader));
|
|
||||||
printf("\r\n");
|
|
||||||
printf(info);
|
|
||||||
|
|
||||||
free(info);
|
|
||||||
}
|
|
||||||
SHELL_CMD_EXPORT_ALIAS(ps_cmd, ps, shell ps);
|
|
||||||
@ -1 +1 @@
|
|||||||
set(CONFIG_TLSF 1)
|
set(CONFIG_SHELL 1)
|
||||||
|
|||||||
@ -57,6 +57,7 @@ cmake_definition+= -DEXAMPLE_BASE_DIR=$(EXAMPLE_BASE_DIR)
|
|||||||
|
|
||||||
cmake_definition+= -DCONFIG_FREERTOS=$(CONFIG_FREERTOS)
|
cmake_definition+= -DCONFIG_FREERTOS=$(CONFIG_FREERTOS)
|
||||||
cmake_definition+= -DCONFIG_TLSF=$(CONFIG_TLSF)
|
cmake_definition+= -DCONFIG_TLSF=$(CONFIG_TLSF)
|
||||||
|
cmake_definition+= -DCONFIG_SHELL=$(CONFIG_SHELL)
|
||||||
|
|
||||||
FINAL_NAME_PRE := $(EXAMPLE_BASE_DIR)/build/$(EXAMPLE_NAME)
|
FINAL_NAME_PRE := $(EXAMPLE_BASE_DIR)/build/$(EXAMPLE_NAME)
|
||||||
|
|
||||||
@ -85,7 +86,7 @@ build:Makefile
|
|||||||
$(CMAKE) -S . -B build -G "Unix Makefiles" $(cmake_definition)
|
$(CMAKE) -S . -B build -G "Unix Makefiles" $(cmake_definition)
|
||||||
$(MAKE) -C build -j
|
$(MAKE) -C build -j
|
||||||
|
|
||||||
clean::
|
clean:
|
||||||
$(RM) build
|
$(RM) build
|
||||||
|
|
||||||
.PHONY:post build clean
|
.PHONY:post build clean
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user