From a9910a780edc43df6b64bcd13c37785a15ec3428 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Tue, 26 Oct 2021 00:51:32 -0400 Subject: [posix][libc] 优化libc中posix结构 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/common/SConscript | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components/libc/compilers/common/SConscript') diff --git a/components/libc/compilers/common/SConscript b/components/libc/compilers/common/SConscript index b7a6626a36..1c1d645564 100644 --- a/components/libc/compilers/common/SConscript +++ b/components/libc/compilers/common/SConscript @@ -11,7 +11,7 @@ CPPDEFINES = [] if GetDepend('RT_USING_LIBC'): src += Glob('*.c') elif GetDepend('RT_LIBC_USING_TIME'): - src += Glob('time.c') + src += ['time.c'] if rtconfig.CROSS_TOOL == 'keil': CPPDEFINES += ['__CLK_TCK=RT_TICK_PER_SECOND'] -- cgit v1.3.1 From 7b43cf9793025b0bbb9b2c3bbeedb788edb04f7c Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Thu, 28 Oct 2021 02:48:51 -0400 Subject: [libc][posix] move libc.c/.h to posix folder --- components/libc/compilers/armlibc/SConscript | 10 +- components/libc/compilers/armlibc/libc.c | 35 ------ components/libc/compilers/armlibc/libc.h | 29 ----- components/libc/compilers/armlibc/stdio.c | 52 --------- components/libc/compilers/armlibc/syscalls.c | 9 +- components/libc/compilers/common/SConscript | 6 +- components/libc/compilers/dlib/SConscript | 7 +- components/libc/compilers/dlib/libc.c | 35 ------ components/libc/compilers/dlib/libc.h | 28 ----- components/libc/compilers/dlib/stdio.c | 49 -------- components/libc/compilers/dlib/syscall_read.c | 2 + components/libc/compilers/dlib/syscall_write.c | 2 + components/libc/compilers/gcc/newlib/SConscript | 11 +- components/libc/compilers/gcc/newlib/libc.c | 39 ------- components/libc/compilers/gcc/newlib/libc.h | 29 ----- components/libc/compilers/gcc/newlib/stdio.c | 91 --------------- components/libc/compilers/gcc/newlib/syscalls.c | 2 + components/libc/posix/src/SConscript | 5 +- components/libc/posix/src/libc.c | 148 ++++++++++++++++++++++++ components/libc/posix/src/libc.h | 29 +++++ 20 files changed, 199 insertions(+), 419 deletions(-) delete mode 100644 components/libc/compilers/armlibc/libc.c delete mode 100644 components/libc/compilers/armlibc/libc.h delete mode 100644 components/libc/compilers/armlibc/stdio.c delete mode 100644 components/libc/compilers/dlib/libc.c delete mode 100644 components/libc/compilers/dlib/libc.h delete mode 100644 components/libc/compilers/dlib/stdio.c delete mode 100644 components/libc/compilers/gcc/newlib/libc.c delete mode 100644 components/libc/compilers/gcc/newlib/libc.h delete mode 100644 components/libc/compilers/gcc/newlib/stdio.c create mode 100644 components/libc/posix/src/libc.c create mode 100644 components/libc/posix/src/libc.h (limited to 'components/libc/compilers/common/SConscript') diff --git a/components/libc/compilers/armlibc/SConscript b/components/libc/compilers/armlibc/SConscript index d77a7c69d5..bf1a299304 100644 --- a/components/libc/compilers/armlibc/SConscript +++ b/components/libc/compilers/armlibc/SConscript @@ -1,18 +1,12 @@ from building import * Import('rtconfig') -src = Glob('*.c') + Glob('*.cpp') -cwd = GetCurrentDir() +src = Glob('*.c') group = [] -CPPPATH = [cwd] CPPDEFINES = ['RT_USING_ARM_LIBC'] -if GetDepend('RT_USING_MODULE') == False: - SrcRemove(src, ['libc_syms.c']) - if rtconfig.PLATFORM == 'armcc' or rtconfig.PLATFORM == 'armclang': - group = DefineGroup('libc', src, depend = ['RT_USING_LIBC'], - CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES) + group = DefineGroup('libc', src, depend = ['RT_USING_LIBC'], CPPDEFINES = CPPDEFINES) Return('group') diff --git a/components/libc/compilers/armlibc/libc.c b/components/libc/compilers/armlibc/libc.c deleted file mode 100644 index bc09759fef..0000000000 --- a/components/libc/compilers/armlibc/libc.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2017/10/15 bernard the first version - */ -#include -#include -#include "libc.h" -#ifdef RT_USING_PTHREADS -#include -#endif - -int libc_system_init(void) -{ -#ifdef RT_USING_POSIX - rt_device_t dev_console; - - dev_console = rt_console_get_device(); - if (dev_console) - { - libc_stdio_set_console(dev_console->parent.name, O_RDWR); - } -#endif /* RT_USING_POSIX */ - -#if defined RT_USING_PTHREADS && !defined RT_USING_COMPONENTS_INIT - pthread_system_init(); -#endif - - return 0; -} -INIT_COMPONENT_EXPORT(libc_system_init); diff --git a/components/libc/compilers/armlibc/libc.h b/components/libc/compilers/armlibc/libc.h deleted file mode 100644 index f81380bf78..0000000000 --- a/components/libc/compilers/armlibc/libc.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2017/10/15 bernard the first version - */ -#ifndef __RTT_LIBC_H__ -#define __RTT_LIBC_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -int libc_system_init(void); -#ifdef RT_USING_POSIX -int libc_stdio_get_console(void); -int libc_stdio_set_console(const char* device_name, int mode); -#endif /* RT_USING_POSIX */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/components/libc/compilers/armlibc/stdio.c b/components/libc/compilers/armlibc/stdio.c deleted file mode 100644 index e5db167ea4..0000000000 --- a/components/libc/compilers/armlibc/stdio.c +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2017/10/15 bernard implement stdio for armcc. - */ -#include - -#ifdef RT_USING_POSIX -#include -#include -#include - -#include "libc.h" - -#include -#include - -#define STDIO_DEVICE_NAME_MAX 32 - -static int std_fd = -1; - -int libc_stdio_set_console(const char* device_name, int mode) -{ - int fd; - char name[STDIO_DEVICE_NAME_MAX]; - - snprintf(name, sizeof(name) - 1, "/dev/%s", device_name); - name[STDIO_DEVICE_NAME_MAX - 1] = '\0'; - - fd = open(name, mode, 0); - if (fd >= 0) - { - if (std_fd >= 0) - { - close(std_fd); - } - std_fd = fd; - } - - return std_fd; -} - -int libc_stdio_get_console(void) -{ - return std_fd; -} - -#endif /* RT_USING_POSIX */ diff --git a/components/libc/compilers/armlibc/syscalls.c b/components/libc/compilers/armlibc/syscalls.c index 3b40a5b7b5..755ffef1a6 100644 --- a/components/libc/compilers/armlibc/syscalls.c +++ b/components/libc/compilers/armlibc/syscalls.c @@ -14,15 +14,16 @@ * 2020-02-13 Meco Man re-implement exit() and abort() * 2020-02-14 Meco Man implement _sys_tmpnam() */ -#include -#include +#include #include -#include "libc.h" - +#include #include #include #include +#ifdef RT_USING_POSIX +#include "libc.h" +#endif #define DBG_TAG "armlibc.syscalls" #define DBG_LVL DBG_INFO diff --git a/components/libc/compilers/common/SConscript b/components/libc/compilers/common/SConscript index 1c1d645564..bd66b70c7e 100644 --- a/components/libc/compilers/common/SConscript +++ b/components/libc/compilers/common/SConscript @@ -8,14 +8,14 @@ group = [] CPPPATH = [cwd] CPPDEFINES = [] +if rtconfig.CROSS_TOOL == 'keil': + CPPDEFINES += ['__CLK_TCK=RT_TICK_PER_SECOND'] + if GetDepend('RT_USING_LIBC'): src += Glob('*.c') elif GetDepend('RT_LIBC_USING_TIME'): src += ['time.c'] -if rtconfig.CROSS_TOOL == 'keil': - CPPDEFINES += ['__CLK_TCK=RT_TICK_PER_SECOND'] - group = DefineGroup('libc', src, depend = [], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES) list = os.listdir(cwd) diff --git a/components/libc/compilers/dlib/SConscript b/components/libc/compilers/dlib/SConscript index 348cbf311f..39707abc61 100644 --- a/components/libc/compilers/dlib/SConscript +++ b/components/libc/compilers/dlib/SConscript @@ -1,25 +1,20 @@ from building import * - Import('rtconfig') src = Glob('*.c') -cwd = GetCurrentDir() group = [] -CPPPATH = [cwd] CPPDEFINES = ['RT_USING_DLIBC'] if rtconfig.PLATFORM == 'iar': - if GetDepend('RT_USING_POSIX'): from distutils.version import LooseVersion from iar import IARVersion CPPDEFINES = CPPDEFINES + ['_DLIB_FILE_DESCRIPTOR'] - if LooseVersion(IARVersion()) < LooseVersion("8.20.1"): CPPDEFINES = CPPDEFINES + ['_DLIB_THREAD_SUPPORT'] - group = DefineGroup('libc', src, depend = ['RT_USING_LIBC'], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES) + group = DefineGroup('libc', src, depend = ['RT_USING_LIBC'], CPPDEFINES = CPPDEFINES) Return('group') diff --git a/components/libc/compilers/dlib/libc.c b/components/libc/compilers/dlib/libc.c deleted file mode 100644 index f6e504bdae..0000000000 --- a/components/libc/compilers/dlib/libc.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2017/10/15 bernard the first version - */ -#include -#include -#include "libc.h" -#ifdef RT_USING_PTHREADS -#include -#endif - -int libc_system_init(void) -{ -#ifdef RT_USING_POSIX - rt_device_t dev_console; - - dev_console = rt_console_get_device(); - if (dev_console) - { - libc_stdio_set_console(dev_console->parent.name, O_RDWR); - } -#endif /* RT_USING_POSIX */ - -#if defined (RT_USING_PTHREADS) && !defined (RT_USING_COMPONENTS_INIT) - pthread_system_init(); -#endif - - return 0; -} -INIT_COMPONENT_EXPORT(libc_system_init); diff --git a/components/libc/compilers/dlib/libc.h b/components/libc/compilers/dlib/libc.h deleted file mode 100644 index 292dbde973..0000000000 --- a/components/libc/compilers/dlib/libc.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2017/10/15 bernard the first version - */ - -#ifndef __RTT_LIBC_H__ -#define __RTT_LIBC_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -int libc_system_init(void); -#ifdef RT_USING_POSIX -int libc_stdio_get_console(void); -int libc_stdio_set_console(const char* device_name, int mode); -#endif /* RT_USING_POSIX */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/components/libc/compilers/dlib/stdio.c b/components/libc/compilers/dlib/stdio.c deleted file mode 100644 index fea98aedd5..0000000000 --- a/components/libc/compilers/dlib/stdio.c +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2017/10/15 bernard implement stdio for IAR dlib. - */ -#include - -#ifdef RT_USING_POSIX - -#include -#include -#include -#include -#include -#include "libc.h" - -#define STDIO_DEVICE_NAME_MAX 32 - -static int std_fd = -1; -int libc_stdio_set_console(const char* device_name, int mode) -{ - int fd; - char name[STDIO_DEVICE_NAME_MAX]; - - snprintf(name, sizeof(name) - 1, "/dev/%s", device_name); - name[STDIO_DEVICE_NAME_MAX - 1] = '\0'; - - fd = open(name, mode, 0); - if (fd >= 0) - { - if (std_fd >= 0) - { - close(std_fd); - } - std_fd = fd; - } - - return std_fd; -} - -int libc_stdio_get_console(void) { - return std_fd; -} - -#endif /* RT_USING_POSIX */ diff --git a/components/libc/compilers/dlib/syscall_read.c b/components/libc/compilers/dlib/syscall_read.c index 447ca03112..74cedb966a 100644 --- a/components/libc/compilers/dlib/syscall_read.c +++ b/components/libc/compilers/dlib/syscall_read.c @@ -11,7 +11,9 @@ #include #include #include +#ifdef RT_USING_POSIX #include "libc.h" +#endif #define DBG_TAG "dlib.syscall_read" #define DBG_LVL DBG_INFO diff --git a/components/libc/compilers/dlib/syscall_write.c b/components/libc/compilers/dlib/syscall_write.c index ae2d4a1559..ab011c1096 100644 --- a/components/libc/compilers/dlib/syscall_write.c +++ b/components/libc/compilers/dlib/syscall_write.c @@ -11,7 +11,9 @@ #include #include #include +#ifdef RT_USING_POSIX #include "libc.h" +#endif #define DBG_TAG "dlib.syscall_write" #define DBG_LVL DBG_INFO diff --git a/components/libc/compilers/gcc/newlib/SConscript b/components/libc/compilers/gcc/newlib/SConscript index e0ee482747..ae50098dec 100644 --- a/components/libc/compilers/gcc/newlib/SConscript +++ b/components/libc/compilers/gcc/newlib/SConscript @@ -4,21 +4,14 @@ Import('rtconfig') src = [] cwd = GetCurrentDir() group = [] -LIBS = ['m'] +LIBS = ['m'] # link libm CPPDEFINES = ['RT_USING_NEWLIB'] CPPPATH = [cwd] if rtconfig.PLATFORM == 'gcc': if GetDepend('RT_USING_LIBC'): - # link with libc and libm: - # libm is a frequently used lib. Newlib is compiled with -ffunction-sections in - # recent GCC tool chains. The linker would just link in the functions that have - # been referenced. So setting this won't result in bigger text size. - LIBS += ['c'] - + LIBS += ['c'] # link libc src += Glob('*.c') - if GetDepend('RT_USING_MODULE') == False: - SrcRemove(src, ['libc_syms.c']) else: src += ['syscalls.c'] diff --git a/components/libc/compilers/gcc/newlib/libc.c b/components/libc/compilers/gcc/newlib/libc.c deleted file mode 100644 index 86af026429..0000000000 --- a/components/libc/compilers/gcc/newlib/libc.c +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2017/10/15 bernard the first version - */ -#include -#include -#include -#include -#include -#include "libc.h" - -#ifdef RT_USING_PTHREADS -#include -#endif - -int libc_system_init(void) -{ -#ifdef RT_USING_POSIX - rt_device_t dev_console; - - dev_console = rt_console_get_device(); - if (dev_console) - { - libc_stdio_set_console(dev_console->parent.name, O_RDWR); - } -#endif /* RT_USING_POSIX */ - -#if defined RT_USING_PTHREADS && !defined RT_USING_COMPONENTS_INIT - pthread_system_init(); -#endif - - return 0; -} -INIT_COMPONENT_EXPORT(libc_system_init); diff --git a/components/libc/compilers/gcc/newlib/libc.h b/components/libc/compilers/gcc/newlib/libc.h deleted file mode 100644 index 2ea27b09f9..0000000000 --- a/components/libc/compilers/gcc/newlib/libc.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2017/10/15 bernard the first version - */ -#ifndef __RTT_LIBC_H__ -#define __RTT_LIBC_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -int libc_system_init(void); - -#ifdef RT_USING_POSIX -int libc_stdio_get_console(void); -int libc_stdio_set_console(const char* device_name, int mode); -#endif /* RT_USING_POSIX */ - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/components/libc/compilers/gcc/newlib/stdio.c b/components/libc/compilers/gcc/newlib/stdio.c deleted file mode 100644 index e6ebc8c303..0000000000 --- a/components/libc/compilers/gcc/newlib/stdio.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2017/10/15 bernard the first version - */ -#include -#ifdef RT_USING_POSIX -#include -#include -#include -#include "libc.h" - -#define STDIO_DEVICE_NAME_MAX 32 -static FILE* std_console = NULL; - -int libc_stdio_set_console(const char* device_name, int mode) -{ - FILE *fp; - char name[STDIO_DEVICE_NAME_MAX]; - char *file_mode; - - snprintf(name, sizeof(name) - 1, "/dev/%s", device_name); - name[STDIO_DEVICE_NAME_MAX - 1] = '\0'; - - if (mode == O_RDWR) - { - file_mode = "r+"; - } - else if (mode == O_WRONLY) - { - file_mode = "wb"; - } - else - { - file_mode = "rb"; - } - - fp = fopen(name, file_mode); - if (fp) - { - setvbuf(fp, NULL, _IONBF, 0); - - if (std_console) - { - fclose(std_console); - std_console = NULL; - } - std_console = fp; - - if (mode == O_RDWR) - { - _GLOBAL_REENT->_stdin = std_console; - } - else - { - _GLOBAL_REENT->_stdin = NULL; - } - - if (mode == O_RDONLY) - { - _GLOBAL_REENT->_stdout = NULL; - _GLOBAL_REENT->_stderr = NULL; - } - else - { - _GLOBAL_REENT->_stdout = std_console; - _GLOBAL_REENT->_stderr = std_console; - } - - _GLOBAL_REENT->__sdidinit = 1; - } - - if (std_console) - return fileno(std_console); - - return -1; -} - -int libc_stdio_get_console(void) -{ - if (std_console) - return fileno(std_console); - else - return -1; -} - -#endif /* RT_USING_POSIX */ diff --git a/components/libc/compilers/gcc/newlib/syscalls.c b/components/libc/compilers/gcc/newlib/syscalls.c index 9e9df3f625..f95e695a85 100644 --- a/components/libc/compilers/gcc/newlib/syscalls.c +++ b/components/libc/compilers/gcc/newlib/syscalls.c @@ -20,7 +20,9 @@ #include #include #include +#ifdef RT_USING_POSIX #include "libc.h" +#endif #ifdef RT_USING_MODULE #include #endif diff --git a/components/libc/posix/src/SConscript b/components/libc/posix/src/SConscript index 5640181ac5..8712d671c0 100644 --- a/components/libc/posix/src/SConscript +++ b/components/libc/posix/src/SConscript @@ -2,9 +2,10 @@ from building import * -cwd = GetCurrentDir() src = Glob('*.c') +cwd = GetCurrentDir() +CPPPATH = [cwd] -group = DefineGroup('POSIX', src, depend = ['RT_USING_POSIX']) +group = DefineGroup('POSIX', src, depend = ['RT_USING_POSIX'], CPPPATH = CPPPATH) Return('group') diff --git a/components/libc/posix/src/libc.c b/components/libc/posix/src/libc.c new file mode 100644 index 0000000000..84c5a601bc --- /dev/null +++ b/components/libc/posix/src/libc.c @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2017/10/15 bernard the first version + */ +#include +#include +#include +#include +#include +#include +#include +#include "libc.h" +#include +#include +#ifdef RT_USING_PTHREADS +#include +#endif + +int libc_system_init(void) +{ +#ifdef RT_USING_POSIX + rt_device_t dev_console; + + dev_console = rt_console_get_device(); + if (dev_console) + { + libc_stdio_set_console(dev_console->parent.name, O_RDWR); + } +#endif /* RT_USING_POSIX */ + +#if defined RT_USING_PTHREADS && !defined RT_USING_COMPONENTS_INIT + pthread_system_init(); +#endif + + return 0; +} +INIT_COMPONENT_EXPORT(libc_system_init); + +#ifdef RT_USING_POSIX + +#if defined(RT_USING_LIBC) && defined(RT_USING_NEWLIB) +#define STDIO_DEVICE_NAME_MAX 32 +static FILE* std_console = NULL; +int libc_stdio_set_console(const char* device_name, int mode) +{ + FILE *fp; + char name[STDIO_DEVICE_NAME_MAX]; + char *file_mode; + + snprintf(name, sizeof(name) - 1, "/dev/%s", device_name); + name[STDIO_DEVICE_NAME_MAX - 1] = '\0'; + + if (mode == O_RDWR) + { + file_mode = "r+"; + } + else if (mode == O_WRONLY) + { + file_mode = "wb"; + } + else + { + file_mode = "rb"; + } + + fp = fopen(name, file_mode); + if (fp) + { + setvbuf(fp, NULL, _IONBF, 0); + + if (std_console) + { + fclose(std_console); + std_console = NULL; + } + std_console = fp; + + if (mode == O_RDWR) + { + _GLOBAL_REENT->_stdin = std_console; + } + else + { + _GLOBAL_REENT->_stdin = NULL; + } + + if (mode == O_RDONLY) + { + _GLOBAL_REENT->_stdout = NULL; + _GLOBAL_REENT->_stderr = NULL; + } + else + { + _GLOBAL_REENT->_stdout = std_console; + _GLOBAL_REENT->_stderr = std_console; + } + + _GLOBAL_REENT->__sdidinit = 1; + } + + if (std_console) + return fileno(std_console); + + return -1; +} + +int libc_stdio_get_console(void) +{ + if (std_console) + return fileno(std_console); + else + return -1; +} + +#else +#define STDIO_DEVICE_NAME_MAX 32 +static int std_fd = -1; +int libc_stdio_set_console(const char* device_name, int mode) +{ + int fd; + char name[STDIO_DEVICE_NAME_MAX]; + + snprintf(name, sizeof(name) - 1, "/dev/%s", device_name); + name[STDIO_DEVICE_NAME_MAX - 1] = '\0'; + + fd = open(name, mode, 0); + if (fd >= 0) + { + if (std_fd >= 0) + { + close(std_fd); + } + std_fd = fd; + } + + return std_fd; +} + +int libc_stdio_get_console(void) { + return std_fd; +} +#endif /* defined(RT_USING_LIBC) && (defined(__GNUC__) && !defined(__ARMCC_VERSION)) */ +#endif /* RT_USING_POSIX */ diff --git a/components/libc/posix/src/libc.h b/components/libc/posix/src/libc.h new file mode 100644 index 0000000000..f81380bf78 --- /dev/null +++ b/components/libc/posix/src/libc.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2017/10/15 bernard the first version + */ +#ifndef __RTT_LIBC_H__ +#define __RTT_LIBC_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +int libc_system_init(void); +#ifdef RT_USING_POSIX +int libc_stdio_get_console(void); +int libc_stdio_set_console(const char* device_name, int mode); +#endif /* RT_USING_POSIX */ + +#ifdef __cplusplus +} +#endif + +#endif -- cgit v1.3.1 From 3c232125db049a42b97287e4eb44ea0664e7538c Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Thu, 28 Oct 2021 14:23:07 -0400 Subject: [bsp][simulator] update project --- bsp/simulator/.config | 77 ++++++++--------------------- bsp/simulator/applications/platform.c | 4 -- bsp/simulator/drivers/board.c | 5 -- bsp/simulator/rtconfig.h | 48 ++---------------- bsp/simulator/rtconfig.py | 2 +- components/libc/compilers/common/SConscript | 1 - components/libc/posix/src/SConscript | 6 ++- components/libc/posix/src/libc.c | 2 +- 8 files changed, 30 insertions(+), 115 deletions(-) (limited to 'components/libc/compilers/common/SConscript') diff --git a/bsp/simulator/.config b/bsp/simulator/.config index f47a218d77..3b6f7f3494 100644 --- a/bsp/simulator/.config +++ b/bsp/simulator/.config @@ -1,9 +1,13 @@ -# Generated by Kconfiglib (https://github.com/ulfalizer/Kconfiglib) +# +# Automatically generated file; DO NOT EDIT. +# RT-Thread Configuration +# # # RT-Thread Kernel # CONFIG_RT_NAME_MAX=8 +# CONFIG_RT_USING_BIG_ENDIAN is not set # CONFIG_RT_USING_ARCH_DATA_TYPE is not set # CONFIG_RT_USING_SMP is not set CONFIG_RT_ALIGN_SIZE=4 @@ -24,8 +28,7 @@ CONFIG_IDLE_THREAD_STACK_SIZE=256 # # CONFIG_RT_KSERVICE_USING_STDLIB is not set # CONFIG_RT_KSERVICE_USING_TINY_SIZE is not set -# end of kservice optimization - +# CONFIG_RT_USING_ASM_MEMCPY is not set CONFIG_RT_DEBUG=y CONFIG_RT_DEBUG_COLOR=y # CONFIG_RT_DEBUG_INIT_CONFIG is not set @@ -48,7 +51,6 @@ CONFIG_RT_USING_EVENT=y CONFIG_RT_USING_MAILBOX=y CONFIG_RT_USING_MESSAGEQUEUE=y # CONFIG_RT_USING_SIGNALS is not set -# end of Inter-Thread communication # # Memory Management @@ -61,7 +63,6 @@ CONFIG_RT_USING_SMALL_MEM=y # CONFIG_RT_USING_USERHEAP is not set # CONFIG_RT_USING_MEMTRACE is not set CONFIG_RT_USING_HEAP=y -# end of Memory Management # # Kernel Device Object @@ -73,10 +74,9 @@ CONFIG_RT_USING_CONSOLE=y CONFIG_RT_CONSOLEBUF_SIZE=128 CONFIG_RT_CONSOLE_DEVICE_NAME="console" # CONFIG_RT_PRINTF_LONGLONG is not set -# end of Kernel Device Object - CONFIG_RT_VER_NUM=0x40004 -# end of RT-Thread Kernel +# CONFIG_RT_USING_CPU_FFS is not set +# CONFIG_ARCH_CPU_STACK_GROWS_UPWARD is not set # # RT-Thread Components @@ -90,7 +90,6 @@ CONFIG_RT_MAIN_THREAD_PRIORITY=10 # C++ features # # CONFIG_RT_USING_CPLUSPLUS is not set -# end of C++ features # # Command shell @@ -110,7 +109,6 @@ CONFIG_FINSH_USING_DESCRIPTION=y # CONFIG_FINSH_ECHO_DISABLE_DEFAULT is not set # CONFIG_FINSH_USING_AUTH is not set CONFIG_FINSH_ARG_MAX=10 -# end of Command shell # # Device virtual file system @@ -144,12 +142,9 @@ CONFIG_RT_DFS_ELM_MAX_SECTOR_SIZE=512 # CONFIG_RT_DFS_ELM_USE_ERASE is not set CONFIG_RT_DFS_ELM_REENTRANT=y CONFIG_RT_DFS_ELM_MUTEX_TIMEOUT=3000 -# end of elm-chan's FatFs, Generic FAT Filesystem Module - CONFIG_RT_USING_DFS_DEVFS=y # CONFIG_RT_USING_DFS_ROMFS is not set # CONFIG_RT_USING_DFS_RAMFS is not set -# end of Device virtual file system # # Device Drivers @@ -189,19 +184,22 @@ CONFIG_RT_SERIAL_RB_BUFSZ=64 # # Using USB # +# CONFIG_RT_USING_USB is not set # CONFIG_RT_USING_USB_HOST is not set # CONFIG_RT_USING_USB_DEVICE is not set -# end of Using USB -# end of Device Drivers # # POSIX layer and C standard library # # CONFIG_RT_USING_LIBC is not set -# CONFIG_RT_USING_PTHREADS is not set CONFIG_RT_LIBC_USING_TIME=y CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 -# end of POSIX layer and C standard library +# CONFIG_RT_USING_PTHREADS is not set +CONFIG_RT_USING_POSIX=y +# CONFIG_RT_USING_POSIX_MMAP is not set +# CONFIG_RT_USING_POSIX_TERMIOS is not set +# CONFIG_RT_USING_POSIX_GETLINE is not set +# CONFIG_RT_USING_POSIX_AIO is not set # # Network @@ -211,32 +209,26 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 # Socket abstraction layer # # CONFIG_RT_USING_SAL is not set -# end of Socket abstraction layer # # Network interface device # # CONFIG_RT_USING_NETDEV is not set -# end of Network interface device # # light weight TCP/IP stack # # CONFIG_RT_USING_LWIP is not set -# end of light weight TCP/IP stack # # AT commands # # CONFIG_RT_USING_AT is not set -# end of AT commands -# end of Network # # VBUS(Virtual Software BUS) # # CONFIG_RT_USING_VBUS is not set -# end of VBUS(Virtual Software BUS) # # Utilities @@ -246,14 +238,11 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 # CONFIG_RT_USING_UTEST is not set # CONFIG_RT_USING_VAR_EXPORT is not set # CONFIG_RT_USING_RT_LINK is not set -# end of Utilities -# end of RT-Thread Components # # RT-Thread Utestcases # # CONFIG_RT_USING_UTESTCASES is not set -# end of RT-Thread Utestcases # # RT-Thread online packages @@ -288,17 +277,12 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 # Marvell WiFi # # CONFIG_PKG_USING_WLANMARVELL is not set -# end of Marvell WiFi # # Wiced WiFi # # CONFIG_PKG_USING_WLAN_WICED is not set -# end of Wiced WiFi - # CONFIG_PKG_USING_RW007 is not set -# end of Wi-Fi - # CONFIG_PKG_USING_COAP is not set # CONFIG_PKG_USING_NOPOLL is not set # CONFIG_PKG_USING_NETUTILS is not set @@ -320,8 +304,6 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 # CONFIG_PKG_USING_JIOT-C-SDK is not set # CONFIG_PKG_USING_UCLOUD_IOT_SDK is not set # CONFIG_PKG_USING_JOYLINK is not set -# end of IoT Cloud - # CONFIG_PKG_USING_NIMBLE is not set # CONFIG_PKG_USING_OTA_DOWNLOADER is not set # CONFIG_PKG_USING_IPMSG is not set @@ -355,7 +337,6 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 # CONFIG_PKG_USING_LORA_GW_DRIVER_LIB is not set # CONFIG_PKG_USING_LORA_PKT_SNIFFER is not set # CONFIG_PKG_USING_HM is not set -# end of IoT - internet of things # # security packages @@ -365,7 +346,6 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 # CONFIG_PKG_USING_TINYCRYPT is not set # CONFIG_PKG_USING_TFM is not set # CONFIG_PKG_USING_YD_CRYPTO is not set -# end of security packages # # language packages @@ -374,22 +354,19 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 # CONFIG_PKG_USING_JERRYSCRIPT is not set # CONFIG_PKG_USING_MICROPYTHON is not set # CONFIG_PKG_USING_PIKASCRIPT is not set -# end of language packages # # multimedia packages # -# CONFIG_PKG_USING_OPENMV is not set -# CONFIG_PKG_USING_MUPDF is not set -# CONFIG_PKG_USING_STEMWIN is not set # -# lvgl: powerful and easy-to-use embedded GUI library +# LVGL: powerful and easy-to-use embedded GUI library # # CONFIG_PKG_USING_LITTLEVGL2RTT is not set # CONFIG_PKG_USING_LVGL is not set -# end of lvgl: powerful and easy-to-use embedded GUI library - +# CONFIG_PKG_USING_OPENMV is not set +# CONFIG_PKG_USING_MUPDF is not set +# CONFIG_PKG_USING_STEMWIN is not set # CONFIG_PKG_USING_WAVPLAYER is not set # CONFIG_PKG_USING_TJPGD is not set # CONFIG_PKG_USING_PDFGEN is not set @@ -406,8 +383,6 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 # # CONFIG_PKG_USING_U8G2_OFFICIAL is not set # CONFIG_PKG_USING_U8G2 is not set -# end of u8g2: a monochrome graphic library -# end of multimedia packages # # tools packages @@ -450,7 +425,6 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 # CONFIG_PKG_USING_MEM_SANDBOX is not set # CONFIG_PKG_USING_SOLAR_TERMS is not set # CONFIG_PKG_USING_GAN_ZHI is not set -# end of tools packages # # system packages @@ -463,7 +437,6 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 # CONFIG_PKG_USING_QFPLIB_M0_FULL is not set # CONFIG_PKG_USING_QFPLIB_M0_TINY is not set # CONFIG_PKG_USING_QFPLIB_M3 is not set -# end of acceleration: Assembly language or algorithmic acceleration packages # # Micrium: Micrium software products porting for RT-Thread @@ -474,8 +447,6 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 # CONFIG_PKG_USING_UC_CLK is not set # CONFIG_PKG_USING_UC_COMMON is not set # CONFIG_PKG_USING_UC_MODBUS is not set -# end of Micrium: Micrium software products porting for RT-Thread - # CONFIG_PKG_USING_GUIENGINE is not set # CONFIG_PKG_USING_CAIRO is not set # CONFIG_PKG_USING_PIXMAN is not set @@ -509,7 +480,6 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 # CONFIG_PKG_USING_WCWIDTH is not set # CONFIG_PKG_USING_MCUBOOT is not set # CONFIG_PKG_USING_TINYUSB is not set -# end of system packages # # peripheral libraries and drivers @@ -585,7 +555,7 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 # CONFIG_PKG_USING_MISAKA_RGB_BLING is not set # CONFIG_PKG_USING_BL_MCU_SDK is not set # CONFIG_PKG_USING_SOFT_SERIAL is not set -# end of peripheral libraries and drivers +# CONFIG_PKG_USING_MB85RS16 is not set # # AI packages @@ -599,7 +569,6 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 # CONFIG_PKG_USING_ULAPACK is not set # CONFIG_PKG_USING_QUEST is not set # CONFIG_PKG_USING_NAXOS is not set -# end of AI packages # # miscellaneous packages @@ -612,7 +581,6 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 # CONFIG_PKG_USING_FILESYSTEM_SAMPLES is not set # CONFIG_PKG_USING_NETWORK_SAMPLES is not set # CONFIG_PKG_USING_PERIPHERAL_SAMPLES is not set -# end of samples: kernel and components samples # # entertainment: terminal games and other interesting software packages @@ -626,8 +594,6 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 # CONFIG_PKG_USING_SNAKE is not set # CONFIG_PKG_USING_TETRIS is not set # CONFIG_PKG_USING_DONUT is not set -# end of entertainment: terminal games and other interesting software packages - # CONFIG_PKG_USING_LIBCSV is not set # CONFIG_PKG_USING_OPTPARSE is not set # CONFIG_PKG_USING_FASTLZ is not set @@ -657,8 +623,5 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 # CONFIG_PKG_USING_MCURSES is not set # CONFIG_PKG_USING_COWSAY is not set # CONFIG_PKG_USING_TERMBOX is not set -# end of miscellaneous packages -# end of RT-Thread online packages - CONFIG_SOC_SIMULATOR=y CONFIG_RT_USING_DFS_WINSHAREDIR=y diff --git a/bsp/simulator/applications/platform.c b/bsp/simulator/applications/platform.c index 815c189e40..2594772eb2 100644 --- a/bsp/simulator/applications/platform.c +++ b/bsp/simulator/applications/platform.c @@ -11,10 +11,6 @@ #include -#ifdef RT_USING_POSIX -#error "simulator does not support RT_USING_POSIX" -#endif - #ifdef RT_USING_LIBC #error "simulator does not support RT_USING_LIBC" #endif diff --git a/bsp/simulator/drivers/board.c b/bsp/simulator/drivers/board.c index 0516af6f79..39c48aa41b 100755 --- a/bsp/simulator/drivers/board.c +++ b/bsp/simulator/drivers/board.c @@ -111,9 +111,4 @@ int rt_hw_board_init(void) return 0; } -void rt_hw_us_delay(rt_uint32_t usec) -{ - -} - /*@}*/ diff --git a/bsp/simulator/rtconfig.h b/bsp/simulator/rtconfig.h index ad7634d729..abbb3008e7 100755 --- a/bsp/simulator/rtconfig.h +++ b/bsp/simulator/rtconfig.h @@ -1,7 +1,8 @@ #ifndef RT_CONFIG_H__ #define RT_CONFIG_H__ -/* Generated by Kconfiglib (https://github.com/ulfalizer/Kconfiglib) */ +/* Automatically generated file; DO NOT EDIT. */ +/* RT-Thread Configuration */ /* RT-Thread Kernel */ @@ -18,7 +19,6 @@ /* kservice optimization */ -/* end of kservice optimization */ #define RT_DEBUG #define RT_DEBUG_COLOR @@ -29,14 +29,12 @@ #define RT_USING_EVENT #define RT_USING_MAILBOX #define RT_USING_MESSAGEQUEUE -/* end of Inter-Thread communication */ /* Memory Management */ #define RT_USING_MEMPOOL #define RT_USING_SMALL_MEM #define RT_USING_HEAP -/* end of Memory Management */ /* Kernel Device Object */ @@ -44,9 +42,7 @@ #define RT_USING_CONSOLE #define RT_CONSOLEBUF_SIZE 128 #define RT_CONSOLE_DEVICE_NAME "console" -/* end of Kernel Device Object */ #define RT_VER_NUM 0x40004 -/* end of RT-Thread Kernel */ /* RT-Thread Components */ @@ -57,7 +53,6 @@ /* C++ features */ -/* end of C++ features */ /* Command shell */ @@ -74,7 +69,6 @@ #define MSH_USING_BUILT_IN_COMMANDS #define FINSH_USING_DESCRIPTION #define FINSH_ARG_MAX 10 -/* end of Command shell */ /* Device virtual file system */ @@ -98,9 +92,7 @@ #define RT_DFS_ELM_MAX_SECTOR_SIZE 512 #define RT_DFS_ELM_REENTRANT #define RT_DFS_ELM_MUTEX_TIMEOUT 3000 -/* end of elm-chan's FatFs, Generic FAT Filesystem Module */ #define RT_USING_DFS_DEVFS -/* end of Device virtual file system */ /* Device Drivers */ @@ -113,46 +105,35 @@ /* Using USB */ -/* end of Using USB */ -/* end of Device Drivers */ /* POSIX layer and C standard library */ #define RT_LIBC_USING_TIME #define RT_LIBC_DEFAULT_TIMEZONE 8 -/* end of POSIX layer and C standard library */ +#define RT_USING_POSIX /* Network */ /* Socket abstraction layer */ -/* end of Socket abstraction layer */ /* Network interface device */ -/* end of Network interface device */ /* light weight TCP/IP stack */ -/* end of light weight TCP/IP stack */ /* AT commands */ -/* end of AT commands */ -/* end of Network */ /* VBUS(Virtual Software BUS) */ -/* end of VBUS(Virtual Software BUS) */ /* Utilities */ -/* end of Utilities */ -/* end of RT-Thread Components */ /* RT-Thread Utestcases */ -/* end of RT-Thread Utestcases */ /* RT-Thread online packages */ @@ -163,72 +144,51 @@ /* Marvell WiFi */ -/* end of Marvell WiFi */ /* Wiced WiFi */ -/* end of Wiced WiFi */ -/* end of Wi-Fi */ /* IoT Cloud */ -/* end of IoT Cloud */ -/* end of IoT - internet of things */ /* security packages */ -/* end of security packages */ /* language packages */ -/* end of language packages */ /* multimedia packages */ +/* LVGL: powerful and easy-to-use embedded GUI library */ -/* lvgl: powerful and easy-to-use embedded GUI library */ - -/* end of lvgl: powerful and easy-to-use embedded GUI library */ /* u8g2: a monochrome graphic library */ -/* end of u8g2: a monochrome graphic library */ -/* end of multimedia packages */ /* tools packages */ -/* end of tools packages */ /* system packages */ /* acceleration: Assembly language or algorithmic acceleration packages */ -/* end of acceleration: Assembly language or algorithmic acceleration packages */ /* Micrium: Micrium software products porting for RT-Thread */ -/* end of Micrium: Micrium software products porting for RT-Thread */ -/* end of system packages */ /* peripheral libraries and drivers */ -/* end of peripheral libraries and drivers */ /* AI packages */ -/* end of AI packages */ /* miscellaneous packages */ /* samples: kernel and components samples */ -/* end of samples: kernel and components samples */ /* entertainment: terminal games and other interesting software packages */ -/* end of entertainment: terminal games and other interesting software packages */ -/* end of miscellaneous packages */ -/* end of RT-Thread online packages */ #define SOC_SIMULATOR #define RT_USING_DFS_WINSHAREDIR #include "rtconfig_project.h" diff --git a/bsp/simulator/rtconfig.py b/bsp/simulator/rtconfig.py index d08447939d..2b18c2140a 100755 --- a/bsp/simulator/rtconfig.py +++ b/bsp/simulator/rtconfig.py @@ -42,7 +42,7 @@ elif CROSS_TOOL == 'msvc': print('Successfully installed VC %s, path:%s' % (vc_version, EXEC_PATH)) else: - print("bad CROSS TOOL!") + print("Simulator does not support this CROSS TOOL!") exit(1) if os.getenv('RTT_EXEC_PATH'): diff --git a/components/libc/compilers/common/SConscript b/components/libc/compilers/common/SConscript index bd66b70c7e..504bf84e56 100644 --- a/components/libc/compilers/common/SConscript +++ b/components/libc/compilers/common/SConscript @@ -1,5 +1,4 @@ from building import * - Import('rtconfig') src = [] diff --git a/components/libc/posix/src/SConscript b/components/libc/posix/src/SConscript index 8712d671c0..f338b52cec 100644 --- a/components/libc/posix/src/SConscript +++ b/components/libc/posix/src/SConscript @@ -1,11 +1,13 @@ -# RT-Thread building script for component - from building import * +Import('rtconfig') src = Glob('*.c') cwd = GetCurrentDir() CPPPATH = [cwd] +if rtconfig.ARCH == 'sim': # the vs simulator does not support select and poll + SrcRemove(src, ['select.c', 'poll.c']) + group = DefineGroup('POSIX', src, depend = ['RT_USING_POSIX'], CPPPATH = CPPPATH) Return('group') diff --git a/components/libc/posix/src/libc.c b/components/libc/posix/src/libc.c index 84c5a601bc..068719d5d6 100644 --- a/components/libc/posix/src/libc.c +++ b/components/libc/posix/src/libc.c @@ -144,5 +144,5 @@ int libc_stdio_set_console(const char* device_name, int mode) int libc_stdio_get_console(void) { return std_fd; } -#endif /* defined(RT_USING_LIBC) && (defined(__GNUC__) && !defined(__ARMCC_VERSION)) */ +#endif /* defined(RT_USING_LIBC) && defined(RT_USING_NEWLIB) */ #endif /* RT_USING_POSIX */ -- cgit v1.3.1