diff --git a/CMakeLists.txt b/CMakeLists.txt index f73a9316..b1a05b6c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}) diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 7eb40ec7..79e05e27 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -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) diff --git a/utils/CMakeLists.txt b/components/utils/CMakeLists.txt similarity index 97% rename from utils/CMakeLists.txt rename to components/utils/CMakeLists.txt index b56c86f8..a6dc7474 100644 --- a/utils/CMakeLists.txt +++ b/components/utils/CMakeLists.txt @@ -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 diff --git a/utils/bflb_block_pool/bflb_block_pool.c b/components/utils/bflb_block_pool/bflb_block_pool.c similarity index 100% rename from utils/bflb_block_pool/bflb_block_pool.c rename to components/utils/bflb_block_pool/bflb_block_pool.c diff --git a/utils/bflb_block_pool/bflb_block_pool.h b/components/utils/bflb_block_pool/bflb_block_pool.h similarity index 100% rename from utils/bflb_block_pool/bflb_block_pool.h rename to components/utils/bflb_block_pool/bflb_block_pool.h diff --git a/utils/bflb_timestamp/bflb_timestamp.c b/components/utils/bflb_timestamp/bflb_timestamp.c similarity index 100% rename from utils/bflb_timestamp/bflb_timestamp.c rename to components/utils/bflb_timestamp/bflb_timestamp.c diff --git a/utils/bflb_timestamp/bflb_timestamp.h b/components/utils/bflb_timestamp/bflb_timestamp.h similarity index 100% rename from utils/bflb_timestamp/bflb_timestamp.h rename to components/utils/bflb_timestamp/bflb_timestamp.h diff --git a/utils/libc/printf.c b/components/utils/libc/printf.c similarity index 100% rename from utils/libc/printf.c rename to components/utils/libc/printf.c diff --git a/utils/libc/syscalls.c b/components/utils/libc/syscalls.c similarity index 85% rename from utils/libc/syscalls.c rename to components/utils/libc/syscalls.c index 036c25e3..b59fb308 100644 --- a/utils/libc/syscalls.c +++ b/components/utils/libc/syscalls.c @@ -1,10 +1,14 @@ #include #include #include -#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 } diff --git a/utils/libc/vsnprintf.c b/components/utils/libc/vsnprintf.c similarity index 100% rename from utils/libc/vsnprintf.c rename to components/utils/libc/vsnprintf.c diff --git a/utils/libc/vsnprintf_nano.c b/components/utils/libc/vsnprintf_nano.c similarity index 100% rename from utils/libc/vsnprintf_nano.c rename to components/utils/libc/vsnprintf_nano.c diff --git a/utils/log/log.c b/components/utils/log/log.c similarity index 100% rename from utils/log/log.c rename to components/utils/log/log.c diff --git a/utils/log/log.h b/components/utils/log/log.h similarity index 100% rename from utils/log/log.h rename to components/utils/log/log.h diff --git a/utils/mmheap/mmheap.c b/components/utils/mmheap/bflb_mmheap.c similarity index 93% rename from utils/mmheap/mmheap.c rename to components/utils/mmheap/bflb_mmheap.c index da439679..1d775709 100644 --- a/utils/mmheap/mmheap.c +++ b/components/utils/mmheap/bflb_mmheap.c @@ -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; diff --git a/utils/mmheap/mmheap.h b/components/utils/mmheap/bflb_mmheap.h similarity index 86% rename from utils/mmheap/mmheap.h rename to components/utils/mmheap/bflb_mmheap.h index a2da5c55..874c4d6e 100644 --- a/utils/mmheap/mmheap.h +++ b/components/utils/mmheap/bflb_mmheap.h @@ -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 #include @@ -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 diff --git a/utils/ring_buffer/ring_buffer.c b/components/utils/ring_buffer/ring_buffer.c similarity index 100% rename from utils/ring_buffer/ring_buffer.c rename to components/utils/ring_buffer/ring_buffer.c diff --git a/utils/ring_buffer/ring_buffer.h b/components/utils/ring_buffer/ring_buffer.h similarity index 100% rename from utils/ring_buffer/ring_buffer.h rename to components/utils/ring_buffer/ring_buffer.h diff --git a/utils/soft_crc/soft_crc.c b/components/utils/soft_crc/soft_crc.c similarity index 100% rename from utils/soft_crc/soft_crc.c rename to components/utils/soft_crc/soft_crc.c diff --git a/utils/soft_crc/soft_crc.h b/components/utils/soft_crc/soft_crc.h similarity index 100% rename from utils/soft_crc/soft_crc.h rename to components/utils/soft_crc/soft_crc.h diff --git a/utils/vlibc/printf.c b/components/utils/vlibc/printf.c similarity index 100% rename from utils/vlibc/printf.c rename to components/utils/vlibc/printf.c diff --git a/utils/vlibc/syscalls.c b/components/utils/vlibc/syscalls.c similarity index 85% rename from utils/vlibc/syscalls.c rename to components/utils/vlibc/syscalls.c index 036c25e3..b59fb308 100644 --- a/utils/vlibc/syscalls.c +++ b/components/utils/vlibc/syscalls.c @@ -1,10 +1,14 @@ #include #include #include -#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 } diff --git a/utils/vlibc/vlibc_stdio.c b/components/utils/vlibc/vlibc_stdio.c similarity index 95% rename from utils/vlibc/vlibc_stdio.c rename to components/utils/vlibc/vlibc_stdio.c index 8d4e440b..c1fdf0c1 100644 --- a/utils/vlibc/vlibc_stdio.c +++ b/components/utils/vlibc/vlibc_stdio.c @@ -1,1561 +1,1561 @@ -#include -#include -#include -#include "vlibc_stdio.h" - -#ifndef vlibc_malloc -#define vlibc_malloc malloc -#endif - -#ifndef vlibc_free -#define vlibc_free free -#endif - -#define _VLIBC_IO_HAVE_WRITE ((unsigned char)(0x04)) -#define _VLIBC_IO_HAVE_READ ((unsigned char)(0x08)) - -#define _VLIBC_ABUF_ENABLE ((unsigned char)(0x01)) -#define _VLIBC_ABUF_DISABLE ((unsigned char)(0x00)) - -#define _VLIBC_TYPEIS_IO ((int)(0x01)) -#define _VLIBC_TYPEIS_FILE ((int)(0x02)) - -#define vlibc_file(_stream) ((vlibc_file_t *)(_stream)) - -#ifdef CONFIG_VLIBC_FATFS -int FRESULT_to_errno[20] = { - 0, - EIO, - EPIPE, - EIO, - ENOENT, - ENOENT, - ENOEXEC, - ENOSPC, - EACCES, - ENXIO, - EROFS, - ENXIO, - ENXIO, - EPERM, - EPERM, - EBUSY, - EACCES, - ENOMEM, - EMFILE, - EINVAL -}; -#endif - -#ifdef CONFIG_VLIBC_DEBUG -#define CHECK_FILE(_stream, __ret) \ - do { \ - if ((void *)(_stream) == NULL) { \ - errno = EINVAL; \ - return __ret; \ - } \ - } while (0) -#else -#define CHECK_FILE(_stream, __ret) \ - do { \ - } while (0) -#endif - -#define IF_IO_DEV(_stream) \ - if (((vlibc_file(_stream)->magic) & _VLIBC_MAGIC_MASK) == _VLIBC_IO_MAGIC_CODE) - -#define IF_FILE(_stream) \ - if (((vlibc_file(_stream)->magic) & _VLIBC_MAGIC_MASK) == _VLIBC_FILE_MAGIC_CODE) - -vlibc_file_t *__vlibc_stdio_fileptrs[3] = { NULL, NULL, NULL }; - -/** - * @brief - * @param stream - */ -void vlibc_clearerr(VLIBC_FILE *stream) -{ - CHECK_FILE(stream, /*!< no return */); - CHECK_FILE(stream->file, /*!< no return */); - - IF_IO_DEV(stream) - { - stream->io->err = 0; - } - else IF_FILE(stream) - { -#ifdef CONFIG_VLIBC_FATFS - f_error(stream->file) = 0; -#endif - } - else - { - } -} - -/** - * @brief - * @param stream - * @return int - */ -int vlibc_feof(VLIBC_FILE *stream) -{ - CHECK_FILE(stream, EOF); - CHECK_FILE(stream->file, EOF); - - IF_IO_DEV(stream) - { - return 0; - } - else IF_FILE(stream) - { -#ifdef CONFIG_VLIBC_FATFS - return f_eof(stream->file); -#else - errno = EIO; - return EOF; -#endif - } - else - { - errno = EBADF; - return EOF; - } -} - -/** - * @brief - * @param stream - * @return int - */ -int vlibc_ferror(VLIBC_FILE *stream) -{ - CHECK_FILE(stream, EOF); - CHECK_FILE(stream->file, EOF); - - IF_IO_DEV(stream) - { - return stream->io->err; - } - else IF_FILE(stream) - { -#ifdef CONFIG_VLIBC_FATFS - int fresult; - - fresult = f_error(stream->file); - - return (fresult == FR_OK) ? 0 : EOF; -#else - errno = EIO; - return EOF; -#endif - } - else - { - errno = EBADF; - return EOF; - } -} - -static int __get_mode_vlibc_fopen(const char *mode, unsigned char *iomode, unsigned char *openmode) -{ - /*!< get file and io open mode */ - switch (*mode) { - case 'r': -#ifdef CONFIG_VLIBC_FATFS - *openmode = FA_READ; -#endif - *iomode = _VLIBC_IO_READ; - break; - case 'w': -#ifdef CONFIG_VLIBC_FATFS - *openmode = FA_CREATE_ALWAYS | FA_WRITE; -#endif - *iomode = _VLIBC_IO_WRITE; - break; - case 'a': -#ifdef CONFIG_VLIBC_FATFS - *openmode = FA_OPEN_APPEND | FA_WRITE; -#endif - *iomode = _VLIBC_IO_WRITE; - break; - case 'x': -#ifdef CONFIG_VLIBC_FATFS - *openmode = FA_CREATE_NEW | FA_WRITE; -#endif - *iomode = _VLIBC_IO_WRITE; - break; - default: - errno = EINVAL; - return EOF; - } - - for (int i = 1; i < 7; ++i) { - switch (*++mode) { - case '\0': - break; - case '+': -#ifdef CONFIG_VLIBC_FATFS - *openmode |= (FA_WRITE | FA_READ); -#endif - *iomode |= (_VLIBC_IO_WRITE | _VLIBC_IO_READ); - continue; - case 'b': - continue; - default: - continue; - } - break; - } - - return 0; -} - -static int __check_type_vlibc_fopen(const char *name, unsigned char iomode) -{ - /*!< check type */ - switch (*name) { - case '>': - case '<': { - unsigned char count = 1; - for (int i = 0; i < VLIBC_FILENAME_MAX; i++) { - switch (*name++) { - case '\0': - if ((0 < count) && (count <= _VLIBC_IONAME_MAX)) { - break; - } else { - errno = ENOEXEC; - return EOF; - } - - /*!< output io device */ - case '<': - if (iomode & _VLIBC_IO_READ) { - errno = EINVAL; - return EOF; - } - - if ((0 < count) && (count <= _VLIBC_IONAME_MAX)) { - count = 0; - /*!< have a output io device */ - iomode |= _VLIBC_IO_HAVE_WRITE; - continue; - } else { - errno = ENOEXEC; - return EOF; - } - - /*!< input io device */ - case '>': - if (iomode & _VLIBC_IO_WRITE) { - errno = EINVAL; - return EOF; - } - - if (iomode & _VLIBC_IO_HAVE_READ) { - /*!< only can have one input io device */ - errno = EINVAL; - return EOF; - } - - if ((0 < count) && (count <= _VLIBC_IONAME_MAX)) { - count = 0; - /*!< have a input io device */ - iomode |= _VLIBC_IO_HAVE_READ; - continue; - } else { - errno = ENOEXEC; - return EOF; - } - - default: - count++; - continue; - } - break; - } - - if (iomode & (_VLIBC_IO_HAVE_READ | _VLIBC_IO_HAVE_WRITE)) { - return _VLIBC_TYPEIS_IO; - } - - return _VLIBC_TYPEIS_FILE; - } - default: - return _VLIBC_TYPEIS_FILE; - } -} - -static VLIBC_FILE *__io_vlibc_open(VLIBC_FILE *fnew, const char *name, unsigned char iomode) -{ - int result = 0; - char namebuf[_VLIBC_IONAME_MAX + 2]; - char *nameend = NULL; - char nofree = 0; - - if (fnew == NULL) { - fnew = (VLIBC_FILE *)vlibc_malloc(sizeof(VLIBC_FILE)); - if (fnew == NULL) { - errno = ENOMEM; - return NULL; - } - } else { - nofree = 1; - } - - fnew->io = (void *)vlibc_malloc(sizeof(struct __vlibc_io)); - if (fnew == NULL) { - errno = ENOMEM; - if (nofree == 0) { - vlibc_free(fnew); - } - return NULL; - } - - fnew->io->bg = (void *)vlibc_malloc(VLIBC_BUFSIZ); - if (fnew->io->bg == NULL) { - vlibc_free(fnew->io); - errno = ENOMEM; - if (nofree == 0) { - vlibc_free(fnew); - } - return NULL; - } - - fnew->magic = _VLIBC_IO_MAGIC_CODE; - - fnew->io->dev = 0; - fnew->io->flag = (iomode & (_VLIBC_IO_WRITE | _VLIBC_IO_READ)); - fnew->io->vbuf = _IOLBF; - fnew->io->abuf = _VLIBC_ABUF_ENABLE; - fnew->io->err = 0; - - fnew->io->wp = fnew->io->bg; - fnew->io->rp = fnew->io->bg; - fnew->io->ed = fnew->io->bg + VLIBC_BUFSIZ; - - /*!< init io device */ - for (int i = 0; i < VLIBC_FILENAME_MAX; i++) { - switch (*name) { - case '\0': - break; - - case '<': - case '>': { - for (; i < VLIBC_FILENAME_MAX; i++) { - switch (*name++) { - case '\0': - name--; - break; - case '>': - case '<': - strncpy(namebuf, name, _VLIBC_IONAME_MAX + 1); - nameend = strchr(namebuf, '<'); - if (nameend != NULL) { - *nameend = '\0'; - } else { - nameend = strchr(namebuf, '>'); - if (nameend != NULL) { - *nameend = '\0'; - } - } - - result = __vlibc_io_init(namebuf, iomode & (_VLIBC_IO_READ | _VLIBC_IO_WRITE)); - fnew->io->dev = result; - if (result == 0) { - vlibc_free(fnew->io->bg); - vlibc_free(fnew->io); - fnew->magic = 0; - if (nofree == 0) { - vlibc_free(fnew); - } - errno = ENOENT; - return NULL; - } - break; - - default: - continue; - } - - break; - } - continue; - } - - default: - name++; - continue; - } - break; - } - - return fnew; -} - -#ifdef CONFIG_VLIBC_FATFS -static VLIBC_FILE *__file_vlibc_open(VLIBC_FILE *fnew, const char *name, unsigned char openmode) -{ - int fresult; - char nofree = 0; - - if (fnew == NULL) { - fnew = (VLIBC_FILE *)vlibc_malloc(sizeof(VLIBC_FILE)); - if (fnew == NULL) { - errno = ENOMEM; - return NULL; - } - } else { - nofree = 1; - } - - fnew->file = (FIL *)vlibc_malloc(sizeof(FIL)); - if (fnew->file == NULL) { - if (nofree == 0) { - vlibc_free(fnew); - } - errno = ENOMEM; - return NULL; - } - - fnew->magic = _VLIBC_FILE_MAGIC_CODE; - - fresult = f_open(fnew->file, name, openmode); - - if (fresult != FR_OK) { - if (fresult <= FR_INVALID_PARAMETER) { - errno = FRESULT_to_errno[fresult]; - } - - vlibc_free(fnew->file); - fnew->magic = 0; - if (nofree == 0) { - vlibc_free(fnew); - } - return NULL; - } - - return fnew; -} -#else -static VLIBC_FILE *__file_vlibc_open(VLIBC_FILE *fnew, const char *name, unsigned char openmode) -{ - errno = EIO; - return NULL; -} -#endif - -static int __io_vlibc_close(VLIBC_FILE *stream) -{ - int result; - - if (stream->io->abuf == _VLIBC_ABUF_ENABLE) { - if (stream->io->bg == NULL) { - return EOF; - } - } - - result = __vlibc_io_deinit(stream->io); - if (result != stream->io->dev) { - errno = EINVAL; - return EOF; - } - - if (stream->io->abuf == _VLIBC_ABUF_ENABLE) { - vlibc_free(stream->io->bg); - } - - vlibc_free(stream->io); - stream->magic = 0; - stream->io = NULL; - return 0; -} - -#ifdef CONFIG_VLIBC_FATFS -static int __file_vlibc_close(VLIBC_FILE *stream) -{ - int fresult; - - fresult = f_close(stream->file); - if (fresult != FR_OK) { - if (fresult <= FR_INVALID_PARAMETER) { - errno = FRESULT_to_errno[fresult]; - } - return EOF; - } - - vlibc_free(stream->file); - stream->magic = 0; - stream->io = NULL; - return 0; -} -#else -static int __file_vlibc_close(VLIBC_FILE *stream) -{ - errno = EIO; - return EOF; -} -#endif - -/** - * @brief - * @param filename - * @param mode - * @return VLIBC_FILE* - */ -VLIBC_FILE *vlibc_fopen(const char *filename, const char *mode) -{ - CHECK_FILE(filename, NULL); - CHECK_FILE(mode, NULL); - - unsigned char iomode = 0; - unsigned char openmode = 0; - - if (__get_mode_vlibc_fopen(mode, &iomode, &openmode)) { - return NULL; - } - - switch (__check_type_vlibc_fopen(filename, iomode)) { - case EOF: - return NULL; - case _VLIBC_TYPEIS_IO: - return __io_vlibc_open(NULL, filename, iomode); - case _VLIBC_TYPEIS_FILE: - return __file_vlibc_open(NULL, filename, openmode); - default: - return NULL; - } -} - -/** - * @brief 重定向输入输出流. - * fclose 之后的文件指针无法再 freopen. - * freopen 会关闭原先的流, 并按照 直接在原先的流上重建实体. - * freopen 会将两个流合并为一个流, 可以多次执行将多个流合并, - * 只需要一次 fclose 就可以关闭所有合并的流 - * @param filename - * @param mode - * @param stream - * @return VLIBC_FILE* - */ -VLIBC_FILE *vlibc_freopen(const char *filename, const char *mode, VLIBC_FILE *stream) -{ - CHECK_FILE(filename, NULL); - CHECK_FILE(mode, NULL); - CHECK_FILE(stream, NULL); - CHECK_FILE(stream->file, NULL); - - VLIBC_FILE *fnew = NULL; - - unsigned char iomode = 0; - unsigned char openmode = 0; - - if (__get_mode_vlibc_fopen(mode, &iomode, &openmode)) { - return NULL; - } - - switch (__check_type_vlibc_fopen(filename, iomode)) { - case EOF: - return NULL; - - case _VLIBC_TYPEIS_IO: - IF_IO_DEV(stream) - { - if (__io_vlibc_close(stream)) { - return NULL; - } - - fnew = __io_vlibc_open(stream, filename, iomode); - if (fnew == NULL) { - return NULL; - } - return fnew; - } - else IF_FILE(stream) - { -#ifdef CONFIG_VLIBC_FATFS - if (__file_vlibc_close(stream)) { - return NULL; - } - - fnew = __io_vlibc_open(stream, filename, iomode); - if (fnew == NULL) { - return NULL; - } - - return fnew; -#else - return NULL; -#endif - } - else - { - errno = EBADF; - return NULL; - } - - case _VLIBC_TYPEIS_FILE: - IF_IO_DEV(stream) - { - if (__io_vlibc_close(stream)) { - return NULL; - } - - fnew = __file_vlibc_open(stream, filename, openmode); - if (fnew == NULL) { - return NULL; - } - - return fnew; - } - else IF_FILE(stream) - { -#ifdef CONFIG_VLIBC_FATFS - if (__file_vlibc_close(stream)) { - return NULL; - } - - fnew = __file_vlibc_open(stream, filename, openmode); - if (fnew == NULL) { - return NULL; - } - - return fnew; -#else - return NULL; -#endif - } - else - { - errno = EBADF; - return NULL; - } - default: - return NULL; - } -} - -/** - * @brief - * @param stream - * @return int - */ -int vlibc_fclose(VLIBC_FILE *stream) -{ - CHECK_FILE(stream, EOF); - CHECK_FILE(stream->file, EOF); - - IF_IO_DEV(stream) - { - if (vlibc_fflush(stream)) { - return EOF; - } - - if (__io_vlibc_close(stream)) { - return EOF; - } - - vlibc_free(stream); - - return 0; - } - else IF_FILE(stream) - { - if (vlibc_fflush(stream)) { - return EOF; - } - - if (__file_vlibc_close(stream)) { - return EOF; - } - - vlibc_free(stream); - - return 0; - } - else - { - errno = EBADF; - return EOF; - } -} - -/** - * @brief - * @param ptr - * @param size - * @param nmemb - * @param stream - * @return size_t - */ -size_t vlibc_fread(void *ptr, size_t size, size_t nmemb, VLIBC_FILE *stream) -{ - CHECK_FILE(ptr, 0); - CHECK_FILE(size, 0); - CHECK_FILE(nmemb, 0); - CHECK_FILE(stream, 0); - - IF_IO_DEV(stream) - { - size_t bytes = size * nmemb; - char *bg = stream->io->bg; - char *wp = stream->io->wp; - char *rp = stream->io->rp; - char *ed = stream->io->ed; - - do { - if (rp == wp) { - break; - } - - if (rp == ed) { - rp = bg; - } - - *(char *)ptr++ = *rp++; - } while (--bytes); - - return size * nmemb - bytes; - } - else IF_FILE(stream) - { -#ifdef CONFIG_VLIBC_FATFS - int fresult; - size_t bytes; - fresult = f_read(stream->file, ptr, size * nmemb, &bytes); - if (fresult != FR_OK) { - if (fresult <= FR_INVALID_PARAMETER) { - errno = FRESULT_to_errno[fresult]; - } - } - - return bytes; -#else - return 0; -#endif - } - else - { - errno = EBADF; - return 0; - } -} - -/** - * @brief - * @param ptr - * @param size - * @param nmemb - * @param stream - * @return size_t - */ -size_t vlibc_fwrite(const void *ptr, size_t size, size_t nmemb, VLIBC_FILE *stream) -{ - CHECK_FILE(ptr, 0); - CHECK_FILE(size, 0); - CHECK_FILE(nmemb, 0); - CHECK_FILE(stream, 0); - - IF_IO_DEV(stream) - { - switch (stream->io->vbuf) { - case _IOFBF: { - size_t ret; - size_t bytes = size * nmemb; - char *bg = stream->io->bg; - char *wp = stream->io->wp; - char *ed = stream->io->ed; - - do { - if (wp == ed) { - ret = __vlibc_io_mem2dev(stream->io, bg, ed - bg); - if (ret == 0) { - stream->io->wp = wp; - errno = EINVAL; - return size * nmemb - bytes; - } - wp = bg; - } - - *wp++ = *(char *)ptr++; - } while (--bytes); - - if (wp == ed) { - ret = __vlibc_io_mem2dev(stream->io, bg, ed - bg); - if (ret == 0) { - stream->io->wp = wp; - errno = EINVAL; - return size * nmemb - bytes; - } - wp = bg; - } - - stream->io->wp = wp; - return size * nmemb - bytes; - } - case _IOLBF: { - size_t ret; - size_t bytes = size * nmemb; - char *bg = stream->io->bg; - char *wp = stream->io->wp; - char *ed = stream->io->ed; - - do { - if (wp == ed) { - ret = __vlibc_io_mem2dev(stream->io, bg, ed - bg); - if (ret == 0) { - stream->io->wp = wp; - errno = EINVAL; - return size * nmemb - bytes; - } - wp = bg; - } - - *wp = *(char *)ptr++; - - if (*wp == '\n') { - wp++; - --bytes; - ret = __vlibc_io_mem2dev(stream->io, bg, wp - bg); - if (ret == 0) { - stream->io->wp = wp; - errno = EINVAL; - return size * nmemb - bytes; - } - - wp = bg; - } else { - wp++; - --bytes; - } - } while (bytes); - - stream->io->wp = wp; - - return size * nmemb - bytes; - } - case _IONBF: { - size_t bytes; - bytes = __vlibc_io_mem2dev(stream->io, ptr, size * nmemb); - if (bytes == 0) { - errno = EINVAL; - } - return bytes; - } - default: - errno = EINVAL; - return 0; - } - } - else IF_FILE(stream) - { -#ifdef CONFIG_VLIBC_FATFS - int fresult; - size_t bytes; - fresult = f_write(stream->file, ptr, size * nmemb, &bytes); - if (fresult != FR_OK) { - if (fresult <= FR_INVALID_PARAMETER) { - errno = FRESULT_to_errno[fresult]; - } - } - - return bytes; -#else - errno = EIO; - return 0; -#endif - } - else - { - errno = EBADF; - return 0; - } -} - -/** - * @brief - * @param stream - * @return int - */ -int vlibc_fflush(VLIBC_FILE *stream) -{ - CHECK_FILE(stream, EOF); - CHECK_FILE(stream->file, EOF); - - IF_IO_DEV(stream) - { - switch (stream->io->vbuf) { - case _IOFBF: - case _IOLBF: { - size_t ret; - ret = (size_t)(stream->io->wp - stream->io->bg); - if (ret > 0) { - ret = __vlibc_io_mem2dev(stream->io, stream->io->bg, ret); - if (ret == 0) { - errno = EINVAL; - return EOF; - } - stream->io->wp = stream->io->bg; - } - } - return 0; - - case _IONBF: - return 0; - - default: - errno = EINVAL; - return EOF; - } - } - else IF_FILE(stream) - { -#ifdef CONFIG_VLIBC_FATFS - int fresult; - fresult = f_sync(stream->file); - if (fresult != FR_OK) { - if (fresult <= FR_INVALID_PARAMETER) { - errno = FRESULT_to_errno[fresult]; - } - return EOF; - } - - return 0; -#else - errno = EIO; - return EOF; -#endif - } - else - { - errno = EBADF; - return EOF; - } -} - -/** - * @brief - * @param stream - * @param offset - * @param whence - * @return int - */ -int vlibc_fseek(VLIBC_FILE *stream, long offset, int whence) -{ - CHECK_FILE(stream, EOF); - CHECK_FILE(stream->file, EOF); - - IF_IO_DEV(stream) - { - errno = ESPIPE; - return EOF; - } - else IF_FILE(stream) - { -#ifdef CONFIG_VLIBC_FATFS - int fresult; - long long temp; - - switch (whence) { - case SEEK_SET: - fresult = f_lseek(stream->file, offset); - if (fresult != FR_OK) { - if (fresult <= FR_INVALID_PARAMETER) { - errno = FRESULT_to_errno[fresult]; - } - return EOF; - } - return 0; - - case SEEK_CUR: - temp = (long)stream->file->fptr; - temp += offset; - if (temp > 0xffffffff) { - errno = ESPIPE; - return EOF; - } - - fresult = f_lseek(stream->file, temp); - if (fresult != FR_OK) { - if (fresult <= FR_INVALID_PARAMETER) { - errno = FRESULT_to_errno[fresult]; - } - return EOF; - } - return 0; - - case SEEK_END: - temp = (long)stream->file->obj.objsize; - temp -= offset; - if (temp <= 0) { - temp = 0; - } - fresult = f_lseek(stream->file, temp); - if (fresult != FR_OK) { - if (fresult <= FR_INVALID_PARAMETER) { - errno = FRESULT_to_errno[fresult]; - } - return EOF; - } - return 0; - default: - errno = EINVAL; - return EOF; - } -#else - errno = EIO; - return EOF; -#endif - } - else - { - errno = EBADF; - return EOF; - } -} - -/** - * @brief - * @param stream - * @return long - */ -long vlibc_ftell(VLIBC_FILE *stream) -{ - CHECK_FILE(stream, EOF); - CHECK_FILE(stream->file, EOF); - - IF_IO_DEV(stream) - { - errno = ESPIPE; - return EOF; - } - else IF_FILE(stream) - { -#ifdef CONFIG_VLIBC_FATFS - return (long)f_tell(stream->file); -#else - errno = EIO; - return EOF; -#endif - } - else - { - errno = EBADF; - return EOF; - } -} - -/** - * @brief - * @param filename - * @return int - */ -int vlibc_remove(const char *filename) -{ - CHECK_FILE(filename, EOF); - -#ifdef CONFIG_VLIBC_FATFS - int fresult; - FILINFO finfo; - - fresult = f_stat(filename, &finfo); - if (fresult != FR_OK) { - if (fresult <= FR_INVALID_PARAMETER) { - errno = FRESULT_to_errno[fresult]; - return EOF; - } - } - - fresult = f_unlink(filename); - if (fresult != FR_OK) { - if (fresult <= FR_INVALID_PARAMETER) { - errno = FRESULT_to_errno[fresult]; - return EOF; - } - } - - return 0; -#else - errno = ENOENT; - return EOF; -#endif -} - -/** - * @brief - * @param old_filename - * @param new_filename - * @return int - */ -int vlibc_rename(const char *old_filename, const char *new_filename) -{ - CHECK_FILE(old_filename, EOF); - CHECK_FILE(new_filename, EOF); -#ifdef CONFIG_VLIBC_FATFS - int fresult; - - fresult = f_rename(old_filename, new_filename); - if (fresult != FR_OK) { - if (fresult <= FR_INVALID_PARAMETER) { - errno = FRESULT_to_errno[fresult]; - return EOF; - } - } - - return 0; -#else - errno = ENOENT; - return EOF; -#endif -} - -/** - * @brief - * @param stream - */ -void vlibc_rewind(VLIBC_FILE *stream) -{ - CHECK_FILE(stream, /*!< no return */); - CHECK_FILE(stream->file, /*!< no return */); - - IF_IO_DEV(stream) - { - errno = ESPIPE; - return; - } - else IF_FILE(stream) - { -#ifdef CONFIG_VLIBC_FATFS - int fresult; - fresult = f_lseek(stream->file, 0); - if (fresult != FR_OK) { - if (fresult <= FR_INVALID_PARAMETER) { - errno = FRESULT_to_errno[fresult]; - } - } -#else - errno = EIO; -#endif - } - else - { - errno = EBADF; - return; - } -} - -/** - * @brief - * @param stream - * @param buffer - */ -void vlibc_setbuf(VLIBC_FILE *stream, char *buffer) -{ - CHECK_FILE(stream, /*!< no return */); - - IF_IO_DEV(stream) - { - if (stream->io->abuf == _VLIBC_ABUF_ENABLE) { - if (stream->io->bg == NULL) { - return; - } - - vlibc_free(stream->io->bg); - stream->io->abuf = _VLIBC_ABUF_DISABLE; - } - - stream->io->bg = buffer; - stream->io->wp = buffer; - stream->io->rp = buffer; - - if (buffer == NULL) { - stream->io->ed = buffer; - } else { - stream->io->ed = buffer + VLIBC_BUFSIZ; - } - } - else IF_FILE(stream) - { -#ifdef CONFIG_VLIBC_FATFS - return; -#else - errno = EIO; - return; -#endif - } - else - { - errno = EBADF; - return; - } -} - -/** - * @brief - * @param stream - * @param buffer - * @param mode - * @param size - * @return int - */ -int vlibc_setvbuf(VLIBC_FILE *stream, char *buffer, int mode, size_t size) -{ - CHECK_FILE(stream, EOF); - - IF_IO_DEV(stream) - { - switch (mode) { - case _IOFBF: - case _IOLBF: - vlibc_setbuf(stream, buffer); - if (buffer != NULL) { - stream->io->ed = buffer + size; - } - stream->io->vbuf = mode; - break; - case _IONBF: - vlibc_setbuf(stream, NULL); - stream->io->vbuf = mode; - break; - default: - return EOF; - } - return 0; - } - else IF_FILE(stream) - { -#ifdef CONFIG_VLIBC_FATFS - return EOF; -#else - errno = EIO; - return EOF; -#endif - } - else - { - errno = EBADF; - return EOF; - } -} - -VLIBC_FILE *vlibc_tmpfile(void) -{ -#ifdef CONFIG_VLIBC_FATFS - return NULL; -#else - return NULL; -#endif -} - -char *vlibc_tmpnam(char *str) -{ -#ifdef CONFIG_VLIBC_FATFS - return NULL; -#else - return NULL; -#endif -} - -int vlibc_fscanf(VLIBC_FILE *stream, const char *format, ...) -{ - CHECK_FILE(stream, EOF); - CHECK_FILE(format, EOF); -#ifdef CONFIG_VLIBC_FATFS - return EOF; -#else - return EOF; -#endif -} - -int vlibc_scanf(const char *format, ...) -{ - CHECK_FILE(format, EOF); -#ifdef CONFIG_VLIBC_FATFS - return EOF; -#else - return EOF; -#endif -} - -int vlibc_sscanf(const char *str, const char *format, ...) -{ - CHECK_FILE(str, EOF); - CHECK_FILE(format, EOF); -#ifdef CONFIG_VLIBC_FATFS - return EOF; -#else - return EOF; -#endif -} - -int vlibc_vfscanf(VLIBC_FILE *stream, const char *format, va_list arg) -{ - CHECK_FILE(stream, EOF); - CHECK_FILE(format, EOF); -#ifdef CONFIG_VLIBC_FATFS - return EOF; -#else - return EOF; -#endif -} - -int vlibc_vscanf(const char *format, va_list arg) -{ - CHECK_FILE(format, EOF); -#ifdef CONFIG_VLIBC_FATFS - return EOF; -#else - return EOF; -#endif -} - -int vlibc_vsscanf(const char *str, const char *format, va_list arg) -{ - CHECK_FILE(str, EOF); - CHECK_FILE(format, EOF); -#ifdef CONFIG_VLIBC_FATFS - return EOF; -#else - return EOF; -#endif -} - -int vlibc_fgetc(VLIBC_FILE *stream) -{ - CHECK_FILE(stream, EOF); - IF_IO_DEV(stream) - { - return EOF; - } - else IF_FILE(stream) - { -#ifdef CONFIG_VLIBC_FATFS - int fresult; - int ch; - size_t bytes; - fresult = f_read(stream->file, &ch, 1, &bytes); - if (fresult != FR_OK) { - if (fresult <= FR_INVALID_PARAMETER) { - errno = FRESULT_to_errno[fresult]; - } - - return EOF; - } - if (bytes != 1) { - return EOF; - } - - return ch; -#else - - return EOF; -#endif - } - else - { - return EOF; - } -} - -char *vlibc_fgets(char *str, int size, VLIBC_FILE *stream) -{ - CHECK_FILE(str, NULL); - CHECK_FILE(stream, NULL); -#ifdef CONFIG_VLIBC_FATFS - return NULL; -#else - return NULL; -#endif -} - -int vlibc_fputc(int chr, VLIBC_FILE *stream) -{ - CHECK_FILE(stream, EOF); - - IF_IO_DEV(stream) - { - return EOF; - } - else IF_FILE(stream) - { -#ifdef CONFIG_VLIBC_FATFS - int fresult; - size_t bytes; - fresult = f_write(stream->file, &chr, 1, &bytes); - if (fresult != FR_OK) { - if (fresult <= FR_INVALID_PARAMETER) { - errno = FRESULT_to_errno[fresult]; - } - - return EOF; - } - if (bytes != 1) { - return EOF; - } - - return 0; -#else - - return EOF; -#endif - } - else - { - return EOF; - } -} - -int vlibc_fputs(const char *str, VLIBC_FILE *stream) -{ - return vlibc_fprintf(stream, str); -} - -int vlibc_getc(VLIBC_FILE *stream) -{ - CHECK_FILE(stream, EOF); - IF_IO_DEV(stream) - { - return EOF; - } - else IF_FILE(stream) - { -#ifdef CONFIG_VLIBC_FATFS - int fresult; - int ch; - size_t bytes; - fresult = f_read(stream->file, &ch, 1, &bytes); - if (fresult != FR_OK) { - if (fresult <= FR_INVALID_PARAMETER) { - errno = FRESULT_to_errno[fresult]; - } - - return EOF; - } - if (bytes != 1) { - return EOF; - } - - return ch; -#else - - return EOF; -#endif - } - else - { - return EOF; - } -} - -int vlibc_getchar(void) -{ -#ifdef CONFIG_VLIBC_FATFS - return EOF; -#else - return EOF; -#endif -} - -char *vlibc_gets(char *str) -{ - CHECK_FILE(str, NULL); -#ifdef CONFIG_VLIBC_FATFS - return NULL; -#else - return NULL; -#endif -} - -int vlibc_putc(int chr, VLIBC_FILE *stream) -{ - CHECK_FILE(stream, EOF); - - IF_IO_DEV(stream) - { - size_t size; - size = vlibc_fwrite(&chr, 1, 1, stream); - if (size == 1) { - return 0; - } else { - return EOF; - } - } - else IF_FILE(stream) - { -#ifdef CONFIG_VLIBC_FATFS - int fresult; - size_t bytes; - fresult = f_write(stream->file, &chr, 1, &bytes); - if (fresult != FR_OK) { - if (fresult <= FR_INVALID_PARAMETER) { - errno = FRESULT_to_errno[fresult]; - } - - return EOF; - } - if (bytes != 1) { - return EOF; - } - - return 0; -#else - - return EOF; -#endif - } - else - { - return EOF; - } -} - -int vlibc_putchar(int chr) -{ - IF_IO_DEV(vlibc_stdout) - { - size_t size; - size = vlibc_fwrite(&chr, 1, 1, vlibc_stdout); - if (size == 1) { - return 0; - } else { - return EOF; - } - } - else IF_FILE(vlibc_stdout) - { -#ifdef CONFIG_VLIBC_FATFS - int fresult; - size_t bytes; - fresult = f_write(vlibc_stdout->file, &chr, 1, &bytes); - if (fresult != FR_OK) { - if (fresult <= FR_INVALID_PARAMETER) { - errno = FRESULT_to_errno[fresult]; - } - - return EOF; - } - if (bytes != 1) { - return EOF; - } - - return 0; -#else - - return EOF; -#endif - } - else - { - return EOF; - } -} - -int vlibc_puts(const char *str) -{ - return vlibc_printf(str); -} - -void vlibc_perror(const char *str) -{ - CHECK_FILE(str, /*!< no return */); -} +#include +#include +#include +#include "vlibc_stdio.h" + +#ifndef vlibc_malloc +#define vlibc_malloc malloc +#endif + +#ifndef vlibc_free +#define vlibc_free free +#endif + +#define _VLIBC_IO_HAVE_WRITE ((unsigned char)(0x04)) +#define _VLIBC_IO_HAVE_READ ((unsigned char)(0x08)) + +#define _VLIBC_ABUF_ENABLE ((unsigned char)(0x01)) +#define _VLIBC_ABUF_DISABLE ((unsigned char)(0x00)) + +#define _VLIBC_TYPEIS_IO ((int)(0x01)) +#define _VLIBC_TYPEIS_FILE ((int)(0x02)) + +#define vlibc_file(_stream) ((vlibc_file_t *)(_stream)) + +#ifdef CONFIG_VLIBC_FATFS +int FRESULT_to_errno[20] = { + 0, + EIO, + EPIPE, + EIO, + ENOENT, + ENOENT, + ENOEXEC, + ENOSPC, + EACCES, + ENXIO, + EROFS, + ENXIO, + ENXIO, + EPERM, + EPERM, + EBUSY, + EACCES, + ENOMEM, + EMFILE, + EINVAL +}; +#endif + +#ifdef CONFIG_VLIBC_DEBUG +#define CHECK_FILE(_stream, __ret) \ + do { \ + if ((void *)(_stream) == NULL) { \ + errno = EINVAL; \ + return __ret; \ + } \ + } while (0) +#else +#define CHECK_FILE(_stream, __ret) \ + do { \ + } while (0) +#endif + +#define IF_IO_DEV(_stream) \ + if (((vlibc_file(_stream)->magic) & _VLIBC_MAGIC_MASK) == _VLIBC_IO_MAGIC_CODE) + +#define IF_FILE(_stream) \ + if (((vlibc_file(_stream)->magic) & _VLIBC_MAGIC_MASK) == _VLIBC_FILE_MAGIC_CODE) + +vlibc_file_t *__vlibc_stdio_fileptrs[3] = { NULL, NULL, NULL }; + +/** + * @brief + * @param stream + */ +void vlibc_clearerr(VLIBC_FILE *stream) +{ + CHECK_FILE(stream, /*!< no return */); + CHECK_FILE(stream->file, /*!< no return */); + + IF_IO_DEV(stream) + { + stream->io->err = 0; + } + else IF_FILE(stream) + { +#ifdef CONFIG_VLIBC_FATFS + f_error(stream->file) = 0; +#endif + } + else + { + } +} + +/** + * @brief + * @param stream + * @return int + */ +int vlibc_feof(VLIBC_FILE *stream) +{ + CHECK_FILE(stream, EOF); + CHECK_FILE(stream->file, EOF); + + IF_IO_DEV(stream) + { + return 0; + } + else IF_FILE(stream) + { +#ifdef CONFIG_VLIBC_FATFS + return f_eof(stream->file); +#else + errno = EIO; + return EOF; +#endif + } + else + { + errno = EBADF; + return EOF; + } +} + +/** + * @brief + * @param stream + * @return int + */ +int vlibc_ferror(VLIBC_FILE *stream) +{ + CHECK_FILE(stream, EOF); + CHECK_FILE(stream->file, EOF); + + IF_IO_DEV(stream) + { + return stream->io->err; + } + else IF_FILE(stream) + { +#ifdef CONFIG_VLIBC_FATFS + int fresult; + + fresult = f_error(stream->file); + + return (fresult == FR_OK) ? 0 : EOF; +#else + errno = EIO; + return EOF; +#endif + } + else + { + errno = EBADF; + return EOF; + } +} + +static int __get_mode_vlibc_fopen(const char *mode, unsigned char *iomode, unsigned char *openmode) +{ + /*!< get file and io open mode */ + switch (*mode) { + case 'r': +#ifdef CONFIG_VLIBC_FATFS + *openmode = FA_READ; +#endif + *iomode = _VLIBC_IO_READ; + break; + case 'w': +#ifdef CONFIG_VLIBC_FATFS + *openmode = FA_CREATE_ALWAYS | FA_WRITE; +#endif + *iomode = _VLIBC_IO_WRITE; + break; + case 'a': +#ifdef CONFIG_VLIBC_FATFS + *openmode = FA_OPEN_APPEND | FA_WRITE; +#endif + *iomode = _VLIBC_IO_WRITE; + break; + case 'x': +#ifdef CONFIG_VLIBC_FATFS + *openmode = FA_CREATE_NEW | FA_WRITE; +#endif + *iomode = _VLIBC_IO_WRITE; + break; + default: + errno = EINVAL; + return EOF; + } + + for (int i = 1; i < 7; ++i) { + switch (*++mode) { + case '\0': + break; + case '+': +#ifdef CONFIG_VLIBC_FATFS + *openmode |= (FA_WRITE | FA_READ); +#endif + *iomode |= (_VLIBC_IO_WRITE | _VLIBC_IO_READ); + continue; + case 'b': + continue; + default: + continue; + } + break; + } + + return 0; +} + +static int __check_type_vlibc_fopen(const char *name, unsigned char iomode) +{ + /*!< check type */ + switch (*name) { + case '>': + case '<': { + unsigned char count = 1; + for (int i = 0; i < VLIBC_FILENAME_MAX; i++) { + switch (*name++) { + case '\0': + if ((0 < count) && (count <= _VLIBC_IONAME_MAX)) { + break; + } else { + errno = ENOEXEC; + return EOF; + } + + /*!< output io device */ + case '<': + if (iomode & _VLIBC_IO_READ) { + errno = EINVAL; + return EOF; + } + + if ((0 < count) && (count <= _VLIBC_IONAME_MAX)) { + count = 0; + /*!< have a output io device */ + iomode |= _VLIBC_IO_HAVE_WRITE; + continue; + } else { + errno = ENOEXEC; + return EOF; + } + + /*!< input io device */ + case '>': + if (iomode & _VLIBC_IO_WRITE) { + errno = EINVAL; + return EOF; + } + + if (iomode & _VLIBC_IO_HAVE_READ) { + /*!< only can have one input io device */ + errno = EINVAL; + return EOF; + } + + if ((0 < count) && (count <= _VLIBC_IONAME_MAX)) { + count = 0; + /*!< have a input io device */ + iomode |= _VLIBC_IO_HAVE_READ; + continue; + } else { + errno = ENOEXEC; + return EOF; + } + + default: + count++; + continue; + } + break; + } + + if (iomode & (_VLIBC_IO_HAVE_READ | _VLIBC_IO_HAVE_WRITE)) { + return _VLIBC_TYPEIS_IO; + } + + return _VLIBC_TYPEIS_FILE; + } + default: + return _VLIBC_TYPEIS_FILE; + } +} + +static VLIBC_FILE *__io_vlibc_open(VLIBC_FILE *fnew, const char *name, unsigned char iomode) +{ + int result = 0; + char namebuf[_VLIBC_IONAME_MAX + 2]; + char *nameend = NULL; + char nofree = 0; + + if (fnew == NULL) { + fnew = (VLIBC_FILE *)vlibc_malloc(sizeof(VLIBC_FILE)); + if (fnew == NULL) { + errno = ENOMEM; + return NULL; + } + } else { + nofree = 1; + } + + fnew->io = (void *)vlibc_malloc(sizeof(struct __vlibc_io)); + if (fnew == NULL) { + errno = ENOMEM; + if (nofree == 0) { + vlibc_free(fnew); + } + return NULL; + } + + fnew->io->bg = (void *)vlibc_malloc(VLIBC_BUFSIZ); + if (fnew->io->bg == NULL) { + vlibc_free(fnew->io); + errno = ENOMEM; + if (nofree == 0) { + vlibc_free(fnew); + } + return NULL; + } + + fnew->magic = _VLIBC_IO_MAGIC_CODE; + + fnew->io->dev = 0; + fnew->io->flag = (iomode & (_VLIBC_IO_WRITE | _VLIBC_IO_READ)); + fnew->io->vbuf = _IOLBF; + fnew->io->abuf = _VLIBC_ABUF_ENABLE; + fnew->io->err = 0; + + fnew->io->wp = fnew->io->bg; + fnew->io->rp = fnew->io->bg; + fnew->io->ed = fnew->io->bg + VLIBC_BUFSIZ; + + /*!< init io device */ + for (int i = 0; i < VLIBC_FILENAME_MAX; i++) { + switch (*name) { + case '\0': + break; + + case '<': + case '>': { + for (; i < VLIBC_FILENAME_MAX; i++) { + switch (*name++) { + case '\0': + name--; + break; + case '>': + case '<': + strncpy(namebuf, name, _VLIBC_IONAME_MAX + 1); + nameend = strchr(namebuf, '<'); + if (nameend != NULL) { + *nameend = '\0'; + } else { + nameend = strchr(namebuf, '>'); + if (nameend != NULL) { + *nameend = '\0'; + } + } + + result = __vlibc_io_init(namebuf, iomode & (_VLIBC_IO_READ | _VLIBC_IO_WRITE)); + fnew->io->dev = result; + if (result == 0) { + vlibc_free(fnew->io->bg); + vlibc_free(fnew->io); + fnew->magic = 0; + if (nofree == 0) { + vlibc_free(fnew); + } + errno = ENOENT; + return NULL; + } + break; + + default: + continue; + } + + break; + } + continue; + } + + default: + name++; + continue; + } + break; + } + + return fnew; +} + +#ifdef CONFIG_VLIBC_FATFS +static VLIBC_FILE *__file_vlibc_open(VLIBC_FILE *fnew, const char *name, unsigned char openmode) +{ + int fresult; + char nofree = 0; + + if (fnew == NULL) { + fnew = (VLIBC_FILE *)vlibc_malloc(sizeof(VLIBC_FILE)); + if (fnew == NULL) { + errno = ENOMEM; + return NULL; + } + } else { + nofree = 1; + } + + fnew->file = (FIL *)vlibc_malloc(sizeof(FIL)); + if (fnew->file == NULL) { + if (nofree == 0) { + vlibc_free(fnew); + } + errno = ENOMEM; + return NULL; + } + + fnew->magic = _VLIBC_FILE_MAGIC_CODE; + + fresult = f_open(fnew->file, name, openmode); + + if (fresult != FR_OK) { + if (fresult <= FR_INVALID_PARAMETER) { + errno = FRESULT_to_errno[fresult]; + } + + vlibc_free(fnew->file); + fnew->magic = 0; + if (nofree == 0) { + vlibc_free(fnew); + } + return NULL; + } + + return fnew; +} +#else +static VLIBC_FILE *__file_vlibc_open(VLIBC_FILE *fnew, const char *name, unsigned char openmode) +{ + errno = EIO; + return NULL; +} +#endif + +static int __io_vlibc_close(VLIBC_FILE *stream) +{ + int result; + + if (stream->io->abuf == _VLIBC_ABUF_ENABLE) { + if (stream->io->bg == NULL) { + return EOF; + } + } + + result = __vlibc_io_deinit(stream->io); + if (result != stream->io->dev) { + errno = EINVAL; + return EOF; + } + + if (stream->io->abuf == _VLIBC_ABUF_ENABLE) { + vlibc_free(stream->io->bg); + } + + vlibc_free(stream->io); + stream->magic = 0; + stream->io = NULL; + return 0; +} + +#ifdef CONFIG_VLIBC_FATFS +static int __file_vlibc_close(VLIBC_FILE *stream) +{ + int fresult; + + fresult = f_close(stream->file); + if (fresult != FR_OK) { + if (fresult <= FR_INVALID_PARAMETER) { + errno = FRESULT_to_errno[fresult]; + } + return EOF; + } + + vlibc_free(stream->file); + stream->magic = 0; + stream->io = NULL; + return 0; +} +#else +static int __file_vlibc_close(VLIBC_FILE *stream) +{ + errno = EIO; + return EOF; +} +#endif + +/** + * @brief + * @param filename + * @param mode + * @return VLIBC_FILE* + */ +VLIBC_FILE *vlibc_fopen(const char *filename, const char *mode) +{ + CHECK_FILE(filename, NULL); + CHECK_FILE(mode, NULL); + + unsigned char iomode = 0; + unsigned char openmode = 0; + + if (__get_mode_vlibc_fopen(mode, &iomode, &openmode)) { + return NULL; + } + + switch (__check_type_vlibc_fopen(filename, iomode)) { + case EOF: + return NULL; + case _VLIBC_TYPEIS_IO: + return __io_vlibc_open(NULL, filename, iomode); + case _VLIBC_TYPEIS_FILE: + return __file_vlibc_open(NULL, filename, openmode); + default: + return NULL; + } +} + +/** + * @brief 重定向输入输出流. + * fclose 之后的文件指针无法再 freopen. + * freopen 会关闭原先的流, 并按照 直接在原先的流上重建实体. + * freopen 会将两个流合并为一个流, 可以多次执行将多个流合并, + * 只需要一次 fclose 就可以关闭所有合并的流 + * @param filename + * @param mode + * @param stream + * @return VLIBC_FILE* + */ +VLIBC_FILE *vlibc_freopen(const char *filename, const char *mode, VLIBC_FILE *stream) +{ + CHECK_FILE(filename, NULL); + CHECK_FILE(mode, NULL); + CHECK_FILE(stream, NULL); + CHECK_FILE(stream->file, NULL); + + VLIBC_FILE *fnew = NULL; + + unsigned char iomode = 0; + unsigned char openmode = 0; + + if (__get_mode_vlibc_fopen(mode, &iomode, &openmode)) { + return NULL; + } + + switch (__check_type_vlibc_fopen(filename, iomode)) { + case EOF: + return NULL; + + case _VLIBC_TYPEIS_IO: + IF_IO_DEV(stream) + { + if (__io_vlibc_close(stream)) { + return NULL; + } + + fnew = __io_vlibc_open(stream, filename, iomode); + if (fnew == NULL) { + return NULL; + } + return fnew; + } + else IF_FILE(stream) + { +#ifdef CONFIG_VLIBC_FATFS + if (__file_vlibc_close(stream)) { + return NULL; + } + + fnew = __io_vlibc_open(stream, filename, iomode); + if (fnew == NULL) { + return NULL; + } + + return fnew; +#else + return NULL; +#endif + } + else + { + errno = EBADF; + return NULL; + } + + case _VLIBC_TYPEIS_FILE: + IF_IO_DEV(stream) + { + if (__io_vlibc_close(stream)) { + return NULL; + } + + fnew = __file_vlibc_open(stream, filename, openmode); + if (fnew == NULL) { + return NULL; + } + + return fnew; + } + else IF_FILE(stream) + { +#ifdef CONFIG_VLIBC_FATFS + if (__file_vlibc_close(stream)) { + return NULL; + } + + fnew = __file_vlibc_open(stream, filename, openmode); + if (fnew == NULL) { + return NULL; + } + + return fnew; +#else + return NULL; +#endif + } + else + { + errno = EBADF; + return NULL; + } + default: + return NULL; + } +} + +/** + * @brief + * @param stream + * @return int + */ +int vlibc_fclose(VLIBC_FILE *stream) +{ + CHECK_FILE(stream, EOF); + CHECK_FILE(stream->file, EOF); + + IF_IO_DEV(stream) + { + if (vlibc_fflush(stream)) { + return EOF; + } + + if (__io_vlibc_close(stream)) { + return EOF; + } + + vlibc_free(stream); + + return 0; + } + else IF_FILE(stream) + { + if (vlibc_fflush(stream)) { + return EOF; + } + + if (__file_vlibc_close(stream)) { + return EOF; + } + + vlibc_free(stream); + + return 0; + } + else + { + errno = EBADF; + return EOF; + } +} + +/** + * @brief + * @param ptr + * @param size + * @param nmemb + * @param stream + * @return size_t + */ +size_t vlibc_fread(void *ptr, size_t size, size_t nmemb, VLIBC_FILE *stream) +{ + CHECK_FILE(ptr, 0); + CHECK_FILE(size, 0); + CHECK_FILE(nmemb, 0); + CHECK_FILE(stream, 0); + + IF_IO_DEV(stream) + { + size_t bytes = size * nmemb; + char *bg = stream->io->bg; + char *wp = stream->io->wp; + char *rp = stream->io->rp; + char *ed = stream->io->ed; + + do { + if (rp == wp) { + break; + } + + if (rp == ed) { + rp = bg; + } + + *(char *)ptr++ = *rp++; + } while (--bytes); + + return size * nmemb - bytes; + } + else IF_FILE(stream) + { +#ifdef CONFIG_VLIBC_FATFS + int fresult; + size_t bytes; + fresult = f_read(stream->file, ptr, size * nmemb, &bytes); + if (fresult != FR_OK) { + if (fresult <= FR_INVALID_PARAMETER) { + errno = FRESULT_to_errno[fresult]; + } + } + + return bytes; +#else + return 0; +#endif + } + else + { + errno = EBADF; + return 0; + } +} + +/** + * @brief + * @param ptr + * @param size + * @param nmemb + * @param stream + * @return size_t + */ +size_t vlibc_fwrite(const void *ptr, size_t size, size_t nmemb, VLIBC_FILE *stream) +{ + CHECK_FILE(ptr, 0); + CHECK_FILE(size, 0); + CHECK_FILE(nmemb, 0); + CHECK_FILE(stream, 0); + + IF_IO_DEV(stream) + { + switch (stream->io->vbuf) { + case _IOFBF: { + size_t ret; + size_t bytes = size * nmemb; + char *bg = stream->io->bg; + char *wp = stream->io->wp; + char *ed = stream->io->ed; + + do { + if (wp == ed) { + ret = __vlibc_io_mem2dev(stream->io, bg, ed - bg); + if (ret == 0) { + stream->io->wp = wp; + errno = EINVAL; + return size * nmemb - bytes; + } + wp = bg; + } + + *wp++ = *(char *)ptr++; + } while (--bytes); + + if (wp == ed) { + ret = __vlibc_io_mem2dev(stream->io, bg, ed - bg); + if (ret == 0) { + stream->io->wp = wp; + errno = EINVAL; + return size * nmemb - bytes; + } + wp = bg; + } + + stream->io->wp = wp; + return size * nmemb - bytes; + } + case _IOLBF: { + size_t ret; + size_t bytes = size * nmemb; + char *bg = stream->io->bg; + char *wp = stream->io->wp; + char *ed = stream->io->ed; + + do { + if (wp == ed) { + ret = __vlibc_io_mem2dev(stream->io, bg, ed - bg); + if (ret == 0) { + stream->io->wp = wp; + errno = EINVAL; + return size * nmemb - bytes; + } + wp = bg; + } + + *wp = *(char *)ptr++; + + if (*wp == '\n') { + wp++; + --bytes; + ret = __vlibc_io_mem2dev(stream->io, bg, wp - bg); + if (ret == 0) { + stream->io->wp = wp; + errno = EINVAL; + return size * nmemb - bytes; + } + + wp = bg; + } else { + wp++; + --bytes; + } + } while (bytes); + + stream->io->wp = wp; + + return size * nmemb - bytes; + } + case _IONBF: { + size_t bytes; + bytes = __vlibc_io_mem2dev(stream->io, ptr, size * nmemb); + if (bytes == 0) { + errno = EINVAL; + } + return bytes; + } + default: + errno = EINVAL; + return 0; + } + } + else IF_FILE(stream) + { +#ifdef CONFIG_VLIBC_FATFS + int fresult; + size_t bytes; + fresult = f_write(stream->file, ptr, size * nmemb, &bytes); + if (fresult != FR_OK) { + if (fresult <= FR_INVALID_PARAMETER) { + errno = FRESULT_to_errno[fresult]; + } + } + + return bytes; +#else + errno = EIO; + return 0; +#endif + } + else + { + errno = EBADF; + return 0; + } +} + +/** + * @brief + * @param stream + * @return int + */ +int vlibc_fflush(VLIBC_FILE *stream) +{ + CHECK_FILE(stream, EOF); + CHECK_FILE(stream->file, EOF); + + IF_IO_DEV(stream) + { + switch (stream->io->vbuf) { + case _IOFBF: + case _IOLBF: { + size_t ret; + ret = (size_t)(stream->io->wp - stream->io->bg); + if (ret > 0) { + ret = __vlibc_io_mem2dev(stream->io, stream->io->bg, ret); + if (ret == 0) { + errno = EINVAL; + return EOF; + } + stream->io->wp = stream->io->bg; + } + } + return 0; + + case _IONBF: + return 0; + + default: + errno = EINVAL; + return EOF; + } + } + else IF_FILE(stream) + { +#ifdef CONFIG_VLIBC_FATFS + int fresult; + fresult = f_sync(stream->file); + if (fresult != FR_OK) { + if (fresult <= FR_INVALID_PARAMETER) { + errno = FRESULT_to_errno[fresult]; + } + return EOF; + } + + return 0; +#else + errno = EIO; + return EOF; +#endif + } + else + { + errno = EBADF; + return EOF; + } +} + +/** + * @brief + * @param stream + * @param offset + * @param whence + * @return int + */ +int vlibc_fseek(VLIBC_FILE *stream, long offset, int whence) +{ + CHECK_FILE(stream, EOF); + CHECK_FILE(stream->file, EOF); + + IF_IO_DEV(stream) + { + errno = ESPIPE; + return EOF; + } + else IF_FILE(stream) + { +#ifdef CONFIG_VLIBC_FATFS + int fresult; + long long temp; + + switch (whence) { + case SEEK_SET: + fresult = f_lseek(stream->file, offset); + if (fresult != FR_OK) { + if (fresult <= FR_INVALID_PARAMETER) { + errno = FRESULT_to_errno[fresult]; + } + return EOF; + } + return 0; + + case SEEK_CUR: + temp = (long)stream->file->fptr; + temp += offset; + if (temp > 0xffffffff) { + errno = ESPIPE; + return EOF; + } + + fresult = f_lseek(stream->file, temp); + if (fresult != FR_OK) { + if (fresult <= FR_INVALID_PARAMETER) { + errno = FRESULT_to_errno[fresult]; + } + return EOF; + } + return 0; + + case SEEK_END: + temp = (long)stream->file->obj.objsize; + temp -= offset; + if (temp <= 0) { + temp = 0; + } + fresult = f_lseek(stream->file, temp); + if (fresult != FR_OK) { + if (fresult <= FR_INVALID_PARAMETER) { + errno = FRESULT_to_errno[fresult]; + } + return EOF; + } + return 0; + default: + errno = EINVAL; + return EOF; + } +#else + errno = EIO; + return EOF; +#endif + } + else + { + errno = EBADF; + return EOF; + } +} + +/** + * @brief + * @param stream + * @return long + */ +long vlibc_ftell(VLIBC_FILE *stream) +{ + CHECK_FILE(stream, EOF); + CHECK_FILE(stream->file, EOF); + + IF_IO_DEV(stream) + { + errno = ESPIPE; + return EOF; + } + else IF_FILE(stream) + { +#ifdef CONFIG_VLIBC_FATFS + return (long)f_tell(stream->file); +#else + errno = EIO; + return EOF; +#endif + } + else + { + errno = EBADF; + return EOF; + } +} + +/** + * @brief + * @param filename + * @return int + */ +int vlibc_remove(const char *filename) +{ + CHECK_FILE(filename, EOF); + +#ifdef CONFIG_VLIBC_FATFS + int fresult; + FILINFO finfo; + + fresult = f_stat(filename, &finfo); + if (fresult != FR_OK) { + if (fresult <= FR_INVALID_PARAMETER) { + errno = FRESULT_to_errno[fresult]; + return EOF; + } + } + + fresult = f_unlink(filename); + if (fresult != FR_OK) { + if (fresult <= FR_INVALID_PARAMETER) { + errno = FRESULT_to_errno[fresult]; + return EOF; + } + } + + return 0; +#else + errno = ENOENT; + return EOF; +#endif +} + +/** + * @brief + * @param old_filename + * @param new_filename + * @return int + */ +int vlibc_rename(const char *old_filename, const char *new_filename) +{ + CHECK_FILE(old_filename, EOF); + CHECK_FILE(new_filename, EOF); +#ifdef CONFIG_VLIBC_FATFS + int fresult; + + fresult = f_rename(old_filename, new_filename); + if (fresult != FR_OK) { + if (fresult <= FR_INVALID_PARAMETER) { + errno = FRESULT_to_errno[fresult]; + return EOF; + } + } + + return 0; +#else + errno = ENOENT; + return EOF; +#endif +} + +/** + * @brief + * @param stream + */ +void vlibc_rewind(VLIBC_FILE *stream) +{ + CHECK_FILE(stream, /*!< no return */); + CHECK_FILE(stream->file, /*!< no return */); + + IF_IO_DEV(stream) + { + errno = ESPIPE; + return; + } + else IF_FILE(stream) + { +#ifdef CONFIG_VLIBC_FATFS + int fresult; + fresult = f_lseek(stream->file, 0); + if (fresult != FR_OK) { + if (fresult <= FR_INVALID_PARAMETER) { + errno = FRESULT_to_errno[fresult]; + } + } +#else + errno = EIO; +#endif + } + else + { + errno = EBADF; + return; + } +} + +/** + * @brief + * @param stream + * @param buffer + */ +void vlibc_setbuf(VLIBC_FILE *stream, char *buffer) +{ + CHECK_FILE(stream, /*!< no return */); + + IF_IO_DEV(stream) + { + if (stream->io->abuf == _VLIBC_ABUF_ENABLE) { + if (stream->io->bg == NULL) { + return; + } + + vlibc_free(stream->io->bg); + stream->io->abuf = _VLIBC_ABUF_DISABLE; + } + + stream->io->bg = buffer; + stream->io->wp = buffer; + stream->io->rp = buffer; + + if (buffer == NULL) { + stream->io->ed = buffer; + } else { + stream->io->ed = buffer + VLIBC_BUFSIZ; + } + } + else IF_FILE(stream) + { +#ifdef CONFIG_VLIBC_FATFS + return; +#else + errno = EIO; + return; +#endif + } + else + { + errno = EBADF; + return; + } +} + +/** + * @brief + * @param stream + * @param buffer + * @param mode + * @param size + * @return int + */ +int vlibc_setvbuf(VLIBC_FILE *stream, char *buffer, int mode, size_t size) +{ + CHECK_FILE(stream, EOF); + + IF_IO_DEV(stream) + { + switch (mode) { + case _IOFBF: + case _IOLBF: + vlibc_setbuf(stream, buffer); + if (buffer != NULL) { + stream->io->ed = buffer + size; + } + stream->io->vbuf = mode; + break; + case _IONBF: + vlibc_setbuf(stream, NULL); + stream->io->vbuf = mode; + break; + default: + return EOF; + } + return 0; + } + else IF_FILE(stream) + { +#ifdef CONFIG_VLIBC_FATFS + return EOF; +#else + errno = EIO; + return EOF; +#endif + } + else + { + errno = EBADF; + return EOF; + } +} + +VLIBC_FILE *vlibc_tmpfile(void) +{ +#ifdef CONFIG_VLIBC_FATFS + return NULL; +#else + return NULL; +#endif +} + +char *vlibc_tmpnam(char *str) +{ +#ifdef CONFIG_VLIBC_FATFS + return NULL; +#else + return NULL; +#endif +} + +int vlibc_fscanf(VLIBC_FILE *stream, const char *format, ...) +{ + CHECK_FILE(stream, EOF); + CHECK_FILE(format, EOF); +#ifdef CONFIG_VLIBC_FATFS + return EOF; +#else + return EOF; +#endif +} + +int vlibc_scanf(const char *format, ...) +{ + CHECK_FILE(format, EOF); +#ifdef CONFIG_VLIBC_FATFS + return EOF; +#else + return EOF; +#endif +} + +int vlibc_sscanf(const char *str, const char *format, ...) +{ + CHECK_FILE(str, EOF); + CHECK_FILE(format, EOF); +#ifdef CONFIG_VLIBC_FATFS + return EOF; +#else + return EOF; +#endif +} + +int vlibc_vfscanf(VLIBC_FILE *stream, const char *format, va_list arg) +{ + CHECK_FILE(stream, EOF); + CHECK_FILE(format, EOF); +#ifdef CONFIG_VLIBC_FATFS + return EOF; +#else + return EOF; +#endif +} + +int vlibc_vscanf(const char *format, va_list arg) +{ + CHECK_FILE(format, EOF); +#ifdef CONFIG_VLIBC_FATFS + return EOF; +#else + return EOF; +#endif +} + +int vlibc_vsscanf(const char *str, const char *format, va_list arg) +{ + CHECK_FILE(str, EOF); + CHECK_FILE(format, EOF); +#ifdef CONFIG_VLIBC_FATFS + return EOF; +#else + return EOF; +#endif +} + +int vlibc_fgetc(VLIBC_FILE *stream) +{ + CHECK_FILE(stream, EOF); + IF_IO_DEV(stream) + { + return EOF; + } + else IF_FILE(stream) + { +#ifdef CONFIG_VLIBC_FATFS + int fresult; + int ch; + size_t bytes; + fresult = f_read(stream->file, &ch, 1, &bytes); + if (fresult != FR_OK) { + if (fresult <= FR_INVALID_PARAMETER) { + errno = FRESULT_to_errno[fresult]; + } + + return EOF; + } + if (bytes != 1) { + return EOF; + } + + return ch; +#else + + return EOF; +#endif + } + else + { + return EOF; + } +} + +char *vlibc_fgets(char *str, int size, VLIBC_FILE *stream) +{ + CHECK_FILE(str, NULL); + CHECK_FILE(stream, NULL); +#ifdef CONFIG_VLIBC_FATFS + return NULL; +#else + return NULL; +#endif +} + +int vlibc_fputc(int chr, VLIBC_FILE *stream) +{ + CHECK_FILE(stream, EOF); + + IF_IO_DEV(stream) + { + return EOF; + } + else IF_FILE(stream) + { +#ifdef CONFIG_VLIBC_FATFS + int fresult; + size_t bytes; + fresult = f_write(stream->file, &chr, 1, &bytes); + if (fresult != FR_OK) { + if (fresult <= FR_INVALID_PARAMETER) { + errno = FRESULT_to_errno[fresult]; + } + + return EOF; + } + if (bytes != 1) { + return EOF; + } + + return 0; +#else + + return EOF; +#endif + } + else + { + return EOF; + } +} + +int vlibc_fputs(const char *str, VLIBC_FILE *stream) +{ + return vlibc_fprintf(stream, str); +} + +int vlibc_getc(VLIBC_FILE *stream) +{ + CHECK_FILE(stream, EOF); + IF_IO_DEV(stream) + { + return EOF; + } + else IF_FILE(stream) + { +#ifdef CONFIG_VLIBC_FATFS + int fresult; + int ch; + size_t bytes; + fresult = f_read(stream->file, &ch, 1, &bytes); + if (fresult != FR_OK) { + if (fresult <= FR_INVALID_PARAMETER) { + errno = FRESULT_to_errno[fresult]; + } + + return EOF; + } + if (bytes != 1) { + return EOF; + } + + return ch; +#else + + return EOF; +#endif + } + else + { + return EOF; + } +} + +int vlibc_getchar(void) +{ +#ifdef CONFIG_VLIBC_FATFS + return EOF; +#else + return EOF; +#endif +} + +char *vlibc_gets(char *str) +{ + CHECK_FILE(str, NULL); +#ifdef CONFIG_VLIBC_FATFS + return NULL; +#else + return NULL; +#endif +} + +int vlibc_putc(int chr, VLIBC_FILE *stream) +{ + CHECK_FILE(stream, EOF); + + IF_IO_DEV(stream) + { + size_t size; + size = vlibc_fwrite(&chr, 1, 1, stream); + if (size == 1) { + return 0; + } else { + return EOF; + } + } + else IF_FILE(stream) + { +#ifdef CONFIG_VLIBC_FATFS + int fresult; + size_t bytes; + fresult = f_write(stream->file, &chr, 1, &bytes); + if (fresult != FR_OK) { + if (fresult <= FR_INVALID_PARAMETER) { + errno = FRESULT_to_errno[fresult]; + } + + return EOF; + } + if (bytes != 1) { + return EOF; + } + + return 0; +#else + + return EOF; +#endif + } + else + { + return EOF; + } +} + +int vlibc_putchar(int chr) +{ + IF_IO_DEV(vlibc_stdout) + { + size_t size; + size = vlibc_fwrite(&chr, 1, 1, vlibc_stdout); + if (size == 1) { + return 0; + } else { + return EOF; + } + } + else IF_FILE(vlibc_stdout) + { +#ifdef CONFIG_VLIBC_FATFS + int fresult; + size_t bytes; + fresult = f_write(vlibc_stdout->file, &chr, 1, &bytes); + if (fresult != FR_OK) { + if (fresult <= FR_INVALID_PARAMETER) { + errno = FRESULT_to_errno[fresult]; + } + + return EOF; + } + if (bytes != 1) { + return EOF; + } + + return 0; +#else + + return EOF; +#endif + } + else + { + return EOF; + } +} + +int vlibc_puts(const char *str) +{ + return vlibc_printf(str); +} + +void vlibc_perror(const char *str) +{ + CHECK_FILE(str, /*!< no return */); +} diff --git a/utils/vlibc/vlibc_stdio.h b/components/utils/vlibc/vlibc_stdio.h similarity index 96% rename from utils/vlibc/vlibc_stdio.h rename to components/utils/vlibc/vlibc_stdio.h index 524983b7..06a1618b 100644 --- a/utils/vlibc/vlibc_stdio.h +++ b/components/utils/vlibc/vlibc_stdio.h @@ -1,170 +1,170 @@ -#ifndef _VLIBC_STDIO_H -#define _VLIBC_STDIO_H - -#include -#include -#include -#include - -#ifdef CONFIG_VLIBC_FATFS -#include "ff.h" -#endif - -/** @addtogroup Types - * @{ - */ - -struct __vlibc_io { - char *bg; /*!< buffer begin pointer */ - char *wp; /*!< buffer write pointer */ - char *rp; /*!< buffer read pointer */ - char *ed; /*!< buffer end pointer */ - - uint32_t dev; /*!< io device */ - uint8_t flag; /*!< io flag */ - uint8_t vbuf; /*!< buffer mode */ - uint8_t abuf; /*!< buffer auto */ - uint8_t err; /*!< error */ -}; - -typedef struct { - uint32_t magic; - - union { - struct __vlibc_io *io; -#ifdef CONFIG_VLIBC_FATFS - FIL *file; -#else - int *file; -#endif - }; -} vlibc_file_t; - -/*!< file type */ -#define VLIBC_FILE vlibc_file_t - -/** - * @} - */ - -/** @addtogroup stdio extra - * @{ - */ -extern uint32_t __vlibc_io_init(const char *name, uint8_t mode); -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_dev2mem(struct __vlibc_io *io, void *ptr, size_t size); -/** - * @} - */ - -/** @addtogroup Marcos - * @{ - */ - -#define _VLIBC_MAGIC_MASK ((unsigned int)(0xffff0000)) -#define _VLIBC_IO_MAGIC_CODE ((unsigned int)(0x10de0000)) -#define _VLIBC_FILE_MAGIC_CODE ((unsigned int)(0xf11e0000)) - -#define _VLIBC_IO_WRITE ((unsigned char)(0x01)) -#define _VLIBC_IO_READ ((unsigned char)(0x02)) - -/*!< io buffer size */ -#define VLIBC_BUFSIZ 256 - -/*!< file stack buffer size */ -#define VLIBC_FBUFSIZ 256 - -/*!< max open file count at the same time */ -#define VLIBC_FOPEN_MAX 20 - -/*!< max file name length */ -#define VLIBC_FILENAME_MAX 256 - -/*!< max io name length */ -#define _VLIBC_IONAME_MAX 32 - -/*!< max tmpnam file name length */ -#define VLIBC_L_tmpnam VLIBC_FILENAME_MAX - -/*!< max tmpnam rand name */ -#define VLIBC_TMP_MAX 0 - -/*!< stand io */ -extern vlibc_file_t *__vlibc_stdio_fileptrs[3]; -#define vlibc_stdin (__vlibc_stdio_fileptrs[0]) -#define vlibc_stdout (__vlibc_stdio_fileptrs[1]) -#define vlibc_stderr (__vlibc_stdio_fileptrs[2]) - -/** - * @} - */ - -/** @addtogroup stdio functions - * @{ - */ - -extern void vlibc_clearerr(VLIBC_FILE *); -extern int vlibc_feof(VLIBC_FILE *); -extern int vlibc_ferror(VLIBC_FILE *); - -extern VLIBC_FILE *vlibc_fopen(const char *, const char *); -extern VLIBC_FILE *vlibc_freopen(const char *, const char *, VLIBC_FILE *); -extern int vlibc_fclose(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 int vlibc_fflush(VLIBC_FILE *); -extern int vlibc_fseek(VLIBC_FILE *, long, int); -extern long vlibc_ftell(VLIBC_FILE *); - -extern int vlibc_remove(const char *); -extern int vlibc_rename(const char *, const char *); -extern void vlibc_rewind(VLIBC_FILE *); - -extern void vlibc_setbuf(VLIBC_FILE *, char *); -extern int vlibc_setvbuf(VLIBC_FILE *, char *, int, size_t); - -extern VLIBC_FILE *vlibc_tmpfile(void); -extern char *vlibc_tmpnam(char *); - -extern int vlibc_fprintf(VLIBC_FILE *, const char *, ...); -extern int vlibc_printf(const char *, ...); -extern int vlibc_sprintf(char *, const char *, ...); -extern int vlibc_snprintf(char *, size_t, const char *, ...); - -extern int vlibc_vfprintf(VLIBC_FILE *, const char *, va_list); -extern int vlibc_vprintf(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_fscanf(VLIBC_FILE *, const char *, ...); -extern int vlibc_scanf(const char *, ...); -extern int vlibc_sscanf(const char *, const char *, ...); - -extern int vlibc_vfscanf(VLIBC_FILE *, 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_fgetc(VLIBC_FILE *); -extern char *vlibc_fgets(char *, int, VLIBC_FILE *); - -extern int vlibc_fputc(int, VLIBC_FILE *); -extern int vlibc_fputs(const char *, VLIBC_FILE *); - -extern int vlibc_getc(VLIBC_FILE *); -extern int vlibc_getchar(void); -extern char *vlibc_gets(char *); - -extern int vlibc_putc(int, VLIBC_FILE *); -extern int vlibc_putchar(int); -extern int vlibc_puts(const char *); - -extern void vlibc_perror(const char *); - -/** - * @} - */ - -#endif +#ifndef _VLIBC_STDIO_H +#define _VLIBC_STDIO_H + +#include +#include +#include +#include + +#ifdef CONFIG_VLIBC_FATFS +#include "ff.h" +#endif + +/** @addtogroup Types + * @{ + */ + +struct __vlibc_io { + char *bg; /*!< buffer begin pointer */ + char *wp; /*!< buffer write pointer */ + char *rp; /*!< buffer read pointer */ + char *ed; /*!< buffer end pointer */ + + uint32_t dev; /*!< io device */ + uint8_t flag; /*!< io flag */ + uint8_t vbuf; /*!< buffer mode */ + uint8_t abuf; /*!< buffer auto */ + uint8_t err; /*!< error */ +}; + +typedef struct { + uint32_t magic; + + union { + struct __vlibc_io *io; +#ifdef CONFIG_VLIBC_FATFS + FIL *file; +#else + int *file; +#endif + }; +} vlibc_file_t; + +/*!< file type */ +#define VLIBC_FILE vlibc_file_t + +/** + * @} + */ + +/** @addtogroup stdio extra + * @{ + */ +extern uint32_t __vlibc_io_init(const char *name, uint8_t mode); +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_dev2mem(struct __vlibc_io *io, void *ptr, size_t size); +/** + * @} + */ + +/** @addtogroup Marcos + * @{ + */ + +#define _VLIBC_MAGIC_MASK ((unsigned int)(0xffff0000)) +#define _VLIBC_IO_MAGIC_CODE ((unsigned int)(0x10de0000)) +#define _VLIBC_FILE_MAGIC_CODE ((unsigned int)(0xf11e0000)) + +#define _VLIBC_IO_WRITE ((unsigned char)(0x01)) +#define _VLIBC_IO_READ ((unsigned char)(0x02)) + +/*!< io buffer size */ +#define VLIBC_BUFSIZ 256 + +/*!< file stack buffer size */ +#define VLIBC_FBUFSIZ 256 + +/*!< max open file count at the same time */ +#define VLIBC_FOPEN_MAX 20 + +/*!< max file name length */ +#define VLIBC_FILENAME_MAX 256 + +/*!< max io name length */ +#define _VLIBC_IONAME_MAX 32 + +/*!< max tmpnam file name length */ +#define VLIBC_L_tmpnam VLIBC_FILENAME_MAX + +/*!< max tmpnam rand name */ +#define VLIBC_TMP_MAX 0 + +/*!< stand io */ +extern vlibc_file_t *__vlibc_stdio_fileptrs[3]; +#define vlibc_stdin (__vlibc_stdio_fileptrs[0]) +#define vlibc_stdout (__vlibc_stdio_fileptrs[1]) +#define vlibc_stderr (__vlibc_stdio_fileptrs[2]) + +/** + * @} + */ + +/** @addtogroup stdio functions + * @{ + */ + +extern void vlibc_clearerr(VLIBC_FILE *); +extern int vlibc_feof(VLIBC_FILE *); +extern int vlibc_ferror(VLIBC_FILE *); + +extern VLIBC_FILE *vlibc_fopen(const char *, const char *); +extern VLIBC_FILE *vlibc_freopen(const char *, const char *, VLIBC_FILE *); +extern int vlibc_fclose(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 int vlibc_fflush(VLIBC_FILE *); +extern int vlibc_fseek(VLIBC_FILE *, long, int); +extern long vlibc_ftell(VLIBC_FILE *); + +extern int vlibc_remove(const char *); +extern int vlibc_rename(const char *, const char *); +extern void vlibc_rewind(VLIBC_FILE *); + +extern void vlibc_setbuf(VLIBC_FILE *, char *); +extern int vlibc_setvbuf(VLIBC_FILE *, char *, int, size_t); + +extern VLIBC_FILE *vlibc_tmpfile(void); +extern char *vlibc_tmpnam(char *); + +extern int vlibc_fprintf(VLIBC_FILE *, const char *, ...); +extern int vlibc_printf(const char *, ...); +extern int vlibc_sprintf(char *, const char *, ...); +extern int vlibc_snprintf(char *, size_t, const char *, ...); + +extern int vlibc_vfprintf(VLIBC_FILE *, const char *, va_list); +extern int vlibc_vprintf(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_fscanf(VLIBC_FILE *, const char *, ...); +extern int vlibc_scanf(const char *, ...); +extern int vlibc_sscanf(const char *, const char *, ...); + +extern int vlibc_vfscanf(VLIBC_FILE *, 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_fgetc(VLIBC_FILE *); +extern char *vlibc_fgets(char *, int, VLIBC_FILE *); + +extern int vlibc_fputc(int, VLIBC_FILE *); +extern int vlibc_fputs(const char *, VLIBC_FILE *); + +extern int vlibc_getc(VLIBC_FILE *); +extern int vlibc_getchar(void); +extern char *vlibc_gets(char *); + +extern int vlibc_putc(int, VLIBC_FILE *); +extern int vlibc_putchar(int); +extern int vlibc_puts(const char *); + +extern void vlibc_perror(const char *); + +/** + * @} + */ + +#endif diff --git a/utils/vlibc/vlibc_vsnprintf.c b/components/utils/vlibc/vlibc_vsnprintf.c similarity index 100% rename from utils/vlibc/vlibc_vsnprintf.c rename to components/utils/vlibc/vlibc_vsnprintf.c diff --git a/drivers/CMakeLists.txt b/drivers/CMakeLists.txt deleted file mode 100644 index 14e930bf..00000000 --- a/drivers/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -add_subdirectory(lhal) -add_subdirectory(soc/${CHIP}) \ No newline at end of file