mirror of
https://github.com/Fishwaldo/bl_mcu_sdk.git
synced 2025-07-08 13:58:35 +00:00
[refactor] move utils into component
This commit is contained in:
parent
d4473020d6
commit
d9adf21997
25 changed files with 1835 additions and 1789 deletions
|
@ -2,6 +2,5 @@ cmake_minimum_required(VERSION 3.15)
|
|||
|
||||
add_subdirectory(bsp)
|
||||
add_subdirectory(components)
|
||||
add_subdirectory(drivers)
|
||||
add_subdirectory(utils)
|
||||
|
||||
add_subdirectory(drivers/lhal)
|
||||
add_subdirectory(drivers/soc/${CHIP})
|
||||
|
|
|
@ -10,3 +10,4 @@ sdk_add_subdirectory_ifdef(CONFIG_BLE ble)
|
|||
sdk_add_subdirectory_ifdef(CONFIG_XZ xz)
|
||||
sdk_add_subdirectory_ifdef(CONFIG_TINYMAIX TinyMaix)
|
||||
sdk_add_subdirectory_ifdef(CONFIG_TENSORFLOWLITE TensorFlowLite)
|
||||
add_subdirectory(utils)
|
||||
|
|
|
@ -42,7 +42,7 @@ endif()
|
|||
|
||||
# libc or vlibc select
|
||||
if(CONFIG_VLIBC)
|
||||
|
||||
sdk_add_compile_definitions(-DCONFIG_VLIBC)
|
||||
# vlibc debug enable
|
||||
if (CONFIG_VLIBC_DEBUG)
|
||||
sdk_add_compile_definitions(-DCONFIG_VLIBC_DEBUG)
|
||||
|
@ -70,7 +70,7 @@ else()
|
|||
endif()
|
||||
|
||||
# memheap
|
||||
sdk_library_add_sources(mmheap/mmheap.c)
|
||||
sdk_library_add_sources(mmheap/bflb_mmheap.c)
|
||||
sdk_add_include_directories(mmheap)
|
||||
|
||||
# memheap lock user config
|
|
@ -1,10 +1,14 @@
|
|||
#include <reent.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include "mmheap.h"
|
||||
#include "bflb_uart.h"
|
||||
#ifdef CONFIG_TLSF
|
||||
#include "bflb_tlsf.h"
|
||||
#else
|
||||
#include "bflb_mmheap.h"
|
||||
|
||||
extern struct heap_info mmheap_root;
|
||||
#endif
|
||||
|
||||
extern struct bflb_device_s *console;
|
||||
|
||||
|
@ -151,11 +155,15 @@ void *_malloc_r(struct _reent *ptr, size_t size)
|
|||
#ifdef CONFIG_MEM_USE_FREERTOS
|
||||
result = pvPortMalloc(size);
|
||||
#else
|
||||
result = (void *)mmheap_alloc(&mmheap_root, size);
|
||||
#ifdef CONFIG_TLSF
|
||||
result = (void *)bflb_malloc(size);
|
||||
#else
|
||||
result = (void *)bflb_mmheap_alloc(&mmheap_root, size);
|
||||
#endif
|
||||
#endif
|
||||
if (result == NULL) {
|
||||
ptr->_errno = -ENOMEM;
|
||||
}
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -164,7 +172,11 @@ void *_realloc_r(struct _reent *ptr, void *old, size_t newlen)
|
|||
void *result;
|
||||
#ifdef CONFIG_MEM_USE_FREERTOS
|
||||
#else
|
||||
result = (void *)mmheap_realloc(&mmheap_root, old, newlen);
|
||||
#ifdef CONFIG_TLSF
|
||||
result = (void *)bflb_realloc(old, newlen);
|
||||
#else
|
||||
result = (void *)bflb_mmheap_realloc(&mmheap_root, old, newlen);
|
||||
#endif
|
||||
#endif
|
||||
if (result == NULL) {
|
||||
ptr->_errno = -ENOMEM;
|
||||
|
@ -177,15 +189,19 @@ void *_calloc_r(struct _reent *ptr, size_t size, size_t len)
|
|||
void *result;
|
||||
#ifdef CONFIG_MEM_USE_FREERTOS
|
||||
result = pvPortMalloc(size * len);
|
||||
if (result) {
|
||||
memset(result, 0, size * len);
|
||||
}
|
||||
#else
|
||||
result = (void *)mmheap_calloc(&mmheap_root, size, len);
|
||||
#ifdef CONFIG_TLSF
|
||||
result = (void *)bflb_calloc(size, len);
|
||||
#else
|
||||
result = (void *)bflb_mmheap_calloc(&mmheap_root, size, len);
|
||||
#endif
|
||||
#endif
|
||||
if (result == NULL) {
|
||||
ptr->_errno = -ENOMEM;
|
||||
}
|
||||
#endif
|
||||
if (result) {
|
||||
memset(result, 0, size * len);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -194,7 +210,11 @@ void *_memalign_r(struct _reent *ptr, size_t align, size_t size)
|
|||
void *result;
|
||||
#ifdef CONFIG_MEM_USE_FREERTOS
|
||||
#else
|
||||
result = (void *)mmheap_align_alloc(&mmheap_root, align, size);
|
||||
#ifdef CONFIG_TLSF
|
||||
result = (void *)bflb_malloc_align(align, size);
|
||||
#else
|
||||
result = (void *)bflb_mmheap_align_alloc(&mmheap_root, align, size);
|
||||
#endif
|
||||
#endif
|
||||
if (result == NULL) {
|
||||
ptr->_errno = -ENOMEM;
|
||||
|
@ -208,7 +228,11 @@ void _free_r(struct _reent *ptr, void *addr)
|
|||
#ifdef CONFIG_MEM_USE_FREERTOS
|
||||
vPortFree(addr);
|
||||
#else
|
||||
mmheap_free(&mmheap_root, addr);
|
||||
#ifdef CONFIG_TLSF
|
||||
bflb_free(addr);
|
||||
#else
|
||||
bflb_mmheap_free(&mmheap_root, addr);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* @file mmheap.c
|
||||
* @file bflb_mmheap.c
|
||||
* @brief
|
||||
*
|
||||
* Copyright (c) 2021 Bouffalolab team
|
||||
|
@ -21,7 +21,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "mmheap.h"
|
||||
#include "bflb_mmheap.h"
|
||||
|
||||
#define MEM_MANAGE_ALIGNMENT_BYTE_DEFAULT 8
|
||||
#define MEM_MANAGE_BITS_PER_BYTE 8
|
||||
|
@ -117,14 +117,14 @@ void mmheap_get_state(struct heap_info *pRoot, struct heap_state *pState)
|
|||
MMHEAP_UNLOCK();
|
||||
}
|
||||
/**
|
||||
* @brief mmheap_align_alloc
|
||||
* @brief bflb_mmheap_align_alloc
|
||||
*
|
||||
* @param pRoot
|
||||
* @param align_size
|
||||
* @param want_size
|
||||
* @return void*
|
||||
*/
|
||||
void *mmheap_align_alloc(struct heap_info *pRoot, size_t align_size, size_t want_size)
|
||||
void *bflb_mmheap_align_alloc(struct heap_info *pRoot, size_t align_size, size_t want_size)
|
||||
{
|
||||
void *pReturn = NULL;
|
||||
struct heap_node *pPriv_Node, *pNow_Node;
|
||||
|
@ -208,25 +208,25 @@ void *mmheap_align_alloc(struct heap_info *pRoot, size_t align_size, size_t want
|
|||
return pReturn;
|
||||
}
|
||||
/**
|
||||
* @brief mmheap_alloc
|
||||
* @brief bflb_mmheap_alloc
|
||||
*
|
||||
* @param pRoot
|
||||
* @param want_size
|
||||
* @return void*
|
||||
*/
|
||||
void *mmheap_alloc(struct heap_info *pRoot, size_t want_size)
|
||||
void *bflb_mmheap_alloc(struct heap_info *pRoot, size_t want_size)
|
||||
{
|
||||
return mmheap_align_alloc(pRoot, MEM_MANAGE_ALIGNMENT_BYTE_DEFAULT, want_size);
|
||||
return bflb_mmheap_align_alloc(pRoot, MEM_MANAGE_ALIGNMENT_BYTE_DEFAULT, want_size);
|
||||
}
|
||||
/**
|
||||
* @brief mmheap_realloc
|
||||
* @brief bflb_mmheap_realloc
|
||||
*
|
||||
* @param pRoot
|
||||
* @param src_addr
|
||||
* @param want_size
|
||||
* @return void*
|
||||
*/
|
||||
void *mmheap_realloc(struct heap_info *pRoot, void *src_addr, size_t want_size)
|
||||
void *bflb_mmheap_realloc(struct heap_info *pRoot, void *src_addr, size_t want_size)
|
||||
{
|
||||
void *pReturn = NULL;
|
||||
struct heap_node *pNext_Node, *pPriv_Node;
|
||||
|
@ -234,10 +234,10 @@ void *mmheap_realloc(struct heap_info *pRoot, void *src_addr, size_t want_size)
|
|||
MMHEAP_ASSERT(pRoot->pStart != NULL);
|
||||
MMHEAP_ASSERT(pRoot->pEnd != NULL);
|
||||
if (src_addr == NULL) {
|
||||
return mmheap_align_alloc(pRoot, MEM_MANAGE_ALIGNMENT_BYTE_DEFAULT, want_size);
|
||||
return bflb_mmheap_align_alloc(pRoot, MEM_MANAGE_ALIGNMENT_BYTE_DEFAULT, want_size);
|
||||
}
|
||||
if (want_size == 0) {
|
||||
mmheap_free(pRoot, src_addr);
|
||||
bflb_mmheap_free(pRoot, src_addr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -288,7 +288,7 @@ void *mmheap_realloc(struct heap_info *pRoot, void *src_addr, size_t want_size)
|
|||
MMHEAP_UNLOCK();
|
||||
} else {
|
||||
MMHEAP_UNLOCK();
|
||||
pReturn = mmheap_align_alloc(pRoot, MEM_MANAGE_ALIGNMENT_BYTE_DEFAULT, want_size);
|
||||
pReturn = bflb_mmheap_align_alloc(pRoot, MEM_MANAGE_ALIGNMENT_BYTE_DEFAULT, want_size);
|
||||
if (pReturn == NULL) {
|
||||
pSrc_Node->mem_size |= MEM_MANAGE_ALLOCA_LABAL;
|
||||
MMHEAP_MALLOC_FAIL();
|
||||
|
@ -298,7 +298,7 @@ void *mmheap_realloc(struct heap_info *pRoot, void *src_addr, size_t want_size)
|
|||
memcpy(pReturn, src_addr, pSrc_Node->mem_size);
|
||||
pSrc_Node->mem_size |= MEM_MANAGE_ALLOCA_LABAL;
|
||||
MMHEAP_UNLOCK();
|
||||
mmheap_free(pRoot, src_addr);
|
||||
bflb_mmheap_free(pRoot, src_addr);
|
||||
}
|
||||
return pReturn;
|
||||
}
|
||||
|
@ -310,11 +310,11 @@ void *mmheap_realloc(struct heap_info *pRoot, void *src_addr, size_t want_size)
|
|||
* @param size
|
||||
* @return void*
|
||||
*/
|
||||
void *mmheap_calloc(struct heap_info *pRoot, size_t num, size_t size)
|
||||
void *bflb_mmheap_calloc(struct heap_info *pRoot, size_t num, size_t size)
|
||||
{
|
||||
void *pReturn = NULL;
|
||||
|
||||
pReturn = (void *)mmheap_alloc(pRoot, size * num);
|
||||
pReturn = (void *)bflb_mmheap_alloc(pRoot, size * num);
|
||||
|
||||
if (pReturn) {
|
||||
memset(pReturn, 0, num * size);
|
||||
|
@ -323,12 +323,12 @@ void *mmheap_calloc(struct heap_info *pRoot, size_t num, size_t size)
|
|||
return pReturn;
|
||||
}
|
||||
/**
|
||||
* @brief mmheap_free
|
||||
* @brief bflb_mmheap_free
|
||||
*
|
||||
* @param pRoot
|
||||
* @param addr
|
||||
*/
|
||||
void mmheap_free(struct heap_info *pRoot, void *addr)
|
||||
void bflb_mmheap_free(struct heap_info *pRoot, void *addr)
|
||||
{
|
||||
struct heap_node *pFree_Node;
|
||||
MMHEAP_ASSERT(pRoot->pStart != NULL);
|
||||
|
@ -356,12 +356,12 @@ void mmheap_free(struct heap_info *pRoot, void *addr)
|
|||
MMHEAP_UNLOCK();
|
||||
}
|
||||
/**
|
||||
* @brief mmheap_init
|
||||
* @brief bflb_mmheap_init
|
||||
*
|
||||
* @param pRoot
|
||||
* @param pRegion
|
||||
*/
|
||||
void mmheap_init(struct heap_info *pRoot, const struct heap_region *pRegion)
|
||||
void bflb_mmheap_init(struct heap_info *pRoot, const struct heap_region *pRegion)
|
||||
{
|
||||
struct heap_node *align_addr;
|
||||
size_t align_size;
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* @file mmheap.h
|
||||
* @file bflb_mmheap.h
|
||||
* @brief
|
||||
*
|
||||
* Copyright (c) 2021 Bouffalolab team
|
||||
|
@ -20,8 +20,8 @@
|
|||
* under the License.
|
||||
*
|
||||
*/
|
||||
#ifndef __DRV_MMHEAP_H
|
||||
#define __DRV_MMHEAP_H
|
||||
#ifndef __BFLB_MMHEAP_H
|
||||
#define __BFLB_MMHEAP_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
@ -77,7 +77,7 @@ struct heap_state {
|
|||
size_t min_node_size;
|
||||
};
|
||||
|
||||
void mmheap_init(struct heap_info *pRoot, const struct heap_region *pRigon);
|
||||
void bflb_mmheap_init(struct heap_info *pRoot, const struct heap_region *pRigon);
|
||||
/**
|
||||
* @brief Alloc start address aligned memory from the heap.
|
||||
* Alloc aligned address and specified size memory from the heap.
|
||||
|
@ -90,7 +90,7 @@ void mmheap_init(struct heap_info *pRoot, const struct heap_region *pRigon);
|
|||
*
|
||||
* @return the pointer to the allocated memory.
|
||||
*/
|
||||
void *mmheap_align_alloc(struct heap_info *pRoot, size_t align_size, size_t want_size);
|
||||
void *bflb_mmheap_align_alloc(struct heap_info *pRoot, size_t align_size, size_t want_size);
|
||||
/**
|
||||
* @brief Alloc memory.
|
||||
* Allocate size bytes and returns a pointer to the allocated memory.
|
||||
|
@ -102,7 +102,7 @@ void *mmheap_align_alloc(struct heap_info *pRoot, size_t align_size, size_t want
|
|||
*
|
||||
* @return the pointer to the allocated memory.
|
||||
*/
|
||||
void *mmheap_alloc(struct heap_info *pRoot, size_t want_size);
|
||||
void *bflb_mmheap_alloc(struct heap_info *pRoot, size_t want_size);
|
||||
/**
|
||||
* @brief Realloc memory from the heap.
|
||||
* Change the size of the memory block pointed to by ptr to size bytes.
|
||||
|
@ -119,7 +119,7 @@ void *mmheap_alloc(struct heap_info *pRoot, size_t want_size);
|
|||
*
|
||||
* @return the new pointer to the allocated memory.
|
||||
*/
|
||||
void *mmheap_realloc(struct heap_info *pRoot, void *src_addr, size_t want_size);
|
||||
void *bflb_mmheap_realloc(struct heap_info *pRoot, void *src_addr, size_t want_size);
|
||||
/**
|
||||
* @brief Cealloc memory from the heap.
|
||||
* Change the size of the memory block pointed to by ptr to size bytes.
|
||||
|
@ -136,7 +136,7 @@ void *mmheap_realloc(struct heap_info *pRoot, void *src_addr, size_t want_size);
|
|||
*
|
||||
* @return the new pointer to the allocated memory.
|
||||
*/
|
||||
void *mmheap_calloc(struct heap_info *pRoot, size_t num, size_t size);
|
||||
void *bflb_mmheap_calloc(struct heap_info *pRoot, size_t num, size_t size);
|
||||
/**
|
||||
* @brief Free the memory.
|
||||
* Free the memory space pointed to by ptr, which must have been returned by a previous call to mmheap_alloc(), mmheap_aligned_alloc(), or mmheap_realloc().
|
||||
|
@ -148,14 +148,14 @@ void *mmheap_calloc(struct heap_info *pRoot, size_t num, size_t size);
|
|||
*
|
||||
* @return None.
|
||||
*/
|
||||
void mmheap_free(struct heap_info *pRoot, void *addr);
|
||||
void bflb_mmheap_free(struct heap_info *pRoot, void *addr);
|
||||
/**
|
||||
* @brief get mmheap state
|
||||
*
|
||||
* @param pRoot heap info.
|
||||
* @param pState heap state
|
||||
*/
|
||||
void mmheap_get_state(struct heap_info *pRoot, struct heap_state *pState);
|
||||
void bflb_mmheap_get_state(struct heap_info *pRoot, struct heap_state *pState);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -1,10 +1,14 @@
|
|||
#include <reent.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include "mmheap.h"
|
||||
#include "bflb_uart.h"
|
||||
#ifdef CONFIG_TLSF
|
||||
#include "bflb_tlsf.h"
|
||||
#else
|
||||
#include "bflb_mmheap.h"
|
||||
|
||||
extern struct heap_info mmheap_root;
|
||||
#endif
|
||||
|
||||
extern struct bflb_device_s *console;
|
||||
|
||||
|
@ -151,11 +155,15 @@ void *_malloc_r(struct _reent *ptr, size_t size)
|
|||
#ifdef CONFIG_MEM_USE_FREERTOS
|
||||
result = pvPortMalloc(size);
|
||||
#else
|
||||
result = (void *)mmheap_alloc(&mmheap_root, size);
|
||||
#ifdef CONFIG_TLSF
|
||||
result = (void *)bflb_malloc(size);
|
||||
#else
|
||||
result = (void *)bflb_mmheap_alloc(&mmheap_root, size);
|
||||
#endif
|
||||
#endif
|
||||
if (result == NULL) {
|
||||
ptr->_errno = -ENOMEM;
|
||||
}
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -164,7 +172,11 @@ void *_realloc_r(struct _reent *ptr, void *old, size_t newlen)
|
|||
void *result;
|
||||
#ifdef CONFIG_MEM_USE_FREERTOS
|
||||
#else
|
||||
result = (void *)mmheap_realloc(&mmheap_root, old, newlen);
|
||||
#ifdef CONFIG_TLSF
|
||||
result = (void *)bflb_realloc(old, newlen);
|
||||
#else
|
||||
result = (void *)bflb_mmheap_realloc(&mmheap_root, old, newlen);
|
||||
#endif
|
||||
#endif
|
||||
if (result == NULL) {
|
||||
ptr->_errno = -ENOMEM;
|
||||
|
@ -177,15 +189,19 @@ void *_calloc_r(struct _reent *ptr, size_t size, size_t len)
|
|||
void *result;
|
||||
#ifdef CONFIG_MEM_USE_FREERTOS
|
||||
result = pvPortMalloc(size * len);
|
||||
if (result) {
|
||||
memset(result, 0, size * len);
|
||||
}
|
||||
#else
|
||||
result = (void *)mmheap_calloc(&mmheap_root, size, len);
|
||||
#ifdef CONFIG_TLSF
|
||||
result = (void *)bflb_calloc(size, len);
|
||||
#else
|
||||
result = (void *)bflb_mmheap_calloc(&mmheap_root, size, len);
|
||||
#endif
|
||||
#endif
|
||||
if (result == NULL) {
|
||||
ptr->_errno = -ENOMEM;
|
||||
}
|
||||
#endif
|
||||
if (result) {
|
||||
memset(result, 0, size * len);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -194,7 +210,11 @@ void *_memalign_r(struct _reent *ptr, size_t align, size_t size)
|
|||
void *result;
|
||||
#ifdef CONFIG_MEM_USE_FREERTOS
|
||||
#else
|
||||
result = (void *)mmheap_align_alloc(&mmheap_root, align, size);
|
||||
#ifdef CONFIG_TLSF
|
||||
result = (void *)bflb_malloc_align(align, size);
|
||||
#else
|
||||
result = (void *)bflb_mmheap_align_alloc(&mmheap_root, align, size);
|
||||
#endif
|
||||
#endif
|
||||
if (result == NULL) {
|
||||
ptr->_errno = -ENOMEM;
|
||||
|
@ -208,7 +228,11 @@ void _free_r(struct _reent *ptr, void *addr)
|
|||
#ifdef CONFIG_MEM_USE_FREERTOS
|
||||
vPortFree(addr);
|
||||
#else
|
||||
mmheap_free(&mmheap_root, addr);
|
||||
#ifdef CONFIG_TLSF
|
||||
bflb_free(addr);
|
||||
#else
|
||||
bflb_mmheap_free(&mmheap_root, addr);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
add_subdirectory(lhal)
|
||||
add_subdirectory(soc/${CHIP})
|
Loading…
Add table
Add a link
Reference in a new issue