mirror of
https://github.com/Fishwaldo/bl_mcu_sdk.git
synced 2025-07-08 22:08:40 +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(bsp)
|
||||||
add_subdirectory(components)
|
add_subdirectory(components)
|
||||||
add_subdirectory(drivers)
|
add_subdirectory(drivers/lhal)
|
||||||
add_subdirectory(utils)
|
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_XZ xz)
|
||||||
sdk_add_subdirectory_ifdef(CONFIG_TINYMAIX TinyMaix)
|
sdk_add_subdirectory_ifdef(CONFIG_TINYMAIX TinyMaix)
|
||||||
sdk_add_subdirectory_ifdef(CONFIG_TENSORFLOWLITE TensorFlowLite)
|
sdk_add_subdirectory_ifdef(CONFIG_TENSORFLOWLITE TensorFlowLite)
|
||||||
|
add_subdirectory(utils)
|
||||||
|
|
|
@ -42,7 +42,7 @@ endif()
|
||||||
|
|
||||||
# libc or vlibc select
|
# libc or vlibc select
|
||||||
if(CONFIG_VLIBC)
|
if(CONFIG_VLIBC)
|
||||||
|
sdk_add_compile_definitions(-DCONFIG_VLIBC)
|
||||||
# vlibc debug enable
|
# vlibc debug enable
|
||||||
if (CONFIG_VLIBC_DEBUG)
|
if (CONFIG_VLIBC_DEBUG)
|
||||||
sdk_add_compile_definitions(-DCONFIG_VLIBC_DEBUG)
|
sdk_add_compile_definitions(-DCONFIG_VLIBC_DEBUG)
|
||||||
|
@ -70,7 +70,7 @@ else()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# memheap
|
# memheap
|
||||||
sdk_library_add_sources(mmheap/mmheap.c)
|
sdk_library_add_sources(mmheap/bflb_mmheap.c)
|
||||||
sdk_add_include_directories(mmheap)
|
sdk_add_include_directories(mmheap)
|
||||||
|
|
||||||
# memheap lock user config
|
# memheap lock user config
|
|
@ -1,10 +1,14 @@
|
||||||
#include <reent.h>
|
#include <reent.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "mmheap.h"
|
|
||||||
#include "bflb_uart.h"
|
#include "bflb_uart.h"
|
||||||
|
#ifdef CONFIG_TLSF
|
||||||
|
#include "bflb_tlsf.h"
|
||||||
|
#else
|
||||||
|
#include "bflb_mmheap.h"
|
||||||
|
|
||||||
extern struct heap_info mmheap_root;
|
extern struct heap_info mmheap_root;
|
||||||
|
#endif
|
||||||
|
|
||||||
extern struct bflb_device_s *console;
|
extern struct bflb_device_s *console;
|
||||||
|
|
||||||
|
@ -151,11 +155,15 @@ void *_malloc_r(struct _reent *ptr, size_t size)
|
||||||
#ifdef CONFIG_MEM_USE_FREERTOS
|
#ifdef CONFIG_MEM_USE_FREERTOS
|
||||||
result = pvPortMalloc(size);
|
result = pvPortMalloc(size);
|
||||||
#else
|
#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) {
|
if (result == NULL) {
|
||||||
ptr->_errno = -ENOMEM;
|
ptr->_errno = -ENOMEM;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,7 +172,11 @@ void *_realloc_r(struct _reent *ptr, void *old, size_t newlen)
|
||||||
void *result;
|
void *result;
|
||||||
#ifdef CONFIG_MEM_USE_FREERTOS
|
#ifdef CONFIG_MEM_USE_FREERTOS
|
||||||
#else
|
#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
|
#endif
|
||||||
if (result == NULL) {
|
if (result == NULL) {
|
||||||
ptr->_errno = -ENOMEM;
|
ptr->_errno = -ENOMEM;
|
||||||
|
@ -177,15 +189,19 @@ void *_calloc_r(struct _reent *ptr, size_t size, size_t len)
|
||||||
void *result;
|
void *result;
|
||||||
#ifdef CONFIG_MEM_USE_FREERTOS
|
#ifdef CONFIG_MEM_USE_FREERTOS
|
||||||
result = pvPortMalloc(size * len);
|
result = pvPortMalloc(size * len);
|
||||||
if (result) {
|
|
||||||
memset(result, 0, size * len);
|
|
||||||
}
|
|
||||||
#else
|
#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) {
|
if (result == NULL) {
|
||||||
ptr->_errno = -ENOMEM;
|
ptr->_errno = -ENOMEM;
|
||||||
}
|
}
|
||||||
#endif
|
if (result) {
|
||||||
|
memset(result, 0, size * len);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,7 +210,11 @@ void *_memalign_r(struct _reent *ptr, size_t align, size_t size)
|
||||||
void *result;
|
void *result;
|
||||||
#ifdef CONFIG_MEM_USE_FREERTOS
|
#ifdef CONFIG_MEM_USE_FREERTOS
|
||||||
#else
|
#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
|
#endif
|
||||||
if (result == NULL) {
|
if (result == NULL) {
|
||||||
ptr->_errno = -ENOMEM;
|
ptr->_errno = -ENOMEM;
|
||||||
|
@ -208,7 +228,11 @@ void _free_r(struct _reent *ptr, void *addr)
|
||||||
#ifdef CONFIG_MEM_USE_FREERTOS
|
#ifdef CONFIG_MEM_USE_FREERTOS
|
||||||
vPortFree(addr);
|
vPortFree(addr);
|
||||||
#else
|
#else
|
||||||
mmheap_free(&mmheap_root, addr);
|
#ifdef CONFIG_TLSF
|
||||||
|
bflb_free(addr);
|
||||||
|
#else
|
||||||
|
bflb_mmheap_free(&mmheap_root, addr);
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/**
|
/**
|
||||||
* @file mmheap.c
|
* @file bflb_mmheap.c
|
||||||
* @brief
|
* @brief
|
||||||
*
|
*
|
||||||
* Copyright (c) 2021 Bouffalolab team
|
* 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_ALIGNMENT_BYTE_DEFAULT 8
|
||||||
#define MEM_MANAGE_BITS_PER_BYTE 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();
|
MMHEAP_UNLOCK();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief mmheap_align_alloc
|
* @brief bflb_mmheap_align_alloc
|
||||||
*
|
*
|
||||||
* @param pRoot
|
* @param pRoot
|
||||||
* @param align_size
|
* @param align_size
|
||||||
* @param want_size
|
* @param want_size
|
||||||
* @return void*
|
* @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;
|
void *pReturn = NULL;
|
||||||
struct heap_node *pPriv_Node, *pNow_Node;
|
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;
|
return pReturn;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief mmheap_alloc
|
* @brief bflb_mmheap_alloc
|
||||||
*
|
*
|
||||||
* @param pRoot
|
* @param pRoot
|
||||||
* @param want_size
|
* @param want_size
|
||||||
* @return void*
|
* @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 pRoot
|
||||||
* @param src_addr
|
* @param src_addr
|
||||||
* @param want_size
|
* @param want_size
|
||||||
* @return void*
|
* @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;
|
void *pReturn = NULL;
|
||||||
struct heap_node *pNext_Node, *pPriv_Node;
|
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->pStart != NULL);
|
||||||
MMHEAP_ASSERT(pRoot->pEnd != NULL);
|
MMHEAP_ASSERT(pRoot->pEnd != NULL);
|
||||||
if (src_addr == 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) {
|
if (want_size == 0) {
|
||||||
mmheap_free(pRoot, src_addr);
|
bflb_mmheap_free(pRoot, src_addr);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,7 +288,7 @@ void *mmheap_realloc(struct heap_info *pRoot, void *src_addr, size_t want_size)
|
||||||
MMHEAP_UNLOCK();
|
MMHEAP_UNLOCK();
|
||||||
} else {
|
} else {
|
||||||
MMHEAP_UNLOCK();
|
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) {
|
if (pReturn == NULL) {
|
||||||
pSrc_Node->mem_size |= MEM_MANAGE_ALLOCA_LABAL;
|
pSrc_Node->mem_size |= MEM_MANAGE_ALLOCA_LABAL;
|
||||||
MMHEAP_MALLOC_FAIL();
|
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);
|
memcpy(pReturn, src_addr, pSrc_Node->mem_size);
|
||||||
pSrc_Node->mem_size |= MEM_MANAGE_ALLOCA_LABAL;
|
pSrc_Node->mem_size |= MEM_MANAGE_ALLOCA_LABAL;
|
||||||
MMHEAP_UNLOCK();
|
MMHEAP_UNLOCK();
|
||||||
mmheap_free(pRoot, src_addr);
|
bflb_mmheap_free(pRoot, src_addr);
|
||||||
}
|
}
|
||||||
return pReturn;
|
return pReturn;
|
||||||
}
|
}
|
||||||
|
@ -310,11 +310,11 @@ void *mmheap_realloc(struct heap_info *pRoot, void *src_addr, size_t want_size)
|
||||||
* @param size
|
* @param size
|
||||||
* @return void*
|
* @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;
|
void *pReturn = NULL;
|
||||||
|
|
||||||
pReturn = (void *)mmheap_alloc(pRoot, size * num);
|
pReturn = (void *)bflb_mmheap_alloc(pRoot, size * num);
|
||||||
|
|
||||||
if (pReturn) {
|
if (pReturn) {
|
||||||
memset(pReturn, 0, num * size);
|
memset(pReturn, 0, num * size);
|
||||||
|
@ -323,12 +323,12 @@ void *mmheap_calloc(struct heap_info *pRoot, size_t num, size_t size)
|
||||||
return pReturn;
|
return pReturn;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief mmheap_free
|
* @brief bflb_mmheap_free
|
||||||
*
|
*
|
||||||
* @param pRoot
|
* @param pRoot
|
||||||
* @param addr
|
* @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;
|
struct heap_node *pFree_Node;
|
||||||
MMHEAP_ASSERT(pRoot->pStart != NULL);
|
MMHEAP_ASSERT(pRoot->pStart != NULL);
|
||||||
|
@ -356,12 +356,12 @@ void mmheap_free(struct heap_info *pRoot, void *addr)
|
||||||
MMHEAP_UNLOCK();
|
MMHEAP_UNLOCK();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief mmheap_init
|
* @brief bflb_mmheap_init
|
||||||
*
|
*
|
||||||
* @param pRoot
|
* @param pRoot
|
||||||
* @param pRegion
|
* @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;
|
struct heap_node *align_addr;
|
||||||
size_t align_size;
|
size_t align_size;
|
|
@ -1,5 +1,5 @@
|
||||||
/**
|
/**
|
||||||
* @file mmheap.h
|
* @file bflb_mmheap.h
|
||||||
* @brief
|
* @brief
|
||||||
*
|
*
|
||||||
* Copyright (c) 2021 Bouffalolab team
|
* Copyright (c) 2021 Bouffalolab team
|
||||||
|
@ -20,8 +20,8 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#ifndef __DRV_MMHEAP_H
|
#ifndef __BFLB_MMHEAP_H
|
||||||
#define __DRV_MMHEAP_H
|
#define __BFLB_MMHEAP_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -77,7 +77,7 @@ struct heap_state {
|
||||||
size_t min_node_size;
|
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.
|
* @brief Alloc start address aligned memory from the heap.
|
||||||
* Alloc aligned address and specified size 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.
|
* @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.
|
* @brief Alloc memory.
|
||||||
* Allocate size bytes and returns a pointer to the allocated 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.
|
* @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.
|
* @brief Realloc memory from the heap.
|
||||||
* Change the size of the memory block pointed to by ptr to size bytes.
|
* 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.
|
* @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.
|
* @brief Cealloc memory from the heap.
|
||||||
* Change the size of the memory block pointed to by ptr to size bytes.
|
* 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.
|
* @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.
|
* @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().
|
* 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.
|
* @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
|
* @brief get mmheap state
|
||||||
*
|
*
|
||||||
* @param pRoot heap info.
|
* @param pRoot heap info.
|
||||||
* @param pState heap state
|
* @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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
|
@ -1,10 +1,14 @@
|
||||||
#include <reent.h>
|
#include <reent.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "mmheap.h"
|
|
||||||
#include "bflb_uart.h"
|
#include "bflb_uart.h"
|
||||||
|
#ifdef CONFIG_TLSF
|
||||||
|
#include "bflb_tlsf.h"
|
||||||
|
#else
|
||||||
|
#include "bflb_mmheap.h"
|
||||||
|
|
||||||
extern struct heap_info mmheap_root;
|
extern struct heap_info mmheap_root;
|
||||||
|
#endif
|
||||||
|
|
||||||
extern struct bflb_device_s *console;
|
extern struct bflb_device_s *console;
|
||||||
|
|
||||||
|
@ -151,11 +155,15 @@ void *_malloc_r(struct _reent *ptr, size_t size)
|
||||||
#ifdef CONFIG_MEM_USE_FREERTOS
|
#ifdef CONFIG_MEM_USE_FREERTOS
|
||||||
result = pvPortMalloc(size);
|
result = pvPortMalloc(size);
|
||||||
#else
|
#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) {
|
if (result == NULL) {
|
||||||
ptr->_errno = -ENOMEM;
|
ptr->_errno = -ENOMEM;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,7 +172,11 @@ void *_realloc_r(struct _reent *ptr, void *old, size_t newlen)
|
||||||
void *result;
|
void *result;
|
||||||
#ifdef CONFIG_MEM_USE_FREERTOS
|
#ifdef CONFIG_MEM_USE_FREERTOS
|
||||||
#else
|
#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
|
#endif
|
||||||
if (result == NULL) {
|
if (result == NULL) {
|
||||||
ptr->_errno = -ENOMEM;
|
ptr->_errno = -ENOMEM;
|
||||||
|
@ -177,15 +189,19 @@ void *_calloc_r(struct _reent *ptr, size_t size, size_t len)
|
||||||
void *result;
|
void *result;
|
||||||
#ifdef CONFIG_MEM_USE_FREERTOS
|
#ifdef CONFIG_MEM_USE_FREERTOS
|
||||||
result = pvPortMalloc(size * len);
|
result = pvPortMalloc(size * len);
|
||||||
if (result) {
|
|
||||||
memset(result, 0, size * len);
|
|
||||||
}
|
|
||||||
#else
|
#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) {
|
if (result == NULL) {
|
||||||
ptr->_errno = -ENOMEM;
|
ptr->_errno = -ENOMEM;
|
||||||
}
|
}
|
||||||
#endif
|
if (result) {
|
||||||
|
memset(result, 0, size * len);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,7 +210,11 @@ void *_memalign_r(struct _reent *ptr, size_t align, size_t size)
|
||||||
void *result;
|
void *result;
|
||||||
#ifdef CONFIG_MEM_USE_FREERTOS
|
#ifdef CONFIG_MEM_USE_FREERTOS
|
||||||
#else
|
#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
|
#endif
|
||||||
if (result == NULL) {
|
if (result == NULL) {
|
||||||
ptr->_errno = -ENOMEM;
|
ptr->_errno = -ENOMEM;
|
||||||
|
@ -208,7 +228,11 @@ void _free_r(struct _reent *ptr, void *addr)
|
||||||
#ifdef CONFIG_MEM_USE_FREERTOS
|
#ifdef CONFIG_MEM_USE_FREERTOS
|
||||||
vPortFree(addr);
|
vPortFree(addr);
|
||||||
#else
|
#else
|
||||||
mmheap_free(&mmheap_root, addr);
|
#ifdef CONFIG_TLSF
|
||||||
|
bflb_free(addr);
|
||||||
|
#else
|
||||||
|
bflb_mmheap_free(&mmheap_root, addr);
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,170 +1,170 @@
|
||||||
#ifndef _VLIBC_STDIO_H
|
#ifndef _VLIBC_STDIO_H
|
||||||
#define _VLIBC_STDIO_H
|
#define _VLIBC_STDIO_H
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifdef CONFIG_VLIBC_FATFS
|
#ifdef CONFIG_VLIBC_FATFS
|
||||||
#include "ff.h"
|
#include "ff.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** @addtogroup Types
|
/** @addtogroup Types
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct __vlibc_io {
|
struct __vlibc_io {
|
||||||
char *bg; /*!< buffer begin pointer */
|
char *bg; /*!< buffer begin pointer */
|
||||||
char *wp; /*!< buffer write pointer */
|
char *wp; /*!< buffer write pointer */
|
||||||
char *rp; /*!< buffer read pointer */
|
char *rp; /*!< buffer read pointer */
|
||||||
char *ed; /*!< buffer end pointer */
|
char *ed; /*!< buffer end pointer */
|
||||||
|
|
||||||
uint32_t dev; /*!< io device */
|
uint32_t dev; /*!< io device */
|
||||||
uint8_t flag; /*!< io flag */
|
uint8_t flag; /*!< io flag */
|
||||||
uint8_t vbuf; /*!< buffer mode */
|
uint8_t vbuf; /*!< buffer mode */
|
||||||
uint8_t abuf; /*!< buffer auto */
|
uint8_t abuf; /*!< buffer auto */
|
||||||
uint8_t err; /*!< error */
|
uint8_t err; /*!< error */
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t magic;
|
uint32_t magic;
|
||||||
|
|
||||||
union {
|
union {
|
||||||
struct __vlibc_io *io;
|
struct __vlibc_io *io;
|
||||||
#ifdef CONFIG_VLIBC_FATFS
|
#ifdef CONFIG_VLIBC_FATFS
|
||||||
FIL *file;
|
FIL *file;
|
||||||
#else
|
#else
|
||||||
int *file;
|
int *file;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
} vlibc_file_t;
|
} vlibc_file_t;
|
||||||
|
|
||||||
/*!< file type */
|
/*!< file type */
|
||||||
#define VLIBC_FILE vlibc_file_t
|
#define VLIBC_FILE vlibc_file_t
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** @addtogroup stdio extra
|
/** @addtogroup stdio extra
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
extern uint32_t __vlibc_io_init(const char *name, uint8_t mode);
|
extern uint32_t __vlibc_io_init(const char *name, uint8_t mode);
|
||||||
extern uint32_t __vlibc_io_deinit(struct __vlibc_io *io);
|
extern uint32_t __vlibc_io_deinit(struct __vlibc_io *io);
|
||||||
extern size_t __vlibc_io_mem2dev(struct __vlibc_io *io, const void *ptr, size_t size);
|
extern size_t __vlibc_io_mem2dev(struct __vlibc_io *io, const void *ptr, size_t size);
|
||||||
extern size_t __vlibc_io_dev2mem(struct __vlibc_io *io, void *ptr, size_t size);
|
extern size_t __vlibc_io_dev2mem(struct __vlibc_io *io, void *ptr, size_t size);
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** @addtogroup Marcos
|
/** @addtogroup Marcos
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _VLIBC_MAGIC_MASK ((unsigned int)(0xffff0000))
|
#define _VLIBC_MAGIC_MASK ((unsigned int)(0xffff0000))
|
||||||
#define _VLIBC_IO_MAGIC_CODE ((unsigned int)(0x10de0000))
|
#define _VLIBC_IO_MAGIC_CODE ((unsigned int)(0x10de0000))
|
||||||
#define _VLIBC_FILE_MAGIC_CODE ((unsigned int)(0xf11e0000))
|
#define _VLIBC_FILE_MAGIC_CODE ((unsigned int)(0xf11e0000))
|
||||||
|
|
||||||
#define _VLIBC_IO_WRITE ((unsigned char)(0x01))
|
#define _VLIBC_IO_WRITE ((unsigned char)(0x01))
|
||||||
#define _VLIBC_IO_READ ((unsigned char)(0x02))
|
#define _VLIBC_IO_READ ((unsigned char)(0x02))
|
||||||
|
|
||||||
/*!< io buffer size */
|
/*!< io buffer size */
|
||||||
#define VLIBC_BUFSIZ 256
|
#define VLIBC_BUFSIZ 256
|
||||||
|
|
||||||
/*!< file stack buffer size */
|
/*!< file stack buffer size */
|
||||||
#define VLIBC_FBUFSIZ 256
|
#define VLIBC_FBUFSIZ 256
|
||||||
|
|
||||||
/*!< max open file count at the same time */
|
/*!< max open file count at the same time */
|
||||||
#define VLIBC_FOPEN_MAX 20
|
#define VLIBC_FOPEN_MAX 20
|
||||||
|
|
||||||
/*!< max file name length */
|
/*!< max file name length */
|
||||||
#define VLIBC_FILENAME_MAX 256
|
#define VLIBC_FILENAME_MAX 256
|
||||||
|
|
||||||
/*!< max io name length */
|
/*!< max io name length */
|
||||||
#define _VLIBC_IONAME_MAX 32
|
#define _VLIBC_IONAME_MAX 32
|
||||||
|
|
||||||
/*!< max tmpnam file name length */
|
/*!< max tmpnam file name length */
|
||||||
#define VLIBC_L_tmpnam VLIBC_FILENAME_MAX
|
#define VLIBC_L_tmpnam VLIBC_FILENAME_MAX
|
||||||
|
|
||||||
/*!< max tmpnam rand name */
|
/*!< max tmpnam rand name */
|
||||||
#define VLIBC_TMP_MAX 0
|
#define VLIBC_TMP_MAX 0
|
||||||
|
|
||||||
/*!< stand io */
|
/*!< stand io */
|
||||||
extern vlibc_file_t *__vlibc_stdio_fileptrs[3];
|
extern vlibc_file_t *__vlibc_stdio_fileptrs[3];
|
||||||
#define vlibc_stdin (__vlibc_stdio_fileptrs[0])
|
#define vlibc_stdin (__vlibc_stdio_fileptrs[0])
|
||||||
#define vlibc_stdout (__vlibc_stdio_fileptrs[1])
|
#define vlibc_stdout (__vlibc_stdio_fileptrs[1])
|
||||||
#define vlibc_stderr (__vlibc_stdio_fileptrs[2])
|
#define vlibc_stderr (__vlibc_stdio_fileptrs[2])
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** @addtogroup stdio functions
|
/** @addtogroup stdio functions
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern void vlibc_clearerr(VLIBC_FILE *);
|
extern void vlibc_clearerr(VLIBC_FILE *);
|
||||||
extern int vlibc_feof(VLIBC_FILE *);
|
extern int vlibc_feof(VLIBC_FILE *);
|
||||||
extern int vlibc_ferror(VLIBC_FILE *);
|
extern int vlibc_ferror(VLIBC_FILE *);
|
||||||
|
|
||||||
extern VLIBC_FILE *vlibc_fopen(const char *, const char *);
|
extern VLIBC_FILE *vlibc_fopen(const char *, const char *);
|
||||||
extern VLIBC_FILE *vlibc_freopen(const char *, const char *, VLIBC_FILE *);
|
extern VLIBC_FILE *vlibc_freopen(const char *, const char *, VLIBC_FILE *);
|
||||||
extern int vlibc_fclose(VLIBC_FILE *);
|
extern int vlibc_fclose(VLIBC_FILE *);
|
||||||
|
|
||||||
extern size_t vlibc_fread(void *, size_t, size_t, VLIBC_FILE *);
|
extern size_t vlibc_fread(void *, size_t, size_t, VLIBC_FILE *);
|
||||||
extern size_t vlibc_fwrite(const void *, size_t, size_t, VLIBC_FILE *);
|
extern size_t vlibc_fwrite(const void *, size_t, size_t, VLIBC_FILE *);
|
||||||
|
|
||||||
extern int vlibc_fflush(VLIBC_FILE *);
|
extern int vlibc_fflush(VLIBC_FILE *);
|
||||||
extern int vlibc_fseek(VLIBC_FILE *, long, int);
|
extern int vlibc_fseek(VLIBC_FILE *, long, int);
|
||||||
extern long vlibc_ftell(VLIBC_FILE *);
|
extern long vlibc_ftell(VLIBC_FILE *);
|
||||||
|
|
||||||
extern int vlibc_remove(const char *);
|
extern int vlibc_remove(const char *);
|
||||||
extern int vlibc_rename(const char *, const char *);
|
extern int vlibc_rename(const char *, const char *);
|
||||||
extern void vlibc_rewind(VLIBC_FILE *);
|
extern void vlibc_rewind(VLIBC_FILE *);
|
||||||
|
|
||||||
extern void vlibc_setbuf(VLIBC_FILE *, char *);
|
extern void vlibc_setbuf(VLIBC_FILE *, char *);
|
||||||
extern int vlibc_setvbuf(VLIBC_FILE *, char *, int, size_t);
|
extern int vlibc_setvbuf(VLIBC_FILE *, char *, int, size_t);
|
||||||
|
|
||||||
extern VLIBC_FILE *vlibc_tmpfile(void);
|
extern VLIBC_FILE *vlibc_tmpfile(void);
|
||||||
extern char *vlibc_tmpnam(char *);
|
extern char *vlibc_tmpnam(char *);
|
||||||
|
|
||||||
extern int vlibc_fprintf(VLIBC_FILE *, const char *, ...);
|
extern int vlibc_fprintf(VLIBC_FILE *, const char *, ...);
|
||||||
extern int vlibc_printf(const char *, ...);
|
extern int vlibc_printf(const char *, ...);
|
||||||
extern int vlibc_sprintf(char *, const char *, ...);
|
extern int vlibc_sprintf(char *, const char *, ...);
|
||||||
extern int vlibc_snprintf(char *, size_t, const char *, ...);
|
extern int vlibc_snprintf(char *, size_t, const char *, ...);
|
||||||
|
|
||||||
extern int vlibc_vfprintf(VLIBC_FILE *, const char *, va_list);
|
extern int vlibc_vfprintf(VLIBC_FILE *, const char *, va_list);
|
||||||
extern int vlibc_vprintf(const char *, va_list);
|
extern int vlibc_vprintf(const char *, va_list);
|
||||||
extern int vlibc_vsprintf(char *, const char *, va_list);
|
extern int vlibc_vsprintf(char *, const char *, va_list);
|
||||||
extern int vlibc_vsnprintf(char *, size_t, const char *, va_list);
|
extern int vlibc_vsnprintf(char *, size_t, const char *, va_list);
|
||||||
|
|
||||||
extern int vlibc_fscanf(VLIBC_FILE *, const char *, ...);
|
extern int vlibc_fscanf(VLIBC_FILE *, const char *, ...);
|
||||||
extern int vlibc_scanf(const char *, ...);
|
extern int vlibc_scanf(const char *, ...);
|
||||||
extern int vlibc_sscanf(const char *, const char *, ...);
|
extern int vlibc_sscanf(const char *, const char *, ...);
|
||||||
|
|
||||||
extern int vlibc_vfscanf(VLIBC_FILE *, const char *, va_list);
|
extern int vlibc_vfscanf(VLIBC_FILE *, const char *, va_list);
|
||||||
extern int vlibc_vscanf(const char *, va_list);
|
extern int vlibc_vscanf(const char *, va_list);
|
||||||
extern int vlibc_vsscanf(const char *, const char *, va_list);
|
extern int vlibc_vsscanf(const char *, const char *, va_list);
|
||||||
|
|
||||||
extern int vlibc_fgetc(VLIBC_FILE *);
|
extern int vlibc_fgetc(VLIBC_FILE *);
|
||||||
extern char *vlibc_fgets(char *, int, VLIBC_FILE *);
|
extern char *vlibc_fgets(char *, int, VLIBC_FILE *);
|
||||||
|
|
||||||
extern int vlibc_fputc(int, VLIBC_FILE *);
|
extern int vlibc_fputc(int, VLIBC_FILE *);
|
||||||
extern int vlibc_fputs(const char *, VLIBC_FILE *);
|
extern int vlibc_fputs(const char *, VLIBC_FILE *);
|
||||||
|
|
||||||
extern int vlibc_getc(VLIBC_FILE *);
|
extern int vlibc_getc(VLIBC_FILE *);
|
||||||
extern int vlibc_getchar(void);
|
extern int vlibc_getchar(void);
|
||||||
extern char *vlibc_gets(char *);
|
extern char *vlibc_gets(char *);
|
||||||
|
|
||||||
extern int vlibc_putc(int, VLIBC_FILE *);
|
extern int vlibc_putc(int, VLIBC_FILE *);
|
||||||
extern int vlibc_putchar(int);
|
extern int vlibc_putchar(int);
|
||||||
extern int vlibc_puts(const char *);
|
extern int vlibc_puts(const char *);
|
||||||
|
|
||||||
extern void vlibc_perror(const char *);
|
extern void vlibc_perror(const char *);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -1,2 +0,0 @@
|
||||||
add_subdirectory(lhal)
|
|
||||||
add_subdirectory(soc/${CHIP})
|
|
Loading…
Add table
Add a link
Reference in a new issue