From c8c632512aa6c87211871fe0a85e77b72d4ebe06 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Tue, 21 Sep 2021 12:51:26 -0400 Subject: [libc][syscall]移除libc_stdio_read/write函数,优化syscall MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/dlib/syscall_write.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'components/libc/compilers/dlib/syscall_write.c') diff --git a/components/libc/compilers/dlib/syscall_write.c b/components/libc/compilers/dlib/syscall_write.c index de464530b8..a5462653bf 100644 --- a/components/libc/compilers/dlib/syscall_write.c +++ b/components/libc/compilers/dlib/syscall_write.c @@ -30,19 +30,24 @@ size_t __write(int handle, const unsigned char *buf, size_t len) #else #ifdef RT_USING_POSIX - return libc_stdio_write((void*)buf, len); + return write(STDOUT_FILENO, (void*)buf, len); #else rt_device_t console_device; console_device = rt_console_get_device(); - if (console_device != 0) rt_device_write(console_device, 0, buf, len); + if (console_device != 0) + { + rt_device_write(console_device, 0, buf, len); + } return len; #endif #endif } - - if (handle == _LLIO_STDIN) return _LLIO_ERROR; + else if (handle == _LLIO_STDIN) + { + return _LLIO_ERROR; + } #ifndef RT_USING_DFS return _LLIO_ERROR; -- cgit v1.3.1 From 86bb54fde6f3ed59050d724a7e98defd7c4f47a9 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Mon, 27 Sep 2021 06:51:40 -0400 Subject: [libc][syscalls] 在标准输入输出前加校验,反正在libc初始化之前调用printf出问题 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/armlibc/syscalls.c | 14 ++++++++++++++ components/libc/compilers/dlib/syscall_read.c | 9 +++++++++ components/libc/compilers/dlib/syscall_write.c | 9 +++++++++ components/libc/compilers/newlib/syscalls.c | 16 ++++++++++++++-- 4 files changed, 46 insertions(+), 2 deletions(-) (limited to 'components/libc/compilers/dlib/syscall_write.c') diff --git a/components/libc/compilers/armlibc/syscalls.c b/components/libc/compilers/armlibc/syscalls.c index d942bdb984..a3ba57a280 100644 --- a/components/libc/compilers/armlibc/syscalls.c +++ b/components/libc/compilers/armlibc/syscalls.c @@ -25,6 +25,10 @@ #include #endif +#define DBG_TAG "armlibc.syscalls" +#define DBG_LVL DBG_INFO +#include + #ifdef __CLANG_ARM __asm(".global __use_no_semihosting\n\t"); #else @@ -146,6 +150,11 @@ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode) if (fh == STDIN) { #ifdef RT_USING_POSIX + if (libc_stdio_get_console() < 0) + { + LOG_E("invoke standard output before initializing libc"); + return -1; + } size = read(STDIN_FILENO, buf, len); return len - size; #else @@ -186,6 +195,11 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode) return 0; #else #ifdef RT_USING_POSIX + if (libc_stdio_get_console() < 0) + { + LOG_E("invoke standard input before initializing libc"); + return -1; + } size = write(STDOUT_FILENO, buf, len); return len - size; #else diff --git a/components/libc/compilers/dlib/syscall_read.c b/components/libc/compilers/dlib/syscall_read.c index e716d0b024..bdc694b7d8 100644 --- a/components/libc/compilers/dlib/syscall_read.c +++ b/components/libc/compilers/dlib/syscall_read.c @@ -15,6 +15,10 @@ #include #include "libc.h" +#define DBG_TAG "dlib.syscall_read" +#define DBG_LVL DBG_INFO +#include + #pragma module_name = "?__read" size_t __read(int handle, unsigned char *buf, size_t len) { @@ -25,6 +29,11 @@ size_t __read(int handle, unsigned char *buf, size_t len) if (handle == _LLIO_STDIN) { #ifdef RT_USING_POSIX + if (libc_stdio_get_console() < 0) + { + LOG_E("invoke standard input before initializing libc"); + return _LLIO_ERROR; + } return read(STDIN_FILENO, buf, len); #else return _LLIO_ERROR; diff --git a/components/libc/compilers/dlib/syscall_write.c b/components/libc/compilers/dlib/syscall_write.c index a5462653bf..bd7cc83d99 100644 --- a/components/libc/compilers/dlib/syscall_write.c +++ b/components/libc/compilers/dlib/syscall_write.c @@ -15,6 +15,10 @@ #include #include "libc.h" +#define DBG_TAG "dlib.syscall_write" +#define DBG_LVL DBG_INFO +#include + #pragma module_name = "?__write" size_t __write(int handle, const unsigned char *buf, size_t len) @@ -30,6 +34,11 @@ size_t __write(int handle, const unsigned char *buf, size_t len) #else #ifdef RT_USING_POSIX + if (libc_stdio_get_console() < 0) + { + LOG_E("invoke standard output before initializing libc"); + return _LLIO_ERROR; + } return write(STDOUT_FILENO, (void*)buf, len); #else rt_device_t console_device; diff --git a/components/libc/compilers/newlib/syscalls.c b/components/libc/compilers/newlib/syscalls.c index aeb4d123e7..d46a264408 100644 --- a/components/libc/compilers/newlib/syscalls.c +++ b/components/libc/compilers/newlib/syscalls.c @@ -26,6 +26,10 @@ #include #endif +#define DBG_TAG "newlib.syscalls" +#define DBG_LVL DBG_INFO +#include + /* Reentrant versions of system calls. */ #ifndef _REENT_ONLY @@ -155,7 +159,11 @@ _ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes) return -1; #else _ssize_t rc; - + if (libc_stdio_get_console() < 0 && fd == STDIN_FILENO) + { + LOG_E("invoke standard input before initializing libc"); + return -1; + } rc = read(fd, buf, nbytes); return rc; #endif @@ -227,7 +235,11 @@ _ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes) #endif /*RT_USING_DEVICE*/ #else _ssize_t rc; - + if (libc_stdio_get_console() < 0 && fd == STDOUT_FILENO) + { + LOG_E("invoke standard output before initializing libc"); + return -1; + } rc = write(fd, buf, nbytes); return rc; #endif -- cgit v1.3.1 From 0a799653df4ae4bcaeef78620768a1c8d6242d94 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Mon, 27 Sep 2021 07:29:50 -0400 Subject: [libc][syscalls]将在libc初始化之前调用printf的行为下调为警告级别 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/armlibc/syscalls.c | 8 ++++---- components/libc/compilers/dlib/syscall_read.c | 4 ++-- components/libc/compilers/dlib/syscall_write.c | 4 ++-- components/libc/compilers/newlib/syscalls.c | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-) (limited to 'components/libc/compilers/dlib/syscall_write.c') diff --git a/components/libc/compilers/armlibc/syscalls.c b/components/libc/compilers/armlibc/syscalls.c index a3ba57a280..7d8ec2e8b4 100644 --- a/components/libc/compilers/armlibc/syscalls.c +++ b/components/libc/compilers/armlibc/syscalls.c @@ -152,8 +152,8 @@ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode) #ifdef RT_USING_POSIX if (libc_stdio_get_console() < 0) { - LOG_E("invoke standard output before initializing libc"); - return -1; + LOG_W("Do not invoke standard output before initializing libc"); + return 0; } size = read(STDIN_FILENO, buf, len); return len - size; @@ -197,8 +197,8 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode) #ifdef RT_USING_POSIX if (libc_stdio_get_console() < 0) { - LOG_E("invoke standard input before initializing libc"); - return -1; + LOG_W("Do not invoke standard input before initializing libc"); + return 0; } size = write(STDOUT_FILENO, buf, len); return len - size; diff --git a/components/libc/compilers/dlib/syscall_read.c b/components/libc/compilers/dlib/syscall_read.c index bdc694b7d8..ae980be6ca 100644 --- a/components/libc/compilers/dlib/syscall_read.c +++ b/components/libc/compilers/dlib/syscall_read.c @@ -31,8 +31,8 @@ size_t __read(int handle, unsigned char *buf, size_t len) #ifdef RT_USING_POSIX if (libc_stdio_get_console() < 0) { - LOG_E("invoke standard input before initializing libc"); - return _LLIO_ERROR; + LOG_W("Do not invoke standard input before initializing libc"); + return 0; } return read(STDIN_FILENO, buf, len); #else diff --git a/components/libc/compilers/dlib/syscall_write.c b/components/libc/compilers/dlib/syscall_write.c index bd7cc83d99..ffee51882d 100644 --- a/components/libc/compilers/dlib/syscall_write.c +++ b/components/libc/compilers/dlib/syscall_write.c @@ -36,8 +36,8 @@ size_t __write(int handle, const unsigned char *buf, size_t len) #ifdef RT_USING_POSIX if (libc_stdio_get_console() < 0) { - LOG_E("invoke standard output before initializing libc"); - return _LLIO_ERROR; + LOG_W("Do not invoke standard output before initializing libc"); + return 0; } return write(STDOUT_FILENO, (void*)buf, len); #else diff --git a/components/libc/compilers/newlib/syscalls.c b/components/libc/compilers/newlib/syscalls.c index 1cb7475fe1..4c1dc82ad3 100644 --- a/components/libc/compilers/newlib/syscalls.c +++ b/components/libc/compilers/newlib/syscalls.c @@ -227,8 +227,8 @@ _ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes) _ssize_t rc; if (libc_stdio_get_console() < 0 && fd == STDIN_FILENO) { - LOG_E("invoke standard input before initializing libc"); - return -1; + LOG_W("Do not invoke standard input before initializing libc"); + return 0; } rc = read(fd, buf, nbytes); return rc; @@ -303,8 +303,8 @@ _ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes) _ssize_t rc; if (libc_stdio_get_console() < 0 && fd == STDOUT_FILENO) { - LOG_E("invoke standard output before initializing libc"); - return -1; + LOG_W("Do not invoke standard output before initializing libc"); + return 0; } rc = write(fd, buf, nbytes); return rc; -- cgit v1.3.1 From a354f846e8699fbb8152cfa721f5b9a1e3a2c1a4 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Wed, 13 Oct 2021 14:29:00 -0400 Subject: [libc]&[dfs] remove unnecessary RT_USING_POSIX and RT_USING_DFS_DEVFS --- components/dfs/src/dfs.c | 4 ++-- components/libc/compilers/armlibc/libc.c | 12 ++++++------ components/libc/compilers/armlibc/syscalls.c | 10 +++++----- components/libc/compilers/dlib/libc.c | 10 +++++----- components/libc/compilers/dlib/syscall_write.c | 10 +++++----- components/libc/compilers/gcc/newlib/libc.c | 8 ++++---- 6 files changed, 27 insertions(+), 27 deletions(-) (limited to 'components/libc/compilers/dlib/syscall_write.c') diff --git a/components/dfs/src/dfs.c b/components/dfs/src/dfs.c index 8155b088f0..c91a9c6ef8 100644 --- a/components/dfs/src/dfs.c +++ b/components/dfs/src/dfs.c @@ -18,7 +18,7 @@ #include #endif -#if defined(RT_USING_DFS_DEVFS) && defined(RT_USING_POSIX) +#if defined(RT_USING_DFS_DEVFS) && defined(RT_USING_LIBC) #include #endif @@ -216,7 +216,7 @@ struct dfs_fd *fd_get(int fd) struct dfs_fd *d; struct dfs_fdtable *fdt; -#if defined(RT_USING_DFS_DEVFS) && defined(RT_USING_POSIX) +#if defined(RT_USING_DFS_DEVFS) && defined(RT_USING_LIBC) if ((0 <= fd) && (fd <= 2)) fd = libc_stdio_get_console(); #endif diff --git a/components/libc/compilers/armlibc/libc.c b/components/libc/compilers/armlibc/libc.c index 889c687309..82f42f5047 100644 --- a/components/libc/compilers/armlibc/libc.c +++ b/components/libc/compilers/armlibc/libc.c @@ -17,23 +17,23 @@ int libc_system_init(void) { -#if defined(RT_USING_DFS) & defined(RT_USING_DFS_DEVFS) +#ifdef RT_USING_DFS_DEVFS rt_device_t dev_console; dev_console = rt_console_get_device(); if (dev_console) { - #if defined(RT_USING_POSIX) + #ifdef RT_USING_POSIX libc_stdio_set_console(dev_console->parent.name, O_RDWR); #else libc_stdio_set_console(dev_console->parent.name, O_WRONLY); - #endif + #endif /* RT_USING_POSIX */ } -#endif +#endif /* RT_USING_DFS_DEVFS */ -#if defined RT_USING_PTHREADS && !defined RT_USING_COMPONENTS_INIT +#if defined(RT_USING_PTHREADS) && !defined(RT_USING_COMPONENTS_INIT) pthread_system_init(); -#endif +#endif /* defined(RT_USING_PTHREADS) && !defined(RT_USING_COMPONENTS_INIT) */ return 0; } diff --git a/components/libc/compilers/armlibc/syscalls.c b/components/libc/compilers/armlibc/syscalls.c index ccdcfc86ea..0142c3335d 100644 --- a/components/libc/compilers/armlibc/syscalls.c +++ b/components/libc/compilers/armlibc/syscalls.c @@ -187,14 +187,14 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode) { #ifdef RT_USING_DFS int size; -#endif +#endif /* RT_USING_DFS */ if ((fh == STDOUT) || (fh == STDERR)) { #if !defined(RT_USING_CONSOLE) || !defined(RT_USING_DEVICE) return 0; #else -#ifdef RT_USING_POSIX +#ifdef RT_USING_DFS if (libc_stdio_get_console() < 0) { LOG_W("Do not invoke standard input before initializing libc"); @@ -210,8 +210,8 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode) } return -1; -#endif -#endif +#endif /* RT_USING_DFS */ +#endif /* !defined(RT_USING_CONSOLE) || !defined(RT_USING_DEVICE) */ } else if (fh == STDIN) { @@ -226,7 +226,7 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode) return len - size; else return -1; -#endif +#endif /* RT_USING_DFS */ } /* diff --git a/components/libc/compilers/dlib/libc.c b/components/libc/compilers/dlib/libc.c index f540ac955f..ac3d78f1f9 100644 --- a/components/libc/compilers/dlib/libc.c +++ b/components/libc/compilers/dlib/libc.c @@ -17,23 +17,23 @@ int libc_system_init(void) { -#if defined(RT_USING_DFS) && defined(RT_USING_DFS_DEVFS) +#ifdef RT_USING_DFS_DEVFS rt_device_t dev_console; dev_console = rt_console_get_device(); if (dev_console) { - #if defined(RT_USING_POSIX) + #ifdef RT_USING_POSIX libc_stdio_set_console(dev_console->parent.name, O_RDWR); #else libc_stdio_set_console(dev_console->parent.name, O_WRONLY); - #endif + #endif /* RT_USING_POSIX */ } -#endif +#endif /* RT_USING_DFS_DEVFS */ #if defined (RT_USING_PTHREADS) && !defined (RT_USING_COMPONENTS_INIT) pthread_system_init(); -#endif +#endif /* defined (RT_USING_PTHREADS) && !defined (RT_USING_COMPONENTS_INIT) */ return 0; } diff --git a/components/libc/compilers/dlib/syscall_write.c b/components/libc/compilers/dlib/syscall_write.c index ffee51882d..481e9f8c3d 100644 --- a/components/libc/compilers/dlib/syscall_write.c +++ b/components/libc/compilers/dlib/syscall_write.c @@ -25,7 +25,7 @@ size_t __write(int handle, const unsigned char *buf, size_t len) { #ifdef RT_USING_DFS int size; -#endif +#endif /* RT_USING_DFS */ if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR)) { @@ -33,7 +33,7 @@ size_t __write(int handle, const unsigned char *buf, size_t len) return _LLIO_ERROR; #else -#ifdef RT_USING_POSIX +#ifdef RT_USING_DFS if (libc_stdio_get_console() < 0) { LOG_W("Do not invoke standard output before initializing libc"); @@ -50,8 +50,8 @@ size_t __write(int handle, const unsigned char *buf, size_t len) } return len; -#endif -#endif +#endif /* RT_USING_DFS */ +#endif /* RT_USING_CONSOLE */ } else if (handle == _LLIO_STDIN) { @@ -63,6 +63,6 @@ size_t __write(int handle, const unsigned char *buf, size_t len) #else size = write(handle, buf, len); return size; -#endif +#endif /* RT_USING_DFS */ } diff --git a/components/libc/compilers/gcc/newlib/libc.c b/components/libc/compilers/gcc/newlib/libc.c index 9834a9a015..20d41a521b 100644 --- a/components/libc/compilers/gcc/newlib/libc.c +++ b/components/libc/compilers/gcc/newlib/libc.c @@ -23,7 +23,7 @@ int _EXFUN(putenv,(char *__string)); int libc_system_init(void) { -#if defined(RT_USING_DFS) & defined(RT_USING_DFS_DEVFS) & defined(RT_USING_CONSOLE) +#if defined(RT_USING_DFS_DEVFS) & defined(RT_USING_CONSOLE) rt_device_t dev_console; dev_console = rt_console_get_device(); @@ -39,11 +39,11 @@ int libc_system_init(void) /* set PATH and HOME */ putenv("PATH=/bin"); putenv("HOME=/home"); -#endif +#endif /* defined(RT_USING_DFS_DEVFS) & defined(RT_USING_CONSOLE) */ -#if defined RT_USING_PTHREADS && !defined RT_USING_COMPONENTS_INIT +#if defined(RT_USING_PTHREADS) && !defined(RT_USING_COMPONENTS_INIT) pthread_system_init(); -#endif +#endif /* defined(RT_USING_PTHREADS) && !defined(RT_USING_COMPONENTS_INIT) */ return 0; } -- cgit v1.3.1 From 8c01acc667898be1674cf0be3f2c21c2cedaa329 Mon Sep 17 00:00:00 2001 From: "Jianting (Meco) Man" <920369182@qq.com> Date: Thu, 14 Oct 2021 20:11:01 -0400 Subject: Revert "[libc]&[dfs] remove unnecessary RT_USING_POSIX and RT_USING_DFS_DEVFS" --- components/dfs/src/dfs.c | 4 ++-- components/libc/compilers/armlibc/libc.c | 12 ++++++------ components/libc/compilers/armlibc/syscalls.c | 10 +++++----- components/libc/compilers/dlib/libc.c | 10 +++++----- components/libc/compilers/dlib/syscall_write.c | 10 +++++----- components/libc/compilers/gcc/newlib/libc.c | 8 ++++---- 6 files changed, 27 insertions(+), 27 deletions(-) (limited to 'components/libc/compilers/dlib/syscall_write.c') diff --git a/components/dfs/src/dfs.c b/components/dfs/src/dfs.c index c91a9c6ef8..8155b088f0 100644 --- a/components/dfs/src/dfs.c +++ b/components/dfs/src/dfs.c @@ -18,7 +18,7 @@ #include #endif -#if defined(RT_USING_DFS_DEVFS) && defined(RT_USING_LIBC) +#if defined(RT_USING_DFS_DEVFS) && defined(RT_USING_POSIX) #include #endif @@ -216,7 +216,7 @@ struct dfs_fd *fd_get(int fd) struct dfs_fd *d; struct dfs_fdtable *fdt; -#if defined(RT_USING_DFS_DEVFS) && defined(RT_USING_LIBC) +#if defined(RT_USING_DFS_DEVFS) && defined(RT_USING_POSIX) if ((0 <= fd) && (fd <= 2)) fd = libc_stdio_get_console(); #endif diff --git a/components/libc/compilers/armlibc/libc.c b/components/libc/compilers/armlibc/libc.c index 82f42f5047..889c687309 100644 --- a/components/libc/compilers/armlibc/libc.c +++ b/components/libc/compilers/armlibc/libc.c @@ -17,23 +17,23 @@ int libc_system_init(void) { -#ifdef RT_USING_DFS_DEVFS +#if defined(RT_USING_DFS) & defined(RT_USING_DFS_DEVFS) rt_device_t dev_console; dev_console = rt_console_get_device(); if (dev_console) { - #ifdef RT_USING_POSIX + #if defined(RT_USING_POSIX) libc_stdio_set_console(dev_console->parent.name, O_RDWR); #else libc_stdio_set_console(dev_console->parent.name, O_WRONLY); - #endif /* RT_USING_POSIX */ + #endif } -#endif /* RT_USING_DFS_DEVFS */ +#endif -#if defined(RT_USING_PTHREADS) && !defined(RT_USING_COMPONENTS_INIT) +#if defined RT_USING_PTHREADS && !defined RT_USING_COMPONENTS_INIT pthread_system_init(); -#endif /* defined(RT_USING_PTHREADS) && !defined(RT_USING_COMPONENTS_INIT) */ +#endif return 0; } diff --git a/components/libc/compilers/armlibc/syscalls.c b/components/libc/compilers/armlibc/syscalls.c index 0142c3335d..ccdcfc86ea 100644 --- a/components/libc/compilers/armlibc/syscalls.c +++ b/components/libc/compilers/armlibc/syscalls.c @@ -187,14 +187,14 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode) { #ifdef RT_USING_DFS int size; -#endif /* RT_USING_DFS */ +#endif if ((fh == STDOUT) || (fh == STDERR)) { #if !defined(RT_USING_CONSOLE) || !defined(RT_USING_DEVICE) return 0; #else -#ifdef RT_USING_DFS +#ifdef RT_USING_POSIX if (libc_stdio_get_console() < 0) { LOG_W("Do not invoke standard input before initializing libc"); @@ -210,8 +210,8 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode) } return -1; -#endif /* RT_USING_DFS */ -#endif /* !defined(RT_USING_CONSOLE) || !defined(RT_USING_DEVICE) */ +#endif +#endif } else if (fh == STDIN) { @@ -226,7 +226,7 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode) return len - size; else return -1; -#endif /* RT_USING_DFS */ +#endif } /* diff --git a/components/libc/compilers/dlib/libc.c b/components/libc/compilers/dlib/libc.c index ac3d78f1f9..f540ac955f 100644 --- a/components/libc/compilers/dlib/libc.c +++ b/components/libc/compilers/dlib/libc.c @@ -17,23 +17,23 @@ int libc_system_init(void) { -#ifdef RT_USING_DFS_DEVFS +#if defined(RT_USING_DFS) && defined(RT_USING_DFS_DEVFS) rt_device_t dev_console; dev_console = rt_console_get_device(); if (dev_console) { - #ifdef RT_USING_POSIX + #if defined(RT_USING_POSIX) libc_stdio_set_console(dev_console->parent.name, O_RDWR); #else libc_stdio_set_console(dev_console->parent.name, O_WRONLY); - #endif /* RT_USING_POSIX */ + #endif } -#endif /* RT_USING_DFS_DEVFS */ +#endif #if defined (RT_USING_PTHREADS) && !defined (RT_USING_COMPONENTS_INIT) pthread_system_init(); -#endif /* defined (RT_USING_PTHREADS) && !defined (RT_USING_COMPONENTS_INIT) */ +#endif return 0; } diff --git a/components/libc/compilers/dlib/syscall_write.c b/components/libc/compilers/dlib/syscall_write.c index 481e9f8c3d..ffee51882d 100644 --- a/components/libc/compilers/dlib/syscall_write.c +++ b/components/libc/compilers/dlib/syscall_write.c @@ -25,7 +25,7 @@ size_t __write(int handle, const unsigned char *buf, size_t len) { #ifdef RT_USING_DFS int size; -#endif /* RT_USING_DFS */ +#endif if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR)) { @@ -33,7 +33,7 @@ size_t __write(int handle, const unsigned char *buf, size_t len) return _LLIO_ERROR; #else -#ifdef RT_USING_DFS +#ifdef RT_USING_POSIX if (libc_stdio_get_console() < 0) { LOG_W("Do not invoke standard output before initializing libc"); @@ -50,8 +50,8 @@ size_t __write(int handle, const unsigned char *buf, size_t len) } return len; -#endif /* RT_USING_DFS */ -#endif /* RT_USING_CONSOLE */ +#endif +#endif } else if (handle == _LLIO_STDIN) { @@ -63,6 +63,6 @@ size_t __write(int handle, const unsigned char *buf, size_t len) #else size = write(handle, buf, len); return size; -#endif /* RT_USING_DFS */ +#endif } diff --git a/components/libc/compilers/gcc/newlib/libc.c b/components/libc/compilers/gcc/newlib/libc.c index 20d41a521b..9834a9a015 100644 --- a/components/libc/compilers/gcc/newlib/libc.c +++ b/components/libc/compilers/gcc/newlib/libc.c @@ -23,7 +23,7 @@ int _EXFUN(putenv,(char *__string)); int libc_system_init(void) { -#if defined(RT_USING_DFS_DEVFS) & defined(RT_USING_CONSOLE) +#if defined(RT_USING_DFS) & defined(RT_USING_DFS_DEVFS) & defined(RT_USING_CONSOLE) rt_device_t dev_console; dev_console = rt_console_get_device(); @@ -39,11 +39,11 @@ int libc_system_init(void) /* set PATH and HOME */ putenv("PATH=/bin"); putenv("HOME=/home"); -#endif /* defined(RT_USING_DFS_DEVFS) & defined(RT_USING_CONSOLE) */ +#endif -#if defined(RT_USING_PTHREADS) && !defined(RT_USING_COMPONENTS_INIT) +#if defined RT_USING_PTHREADS && !defined RT_USING_COMPONENTS_INIT pthread_system_init(); -#endif /* defined(RT_USING_PTHREADS) && !defined(RT_USING_COMPONENTS_INIT) */ +#endif return 0; } -- cgit v1.3.1 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 --- bsp/bluetrum/ab32vg1-ab-prougen/.config | 74 ++-------- bsp/bluetrum/ab32vg1-ab-prougen/rtconfig.h | 50 +------ bsp/gd32303e-eval/rtconfig.h | 1 - bsp/gd32vf103v-eval/.config | 74 ++-------- bsp/gd32vf103v-eval/SConscript | 2 - bsp/gd32vf103v-eval/libraries/SConscript | 7 +- .../libraries/n22/env_Eclipse/handlers.c | 9 +- .../libraries/n22/env_Eclipse/start.S | 2 +- bsp/gd32vf103v-eval/rtconfig.h | 50 +------ bsp/lm3s8962/applications/startup.c | 2 +- bsp/lpc1114/.config | 73 ++------- bsp/lpc1114/rtconfig.h | 47 +----- components/dfs/src/dfs.c | 4 +- components/finsh/shell.c | 8 +- components/finsh/shell.h | 2 +- components/libc/Kconfig | 67 +++++---- components/libc/compilers/armlibc/SConscript | 3 - components/libc/compilers/armlibc/libc.c | 11 +- components/libc/compilers/armlibc/libc.h | 4 + components/libc/compilers/armlibc/stdio.c | 9 +- components/libc/compilers/armlibc/syscalls.c | 121 +++++++-------- components/libc/compilers/common/SConscript | 2 +- components/libc/compilers/dlib/SConscript | 5 +- components/libc/compilers/dlib/libc.c | 12 +- components/libc/compilers/dlib/libc.h | 2 + components/libc/compilers/dlib/stdio.c | 12 +- components/libc/compilers/dlib/syscall_close.c | 11 +- components/libc/compilers/dlib/syscall_lseek.c | 7 +- components/libc/compilers/dlib/syscall_open.c | 12 +- components/libc/compilers/dlib/syscall_read.c | 18 +-- components/libc/compilers/dlib/syscall_remove.c | 12 +- components/libc/compilers/dlib/syscall_write.c | 30 ++-- components/libc/compilers/gcc/newlib/libc.c | 15 +- components/libc/compilers/gcc/newlib/libc.h | 7 +- components/libc/compilers/gcc/newlib/stdio.c | 8 +- components/libc/compilers/gcc/newlib/syscalls.c | 164 +++++++++------------ 36 files changed, 297 insertions(+), 640 deletions(-) (limited to 'components/libc/compilers/dlib/syscall_write.c') diff --git a/bsp/bluetrum/ab32vg1-ab-prougen/.config b/bsp/bluetrum/ab32vg1-ab-prougen/.config index e7c661a790..694e4bd3ff 100644 --- a/bsp/bluetrum/ab32vg1-ab-prougen/.config +++ b/bsp/bluetrum/ab32vg1-ab-prougen/.config @@ -1,9 +1,13 @@ -# Generated by Kconfiglib (https://github.com/ulfalizer/Kconfiglib) +# +# Automatically generated file; DO NOT EDIT. +# RT-Thread Project 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=8 @@ -26,8 +30,7 @@ CONFIG_RT_TIMER_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 is not set # CONFIG_RT_DEBUG_INIT_CONFIG is not set @@ -50,7 +53,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 @@ -64,7 +66,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 @@ -76,10 +77,9 @@ CONFIG_RT_USING_CONSOLE=y CONFIG_RT_CONSOLEBUF_SIZE=128 CONFIG_RT_CONSOLE_DEVICE_NAME="uart0" # 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 @@ -93,7 +93,6 @@ CONFIG_RT_MAIN_THREAD_PRIORITY=10 # C++ features # # CONFIG_RT_USING_CPLUSPLUS is not set -# end of C++ features # # Command shell @@ -113,13 +112,11 @@ 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 # # CONFIG_RT_USING_DFS is not set -# end of Device virtual file system # # Device Drivers @@ -159,20 +156,17 @@ CONFIG_RT_USING_PIN=y # # 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=y +# CONFIG_RT_USING_LIBC is not set # CONFIG_RT_USING_PTHREADS is not set CONFIG_RT_LIBC_USING_TIME=y -# CONFIG_RT_USING_MODULE is not set CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 -# end of POSIX layer and C standard library # # Network @@ -182,32 +176,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 @@ -217,14 +205,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 @@ -259,17 +244,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 @@ -291,8 +271,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 @@ -326,7 +304,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 @@ -336,7 +313,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 @@ -345,22 +321,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 @@ -377,8 +350,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 @@ -421,7 +392,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 @@ -434,7 +404,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 @@ -445,8 +414,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 @@ -480,7 +447,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 @@ -560,7 +526,7 @@ CONFIG_PKG_BLUETRUM_SDK_VER="latest" # 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 @@ -574,7 +540,6 @@ CONFIG_PKG_BLUETRUM_SDK_VER="latest" # 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 @@ -587,7 +552,6 @@ CONFIG_PKG_BLUETRUM_SDK_VER="latest" # 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 @@ -601,8 +565,6 @@ CONFIG_PKG_BLUETRUM_SDK_VER="latest" # 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 @@ -632,8 +594,6 @@ CONFIG_PKG_BLUETRUM_SDK_VER="latest" # 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 # # Hardware Drivers Config @@ -645,7 +605,6 @@ CONFIG_SOC_AB32VG1=y # # CONFIG_BSP_USING_AUDIO is not set # CONFIG_BSP_USING_SDCARD is not set -# end of Onboard Peripheral Drivers # # On-chip Peripheral Drivers @@ -663,11 +622,8 @@ CONFIG_BSP_UART0_FIFO_SIZE=10 # CONFIG_BSP_USING_ONCHIP_RTC is not set # CONFIG_BSP_USING_ADC is not set # CONFIG_BSP_USING_IRRX is not set -# end of On-chip Peripheral Drivers # # Board extended module Drivers # -# end of Hardware Drivers Config - CONFIG_BOARD_BLUETRUM_EVB=y diff --git a/bsp/bluetrum/ab32vg1-ab-prougen/rtconfig.h b/bsp/bluetrum/ab32vg1-ab-prougen/rtconfig.h index c3ec6bfbd6..fe8966f5c4 100644 --- a/bsp/bluetrum/ab32vg1-ab-prougen/rtconfig.h +++ b/bsp/bluetrum/ab32vg1-ab-prougen/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 Project Configuration */ /* RT-Thread Kernel */ @@ -21,7 +22,6 @@ /* kservice optimization */ -/* end of kservice optimization */ #define RT_DEBUG /* Inter-Thread communication */ @@ -31,7 +31,6 @@ #define RT_USING_EVENT #define RT_USING_MAILBOX #define RT_USING_MESSAGEQUEUE -/* end of Inter-Thread communication */ /* Memory Management */ @@ -39,7 +38,6 @@ #define RT_USING_MEMHEAP #define RT_USING_SMALL_MEM #define RT_USING_HEAP -/* end of Memory Management */ /* Kernel Device Object */ @@ -48,9 +46,7 @@ #define RT_USING_CONSOLE #define RT_CONSOLEBUF_SIZE 128 #define RT_CONSOLE_DEVICE_NAME "uart0" -/* end of Kernel Device Object */ #define RT_VER_NUM 0x40004 -/* end of RT-Thread Kernel */ /* RT-Thread Components */ @@ -61,7 +57,6 @@ /* C++ features */ -/* end of C++ features */ /* Command shell */ @@ -78,11 +73,9 @@ #define MSH_USING_BUILT_IN_COMMANDS #define FINSH_USING_DESCRIPTION #define FINSH_ARG_MAX 10 -/* end of Command shell */ /* Device virtual file system */ -/* end of Device virtual file system */ /* Device Drivers */ @@ -95,47 +88,34 @@ /* Using USB */ -/* end of Using USB */ -/* end of Device Drivers */ /* POSIX layer and C standard library */ -#define RT_USING_LIBC #define RT_LIBC_USING_TIME #define RT_LIBC_DEFAULT_TIMEZONE 8 -/* end of POSIX layer and C standard library */ /* 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 */ @@ -146,74 +126,53 @@ /* 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 */ #define PKG_USING_BLUETRUM_SDK #define PKG_USING_BLUETRUM_SDK_LATEST_VERSION -/* 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 */ /* Hardware Drivers Config */ @@ -221,18 +180,15 @@ /* Onboard Peripheral Drivers */ -/* end of Onboard Peripheral Drivers */ /* On-chip Peripheral Drivers */ #define BSP_USING_UART #define BSP_USING_UART0 #define BSP_UART0_FIFO_SIZE 10 -/* end of On-chip Peripheral Drivers */ /* Board extended module Drivers */ -/* end of Hardware Drivers Config */ #define BOARD_BLUETRUM_EVB #endif diff --git a/bsp/gd32303e-eval/rtconfig.h b/bsp/gd32303e-eval/rtconfig.h index 365fd296e0..7a47c83787 100644 --- a/bsp/gd32303e-eval/rtconfig.h +++ b/bsp/gd32303e-eval/rtconfig.h @@ -125,7 +125,6 @@ /* POSIX layer and C standard library */ #define RT_USING_LIBC -#define RT_USING_POSIX #define RT_LIBC_USING_TIME #define RT_LIBC_DEFAULT_TIMEZONE 8 /* end of POSIX layer and C standard library */ diff --git a/bsp/gd32vf103v-eval/.config b/bsp/gd32vf103v-eval/.config index e132f56ff7..60139f82a5 100644 --- a/bsp/gd32vf103v-eval/.config +++ b/bsp/gd32vf103v-eval/.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 @@ -26,8 +30,7 @@ CONFIG_RT_TIMER_THREAD_STACK_SIZE=512 # # 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 is not set # CONFIG_RT_DEBUG_INIT_CONFIG is not set @@ -50,7 +53,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 @@ -63,7 +65,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 @@ -75,10 +76,9 @@ CONFIG_RT_USING_CONSOLE=y CONFIG_RT_CONSOLEBUF_SIZE=128 CONFIG_RT_CONSOLE_DEVICE_NAME="uart0" # 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 @@ -92,7 +92,6 @@ CONFIG_RT_MAIN_THREAD_PRIORITY=10 # C++ features # # CONFIG_RT_USING_CPLUSPLUS is not set -# end of C++ features # # Command shell @@ -112,13 +111,11 @@ 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 # # CONFIG_RT_USING_DFS is not set -# end of Device virtual file system # # Device Drivers @@ -158,20 +155,17 @@ CONFIG_RT_USING_PIN=y # # 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=y +# CONFIG_RT_USING_LIBC is not set # CONFIG_RT_USING_PTHREADS is not set CONFIG_RT_LIBC_USING_TIME=y -# CONFIG_RT_USING_MODULE is not set CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 -# end of POSIX layer and C standard library # # Network @@ -181,32 +175,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 @@ -216,14 +204,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 @@ -258,17 +243,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 @@ -290,8 +270,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 @@ -325,7 +303,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 @@ -335,7 +312,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 @@ -344,22 +320,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 @@ -376,8 +349,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 @@ -420,7 +391,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 @@ -433,7 +403,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 @@ -444,8 +413,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 @@ -479,7 +446,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 @@ -555,7 +521,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 @@ -569,7 +535,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 @@ -582,7 +547,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 @@ -596,8 +560,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 @@ -627,8 +589,6 @@ 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 # # Hardware Drivers Config @@ -639,7 +599,6 @@ CONFIG_SOC_GD32VF103V=y # Onboard Peripheral Drivers # CONFIG_BSP_USING_USART=y -# end of Onboard Peripheral Drivers # # On-chip Peripheral Drivers @@ -647,11 +606,8 @@ CONFIG_BSP_USING_USART=y CONFIG_BSP_USING_GPIO=y CONFIG_BSP_USING_UART=y CONFIG_BSP_USING_UART0=y -# end of On-chip Peripheral Drivers # # Board extended module Drivers # -# end of Hardware Drivers Config - CONFIG_SOC_GD32VF103=y diff --git a/bsp/gd32vf103v-eval/SConscript b/bsp/gd32vf103v-eval/SConscript index 534ec8eb5a..9044e1496c 100644 --- a/bsp/gd32vf103v-eval/SConscript +++ b/bsp/gd32vf103v-eval/SConscript @@ -13,6 +13,4 @@ for d in list: if os.path.isfile(os.path.join(path, 'SConscript')): objs = objs + SConscript(os.path.join(d, 'SConscript')) -group = DefineGroup('', src, depend = [''], CPPPATH = []) -#objs += group Return('objs') diff --git a/bsp/gd32vf103v-eval/libraries/SConscript b/bsp/gd32vf103v-eval/libraries/SConscript index 932d0eef17..d8ee90a4ae 100644 --- a/bsp/gd32vf103v-eval/libraries/SConscript +++ b/bsp/gd32vf103v-eval/libraries/SConscript @@ -15,11 +15,8 @@ src += ['GD32VF103_standard_peripheral/system_gd32vf103.c', CPPPATH = [ cwd + '/GD32VF103_standard_peripheral/Include', cwd + '/GD32VF103_standard_peripheral', - cwd + '/n22/drivers', - cwd + '/n22/stubs'] + cwd + '/n22/drivers'] -CPPDEFINES = [] - -group = DefineGroup('Libraries', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES=CPPDEFINES) +group = DefineGroup('Libraries', src, depend = [''], CPPPATH = CPPPATH) Return('group') diff --git a/bsp/gd32vf103v-eval/libraries/n22/env_Eclipse/handlers.c b/bsp/gd32vf103v-eval/libraries/n22/env_Eclipse/handlers.c index ed2ed78c98..5d147f288b 100644 --- a/bsp/gd32vf103v-eval/libraries/n22/env_Eclipse/handlers.c +++ b/bsp/gd32vf103v-eval/libraries/n22/env_Eclipse/handlers.c @@ -1,12 +1,12 @@ //See LICENSE for license details. #include #include -#include #include "riscv_encoding.h" #include "n22_func.h" +#include + __attribute__((weak)) uintptr_t handle_nmi() { - write(1, "nmi\n", 5); - _exit(1); + rt_kprintf("nmi\n"); return 0; } @@ -14,8 +14,7 @@ __attribute__((weak)) uintptr_t handle_trap(uintptr_t mcause, uintptr_t sp) { if (mcause == 0xFFF) { handle_nmi(); } - write(1, "trap\n", 5); - _exit(mcause); + rt_kprintf("trap\n"); return 0; } diff --git a/bsp/gd32vf103v-eval/libraries/n22/env_Eclipse/start.S b/bsp/gd32vf103v-eval/libraries/n22/env_Eclipse/start.S index 953adf3139..be68e7f08c 100644 --- a/bsp/gd32vf103v-eval/libraries/n22/env_Eclipse/start.S +++ b/bsp/gd32vf103v-eval/libraries/n22/env_Eclipse/start.S @@ -241,7 +241,7 @@ _start0800: li a0, 0 li a1, 0 call entry - tail exit + /* tail exit */ 1: j 1b diff --git a/bsp/gd32vf103v-eval/rtconfig.h b/bsp/gd32vf103v-eval/rtconfig.h index 505d712c46..a0f1bf728a 100644 --- a/bsp/gd32vf103v-eval/rtconfig.h +++ b/bsp/gd32vf103v-eval/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 */ @@ -21,7 +22,6 @@ /* kservice optimization */ -/* end of kservice optimization */ #define RT_DEBUG /* Inter-Thread communication */ @@ -31,14 +31,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 */ @@ -46,9 +44,7 @@ #define RT_USING_CONSOLE #define RT_CONSOLEBUF_SIZE 128 #define RT_CONSOLE_DEVICE_NAME "uart0" -/* end of Kernel Device Object */ #define RT_VER_NUM 0x40004 -/* end of RT-Thread Kernel */ /* RT-Thread Components */ @@ -59,7 +55,6 @@ /* C++ features */ -/* end of C++ features */ /* Command shell */ @@ -76,11 +71,9 @@ #define MSH_USING_BUILT_IN_COMMANDS #define FINSH_USING_DESCRIPTION #define FINSH_ARG_MAX 10 -/* end of Command shell */ /* Device virtual file system */ -/* end of Device virtual file system */ /* Device Drivers */ @@ -93,47 +86,34 @@ /* Using USB */ -/* end of Using USB */ -/* end of Device Drivers */ /* POSIX layer and C standard library */ -#define RT_USING_LIBC #define RT_LIBC_USING_TIME #define RT_LIBC_DEFAULT_TIMEZONE 8 -/* end of POSIX layer and C standard library */ /* 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 */ @@ -144,72 +124,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 */ /* Hardware Drivers Config */ @@ -218,18 +177,15 @@ /* Onboard Peripheral Drivers */ #define BSP_USING_USART -/* end of Onboard Peripheral Drivers */ /* On-chip Peripheral Drivers */ #define BSP_USING_GPIO #define BSP_USING_UART #define BSP_USING_UART0 -/* end of On-chip Peripheral Drivers */ /* Board extended module Drivers */ -/* end of Hardware Drivers Config */ #define SOC_GD32VF103 #endif diff --git a/bsp/lm3s8962/applications/startup.c b/bsp/lm3s8962/applications/startup.c index 0742c5453c..0769ffbde6 100644 --- a/bsp/lm3s8962/applications/startup.c +++ b/bsp/lm3s8962/applications/startup.c @@ -119,7 +119,7 @@ void rtthread_startup(void) #ifdef RT_USING_FINSH /* init finsh */ finsh_system_init(); -#if !defined(RT_USING_LIBC) && defined(RT_USING_DEVICE) +#if !defined(RT_LIBC_USING_FILEIO) && defined(RT_USING_DEVICE) finsh_set_device("uart1"); #endif #endif diff --git a/bsp/lpc1114/.config b/bsp/lpc1114/.config index 9896107a19..a7f5cf91e1 100644 --- a/bsp/lpc1114/.config +++ b/bsp/lpc1114/.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 @@ -23,8 +27,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 is not set # @@ -36,7 +39,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 @@ -49,7 +51,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 @@ -61,14 +62,12 @@ CONFIG_RT_USING_CONSOLE=y CONFIG_RT_CONSOLEBUF_SIZE=128 CONFIG_RT_CONSOLE_DEVICE_NAME="uart" # CONFIG_RT_PRINTF_LONGLONG is not set -# end of Kernel Device Object - CONFIG_RT_VER_NUM=0x40004 -# end of RT-Thread Kernel - CONFIG_ARCH_ARM=y +# CONFIG_RT_USING_CPU_FFS is not set CONFIG_ARCH_ARM_CORTEX_M=y CONFIG_ARCH_ARM_CORTEX_M0=y +# CONFIG_ARCH_CPU_STACK_GROWS_UPWARD is not set # # RT-Thread Components @@ -82,7 +81,6 @@ CONFIG_RT_MAIN_THREAD_PRIORITY=10 # C++ features # # CONFIG_RT_USING_CPLUSPLUS is not set -# end of C++ features # # Command shell @@ -102,13 +100,11 @@ 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 # # CONFIG_RT_USING_DFS is not set -# end of Device virtual file system # # Device Drivers @@ -148,20 +144,17 @@ CONFIG_RT_USING_PIN=y # # 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=y +# CONFIG_RT_USING_LIBC is not set # CONFIG_RT_USING_PTHREADS is not set CONFIG_RT_LIBC_USING_TIME=y -# CONFIG_RT_USING_MODULE is not set CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 -# end of POSIX layer and C standard library # # Network @@ -171,32 +164,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 @@ -206,16 +193,12 @@ 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 - # CONFIG_RT_USING_LWP is not set -# end of RT-Thread Components # # RT-Thread Utestcases # # CONFIG_RT_USING_UTESTCASES is not set -# end of RT-Thread Utestcases # # RT-Thread online packages @@ -250,17 +233,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 @@ -282,8 +260,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 @@ -317,7 +293,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 @@ -327,7 +302,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 @@ -336,22 +310,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 @@ -368,8 +339,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 @@ -412,7 +381,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 @@ -425,7 +393,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 @@ -436,8 +403,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 @@ -471,7 +436,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 @@ -547,7 +511,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 @@ -561,7 +525,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 @@ -574,7 +537,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 @@ -588,8 +550,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 @@ -619,7 +579,4 @@ 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_LPC1114=y diff --git a/bsp/lpc1114/rtconfig.h b/bsp/lpc1114/rtconfig.h index 152ac5149e..17d3182f38 100644 --- a/bsp/lpc1114/rtconfig.h +++ b/bsp/lpc1114/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 */ @@ -14,7 +15,6 @@ /* kservice optimization */ -/* end of kservice optimization */ /* Inter-Thread communication */ @@ -23,14 +23,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 */ @@ -38,9 +36,7 @@ #define RT_USING_CONSOLE #define RT_CONSOLEBUF_SIZE 128 #define RT_CONSOLE_DEVICE_NAME "uart" -/* end of Kernel Device Object */ #define RT_VER_NUM 0x40004 -/* end of RT-Thread Kernel */ #define ARCH_ARM #define ARCH_ARM_CORTEX_M #define ARCH_ARM_CORTEX_M0 @@ -54,7 +50,6 @@ /* C++ features */ -/* end of C++ features */ /* Command shell */ @@ -71,11 +66,9 @@ #define MSH_USING_BUILT_IN_COMMANDS #define FINSH_USING_DESCRIPTION #define FINSH_ARG_MAX 10 -/* end of Command shell */ /* Device virtual file system */ -/* end of Device virtual file system */ /* Device Drivers */ @@ -88,47 +81,34 @@ /* Using USB */ -/* end of Using USB */ -/* end of Device Drivers */ /* POSIX layer and C standard library */ -#define RT_USING_LIBC #define RT_LIBC_USING_TIME #define RT_LIBC_DEFAULT_TIMEZONE 8 -/* end of POSIX layer and C standard library */ /* 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 */ @@ -139,72 +119,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_LPC1114 #endif diff --git a/components/dfs/src/dfs.c b/components/dfs/src/dfs.c index fa93afd749..8cf642a2f9 100644 --- a/components/dfs/src/dfs.c +++ b/components/dfs/src/dfs.c @@ -18,7 +18,7 @@ #include #endif -#ifdef RT_USING_LIBC +#ifdef RT_LIBC_USING_FILEIO #include #endif @@ -216,7 +216,7 @@ struct dfs_fd *fd_get(int fd) struct dfs_fd *d; struct dfs_fdtable *fdt; -#ifdef RT_USING_LIBC +#ifdef RT_LIBC_USING_FILEIO if ((0 <= fd) && (fd <= 2)) fd = libc_stdio_get_console(); #endif diff --git a/components/finsh/shell.c b/components/finsh/shell.c index 292ea588cf..16aaaac27b 100644 --- a/components/finsh/shell.c +++ b/components/finsh/shell.c @@ -145,7 +145,7 @@ void finsh_set_prompt_mode(rt_uint32_t prompt_mode) int finsh_getchar(void) { #ifdef RT_USING_DEVICE -#ifdef RT_USING_LIBC +#ifdef RT_LIBC_USING_FILEIO return getchar(); #else char ch = 0; @@ -163,14 +163,14 @@ int finsh_getchar(void) rt_sem_take(&shell->rx_sem, RT_WAITING_FOREVER); return ch; -#endif /* RT_USING_LIBC */ +#endif /* RT_LIBC_USING_FILEIO */ #else extern char rt_hw_console_getchar(void); return rt_hw_console_getchar(); #endif /* RT_USING_DEVICE */ } -#if !defined(RT_USING_LIBC) && defined(RT_USING_DEVICE) +#if !defined(RT_LIBC_USING_FILEIO) && defined(RT_USING_DEVICE) static rt_err_t finsh_rx_ind(rt_device_t dev, rt_size_t size) { RT_ASSERT(shell != RT_NULL); @@ -436,7 +436,7 @@ void finsh_thread_entry(void *parameter) shell->echo_mode = 0; #endif -#if !defined(RT_USING_LIBC) && defined(RT_USING_DEVICE) +#if !defined(RT_LIBC_USING_FILEIO) && defined(RT_USING_DEVICE) /* set console device as shell device */ if (shell->device == RT_NULL) { diff --git a/components/finsh/shell.h b/components/finsh/shell.h index 598596ce00..6082c77fd5 100644 --- a/components/finsh/shell.h +++ b/components/finsh/shell.h @@ -78,7 +78,7 @@ struct finsh_shell rt_uint16_t line_position; rt_uint16_t line_curpos; -#if !defined(RT_USING_LIBC) && defined(RT_USING_DEVICE) +#if !defined(RT_LIBC_USING_FILEIO) && defined(RT_USING_DEVICE) rt_device_t device; #endif diff --git a/components/libc/Kconfig b/components/libc/Kconfig index 812b1ce48c..b2af15e841 100644 --- a/components/libc/Kconfig +++ b/components/libc/Kconfig @@ -2,18 +2,49 @@ menu "POSIX layer and C standard library" config RT_USING_LIBC bool "Enable libc APIs from toolchain" - select RT_USING_DFS - select RT_USING_POSIX default y +if RT_USING_LIBC + config RT_LIBC_USING_TIME + default y + + config RT_LIBC_USING_FILEIO + bool "Enable libc with file operation, eg.fopen/fwrite/fread/getchar" + select RT_USING_DFS + select RT_USING_POSIX + default n + + config RT_USING_MODULE + bool "Enable dynamic module with dlopen/dlsym/dlclose feature" + default n + + if RT_USING_MODULE + config RT_USING_CUSTOM_DLMODULE + bool "Enable load dynamic module by custom" + default n + endif +endif + +if RT_USING_LIBC != y + config RT_LIBC_USING_TIME + bool "Enable time functions without compiler's libc" + default y +endif + +config RT_LIBC_DEFAULT_TIMEZONE + depends on (RT_LIBC_USING_TIME || RT_USING_LIBC) + int "Set the default time zone (UTC+)" + range -12 12 + default 8 + config RT_USING_PTHREADS bool "Enable pthreads APIs" default n if RT_USING_PTHREADS config PTHREAD_NUM_MAX - int "Maximum number of pthreads" - default 8 + int "Maximum number of pthreads" + default 8 endif if RT_USING_DFS @@ -42,32 +73,4 @@ if RT_USING_DFS endif -if RT_USING_LIBC - config RT_LIBC_USING_TIME - default y - - config RT_USING_MODULE - bool "Enable dynamic module with dlopen/dlsym/dlclose feature" - default n - - if RT_USING_MODULE - config RT_USING_CUSTOM_DLMODULE - bool "Enable load dynamic module by custom" - default n - endif - -endif - -if RT_USING_LIBC != y - config RT_LIBC_USING_TIME - bool "Enable time functions without compiler's libc" - default y -endif - -config RT_LIBC_DEFAULT_TIMEZONE - depends on (RT_LIBC_USING_TIME || RT_USING_LIBC) - int "Set the default time zone (UTC+)" - range -12 12 - default 8 - endmenu diff --git a/components/libc/compilers/armlibc/SConscript b/components/libc/compilers/armlibc/SConscript index 52f7a6d93a..d77a7c69d5 100644 --- a/components/libc/compilers/armlibc/SConscript +++ b/components/libc/compilers/armlibc/SConscript @@ -8,9 +8,6 @@ group = [] CPPPATH = [cwd] CPPDEFINES = ['RT_USING_ARM_LIBC'] -if GetDepend('RT_USING_DFS') == False: - SrcRemove(src, ['stdio.c']) - if GetDepend('RT_USING_MODULE') == False: SrcRemove(src, ['libc_syms.c']) diff --git a/components/libc/compilers/armlibc/libc.c b/components/libc/compilers/armlibc/libc.c index 889c687309..bc09759fef 100644 --- a/components/libc/compilers/armlibc/libc.c +++ b/components/libc/compilers/armlibc/libc.c @@ -7,29 +7,24 @@ * Date Author Notes * 2017/10/15 bernard the first version */ -#include #include +#include #include "libc.h" - #ifdef RT_USING_PTHREADS #include #endif int libc_system_init(void) { -#if defined(RT_USING_DFS) & defined(RT_USING_DFS_DEVFS) +#ifdef RT_USING_POSIX rt_device_t dev_console; dev_console = rt_console_get_device(); if (dev_console) { - #if defined(RT_USING_POSIX) libc_stdio_set_console(dev_console->parent.name, O_RDWR); - #else - libc_stdio_set_console(dev_console->parent.name, O_WRONLY); - #endif } -#endif +#endif /* RT_USING_POSIX */ #if defined RT_USING_PTHREADS && !defined RT_USING_COMPONENTS_INIT pthread_system_init(); diff --git a/components/libc/compilers/armlibc/libc.h b/components/libc/compilers/armlibc/libc.h index 5c1613728e..f81380bf78 100644 --- a/components/libc/compilers/armlibc/libc.h +++ b/components/libc/compilers/armlibc/libc.h @@ -10,13 +10,17 @@ #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 } diff --git a/components/libc/compilers/armlibc/stdio.c b/components/libc/compilers/armlibc/stdio.c index 7dd9dbfe3f..e5db167ea4 100644 --- a/components/libc/compilers/armlibc/stdio.c +++ b/components/libc/compilers/armlibc/stdio.c @@ -7,16 +7,17 @@ * Date Author Notes * 2017/10/15 bernard implement stdio for armcc. */ +#include +#ifdef RT_USING_POSIX #include #include #include -#include #include "libc.h" -#if defined(RT_USING_DFS) && defined(RT_USING_DFS_DEVFS) -#include +#include +#include #define STDIO_DEVICE_NAME_MAX 32 @@ -48,4 +49,4 @@ int libc_stdio_get_console(void) return std_fd; } -#endif +#endif /* RT_USING_POSIX */ diff --git a/components/libc/compilers/armlibc/syscalls.c b/components/libc/compilers/armlibc/syscalls.c index ccdcfc86ea..ecb1a9da5a 100644 --- a/components/libc/compilers/armlibc/syscalls.c +++ b/components/libc/compilers/armlibc/syscalls.c @@ -14,16 +14,15 @@ * 2020-02-13 Meco Man re-implement exit() and abort() * 2020-02-14 Meco Man implement _sys_tmpnam() */ - #include #include #include #include "libc.h" -#ifdef RT_USING_DFS -#include -#endif +#include +#include +#include #define DBG_TAG "armlibc.syscalls" #define DBG_LVL DBG_INFO @@ -55,7 +54,7 @@ const char __stderr_name[] = "STDERR"; */ FILEHANDLE _sys_open(const char *name, int openmode) { -#ifdef RT_USING_DFS +#ifdef RT_LIBC_USING_FILEIO int fd; int mode = O_RDONLY; #endif @@ -68,8 +67,8 @@ FILEHANDLE _sys_open(const char *name, int openmode) if (strcmp(name, __stderr_name) == 0) return (STDERR); -#ifndef RT_USING_DFS - return -1; +#ifndef RT_LIBC_USING_FILEIO + return 0; /* error */ #else /* Correct openmode from fopen to open */ if (openmode & OPEN_PLUS) @@ -99,21 +98,22 @@ FILEHANDLE _sys_open(const char *name, int openmode) fd = open(name, mode, 0); if (fd < 0) - return -1; + return 0; /* error */ else return fd; -#endif +#endif /* RT_LIBC_USING_FILEIO */ } int _sys_close(FILEHANDLE fh) { -#ifndef RT_USING_DFS - return 0; -#else - if (fh <= STDERR) return 0; +#ifdef RT_LIBC_USING_FILEIO + if (fh <= STDERR) + return 0; /* error */ return close(fh); -#endif +#else + return 0; +#endif /* RT_LIBC_USING_FILEIO */ } /* @@ -143,13 +143,11 @@ int _sys_close(FILEHANDLE fh) */ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode) { -#ifdef RT_USING_DFS +#ifdef RT_LIBC_USING_FILEIO int size; -#endif if (fh == STDIN) { -#ifdef RT_USING_POSIX if (libc_stdio_get_console() < 0) { LOG_W("Do not invoke standard output before initializing libc"); @@ -157,25 +155,20 @@ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode) } size = read(STDIN_FILENO, buf, len); return len - size; -#else - /* no stdin */ - return -1; -#endif } else if ((fh == STDOUT) || (fh == STDERR)) { - return -1; + return 0; /* error */ } -#ifndef RT_USING_DFS - return 0; -#else size = read(fh, buf, len); if (size >= 0) return len - size; else - return -1; -#endif + return 0; /* error */ +#else + return 0; /* error */ +#endif /* RT_LIBC_USING_FILEIO */ } /* @@ -185,16 +178,13 @@ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode) */ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode) { -#ifdef RT_USING_DFS +#ifdef RT_LIBC_USING_FILEIO int size; -#endif +#endif /* RT_LIBC_USING_FILEIO */ if ((fh == STDOUT) || (fh == STDERR)) { -#if !defined(RT_USING_CONSOLE) || !defined(RT_USING_DEVICE) - return 0; -#else -#ifdef RT_USING_POSIX +#ifdef RT_LIBC_USING_FILEIO if (libc_stdio_get_console() < 0) { LOG_W("Do not invoke standard input before initializing libc"); @@ -202,31 +192,29 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode) } size = write(STDOUT_FILENO, buf, len); return len - size; -#else +#elif defined(RT_USING_CONSOLE) if (rt_console_get_device()) { rt_device_write(rt_console_get_device(), -1, buf, len); - return 0; } - return -1; -#endif -#endif + return 0; /* error */ +#endif /* RT_LIBC_USING_FILEIO */ } else if (fh == STDIN) { - return -1; + return 0; /* error */ } -#ifndef RT_USING_DFS - return 0; -#else +#ifdef RT_LIBC_USING_FILEIO size = write(fh, buf, len); if (size >= 0) return len - size; else - return -1; -#endif + return 0; /* error */ +#else + return 0; +#endif /* RT_LIBC_USING_FILEIO */ } /* @@ -235,16 +223,15 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode) */ int _sys_seek(FILEHANDLE fh, long pos) { +#ifdef RT_LIBC_USING_FILEIO if (fh < STDERR) - return -1; - -#ifndef RT_USING_DFS - return -1; -#else + return 0; /* error */ /* position is relative to the start of file fh */ return lseek(fh, pos, 0); -#endif +#else + return 0; /* error */ +#endif /* RT_LIBC_USING_FILEIO */ } /** @@ -270,7 +257,7 @@ void _ttywrch(int ch) c = (char)ch; rt_kprintf(&c); -#endif +#endif /* RT_USING_CONSOLE */ } /* for exit() and abort() */ @@ -289,17 +276,17 @@ RT_WEAK void _sys_exit(int return_code) */ long _sys_flen(FILEHANDLE fh) { -#ifdef RT_USING_DFS +#ifdef RT_LIBC_USING_FILEIO struct stat stat; if (fh < STDERR) - return -1; + return 0; /* error */ fstat(fh, &stat); return stat.st_size; #else - return -1; -#endif + return 0; +#endif /* RT_LIBC_USING_FILEIO */ } int _sys_istty(FILEHANDLE fh) @@ -312,11 +299,11 @@ int _sys_istty(FILEHANDLE fh) int remove(const char *filename) { -#ifndef RT_USING_DFS - return -1; -#else +#ifdef RT_LIBC_USING_FILEIO return unlink(filename); -#endif +#else + return 0; /* error */ +#endif /* RT_LIBC_USING_FILEIO */ } #ifdef __MICROLIB @@ -324,28 +311,32 @@ int remove(const char *filename) int fputc(int c, FILE *f) { +#ifdef RT_USING_CONSOLE char ch[2] = {0}; ch[0] = c; rt_kprintf(&ch[0]); return 1; +#else + return 0; /* error */ +#endif /* RT_USING_CONSOLE */ } int fgetc(FILE *f) { -#ifdef RT_USING_POSIX +#ifdef RT_LIBC_USING_FILEIO char ch; if (libc_stdio_get_console() < 0) { LOG_W("Do not invoke standard output before initializing libc"); - return -1; + return 0; } if(read(STDIN_FILENO, &ch, 1) == 1) return ch; -#endif - - return -1; +#endif /* RT_LIBC_USING_FILEIO */ + return 0; /* error */ } -#endif + +#endif /* __MICROLIB */ 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'] diff --git a/components/libc/compilers/dlib/SConscript b/components/libc/compilers/dlib/SConscript index 75a5812fab..3eee0e0184 100644 --- a/components/libc/compilers/dlib/SConscript +++ b/components/libc/compilers/dlib/SConscript @@ -11,7 +11,7 @@ CPPDEFINES = ['RT_USING_DLIBC'] if rtconfig.PLATFORM == 'iar': - if GetDepend('RT_USING_DFS'): + if GetDepend('RT_LIBC_USING_FILEIO'): from distutils.version import LooseVersion from iar import IARVersion @@ -20,7 +20,6 @@ if rtconfig.PLATFORM == 'iar': 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'], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES) Return('group') diff --git a/components/libc/compilers/dlib/libc.c b/components/libc/compilers/dlib/libc.c index f540ac955f..f6e504bdae 100644 --- a/components/libc/compilers/dlib/libc.c +++ b/components/libc/compilers/dlib/libc.c @@ -7,29 +7,24 @@ * Date Author Notes * 2017/10/15 bernard the first version */ -#include #include +#include #include "libc.h" - #ifdef RT_USING_PTHREADS #include #endif int libc_system_init(void) { -#if defined(RT_USING_DFS) && defined(RT_USING_DFS_DEVFS) +#ifdef RT_USING_POSIX rt_device_t dev_console; dev_console = rt_console_get_device(); if (dev_console) { - #if defined(RT_USING_POSIX) libc_stdio_set_console(dev_console->parent.name, O_RDWR); - #else - libc_stdio_set_console(dev_console->parent.name, O_WRONLY); - #endif } -#endif +#endif /* RT_USING_POSIX */ #if defined (RT_USING_PTHREADS) && !defined (RT_USING_COMPONENTS_INIT) pthread_system_init(); @@ -38,4 +33,3 @@ int libc_system_init(void) return 0; } INIT_COMPONENT_EXPORT(libc_system_init); - diff --git a/components/libc/compilers/dlib/libc.h b/components/libc/compilers/dlib/libc.h index 9643c1161f..292dbde973 100644 --- a/components/libc/compilers/dlib/libc.h +++ b/components/libc/compilers/dlib/libc.h @@ -16,8 +16,10 @@ 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 } diff --git a/components/libc/compilers/dlib/stdio.c b/components/libc/compilers/dlib/stdio.c index ed3f5dfef9..fea98aedd5 100644 --- a/components/libc/compilers/dlib/stdio.c +++ b/components/libc/compilers/dlib/stdio.c @@ -7,17 +7,17 @@ * Date Author Notes * 2017/10/15 bernard implement stdio for IAR dlib. */ +#include + +#ifdef RT_USING_POSIX #include #include #include - -#include +#include +#include #include "libc.h" -#if defined(RT_USING_DFS) && defined(RT_USING_DFS_DEVFS) -#include - #define STDIO_DEVICE_NAME_MAX 32 static int std_fd = -1; @@ -46,4 +46,4 @@ int libc_stdio_get_console(void) { return std_fd; } -#endif +#endif /* RT_USING_POSIX */ diff --git a/components/libc/compilers/dlib/syscall_close.c b/components/libc/compilers/dlib/syscall_close.c index 7ed1cc2f2d..bafe21aa4b 100644 --- a/components/libc/compilers/dlib/syscall_close.c +++ b/components/libc/compilers/dlib/syscall_close.c @@ -8,10 +8,8 @@ * 2015-01-28 Bernard first version */ #include -#ifdef RT_USING_DFS -#include -#endif #include +#include #pragma module_name = "?__close" int __close(int handle) @@ -20,10 +18,9 @@ int __close(int handle) handle == _LLIO_STDERR || handle == _LLIO_STDIN) return _LLIO_ERROR; - -#ifdef RT_USING_DFS +#ifdef RT_LIBC_USING_FILEIO return close(handle); #else - return 0; -#endif + return _LLIO_ERROR; +#endif /* RT_LIBC_USING_FILEIO */ } diff --git a/components/libc/compilers/dlib/syscall_lseek.c b/components/libc/compilers/dlib/syscall_lseek.c index 47a069bf0a..4a3a5c6a46 100644 --- a/components/libc/compilers/dlib/syscall_lseek.c +++ b/components/libc/compilers/dlib/syscall_lseek.c @@ -8,10 +8,8 @@ * 2015-01-28 Bernard first version */ #include -#ifdef RT_USING_DFS -#include -#endif #include +#include #pragma module_name = "?__lseek" long __lseek(int handle, long offset, int whence) @@ -20,8 +18,7 @@ long __lseek(int handle, long offset, int whence) handle == _LLIO_STDERR || handle == _LLIO_STDIN) return _LLIO_ERROR; - -#ifdef RT_USING_DFS +#ifdef RT_LIBC_USING_FILEIO return lseek(handle, offset, whence); #else return _LLIO_ERROR; diff --git a/components/libc/compilers/dlib/syscall_open.c b/components/libc/compilers/dlib/syscall_open.c index 37bfcecb47..891b9afe58 100644 --- a/components/libc/compilers/dlib/syscall_open.c +++ b/components/libc/compilers/dlib/syscall_open.c @@ -10,17 +10,13 @@ #include #include -#ifdef RT_USING_DFS -#include -#endif +#include #pragma module_name = "?__open" int __open(const char *filename, int mode) { -#ifndef RT_USING_DFS - return _LLIO_ERROR; -#else +#ifdef RT_LIBC_USING_FILEIO int handle; int open_mode = O_RDONLY; @@ -70,5 +66,7 @@ int __open(const char *filename, int mode) return _LLIO_ERROR; return handle; -#endif +#else + return _LLIO_ERROR; +#endif /* RT_LIBC_USING_FILEIO */ } diff --git a/components/libc/compilers/dlib/syscall_read.c b/components/libc/compilers/dlib/syscall_read.c index ae980be6ca..f65b502966 100644 --- a/components/libc/compilers/dlib/syscall_read.c +++ b/components/libc/compilers/dlib/syscall_read.c @@ -9,10 +9,8 @@ */ #include -#ifdef RT_USING_DFS -#include -#endif #include +#include #include "libc.h" #define DBG_TAG "dlib.syscall_read" @@ -22,32 +20,26 @@ #pragma module_name = "?__read" size_t __read(int handle, unsigned char *buf, size_t len) { -#ifdef RT_USING_DFS +#ifdef RT_LIBC_USING_FILEIO int size; -#endif if (handle == _LLIO_STDIN) { -#ifdef RT_USING_POSIX if (libc_stdio_get_console() < 0) { LOG_W("Do not invoke standard input before initializing libc"); return 0; } return read(STDIN_FILENO, buf, len); -#else - return _LLIO_ERROR; -#endif } else if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR)) { return _LLIO_ERROR; } -#ifndef RT_USING_DFS - return _LLIO_ERROR; -#else size = read(handle, buf, len); return size; -#endif +#else + return _LLIO_ERROR; +#endif /* RT_LIBC_USING_FILEIO */ } diff --git a/components/libc/compilers/dlib/syscall_remove.c b/components/libc/compilers/dlib/syscall_remove.c index 7d74236f4c..05bfbb67ae 100644 --- a/components/libc/compilers/dlib/syscall_remove.c +++ b/components/libc/compilers/dlib/syscall_remove.c @@ -8,17 +8,15 @@ * 2015-01-28 Bernard first version */ #include -#ifdef RT_USING_DFS -#include -#endif #include +#include #pragma module_name = "?remove" int remove(const char *val) { -#ifndef RT_USING_DFS - return -1; -#else +#ifdef RT_USING_POSIX return unlink(val); -#endif +#else + return -1; +#endif /* RT_USING_POSIX */ } diff --git a/components/libc/compilers/dlib/syscall_write.c b/components/libc/compilers/dlib/syscall_write.c index ffee51882d..af47d64a3e 100644 --- a/components/libc/compilers/dlib/syscall_write.c +++ b/components/libc/compilers/dlib/syscall_write.c @@ -9,10 +9,8 @@ */ #include -#ifdef RT_USING_DFS -#include -#endif #include +#include #include "libc.h" #define DBG_TAG "dlib.syscall_write" @@ -23,24 +21,20 @@ size_t __write(int handle, const unsigned char *buf, size_t len) { -#ifdef RT_USING_DFS +#ifdef RT_LIBC_USING_FILEIO int size; -#endif +#endif /* RT_LIBC_USING_FILEIO */ if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR)) { -#ifndef RT_USING_CONSOLE - return _LLIO_ERROR; -#else - -#ifdef RT_USING_POSIX +#ifdef RT_LIBC_USING_FILEIO if (libc_stdio_get_console() < 0) { LOG_W("Do not invoke standard output before initializing libc"); return 0; } return write(STDOUT_FILENO, (void*)buf, len); -#else +#elif defined(RT_USING_CONSOLE) rt_device_t console_device; console_device = rt_console_get_device(); @@ -50,19 +44,19 @@ size_t __write(int handle, const unsigned char *buf, size_t len) } return len; -#endif -#endif +#else + return _LLIO_ERROR; +#endif /* RT_LIBC_USING_FILEIO */ } else if (handle == _LLIO_STDIN) { return _LLIO_ERROR; } -#ifndef RT_USING_DFS - return _LLIO_ERROR; -#else +#ifdef RT_LIBC_USING_FILEIO size = write(handle, buf, len); return size; -#endif +#else + return _LLIO_ERROR; +#endif /* RT_LIBC_USING_FILEIO */ } - diff --git a/components/libc/compilers/gcc/newlib/libc.c b/components/libc/compilers/gcc/newlib/libc.c index 9834a9a015..943d127eed 100644 --- a/components/libc/compilers/gcc/newlib/libc.c +++ b/components/libc/compilers/gcc/newlib/libc.c @@ -12,34 +12,23 @@ #include #include #include - #include "libc.h" #ifdef RT_USING_PTHREADS #include #endif -int _EXFUN(putenv,(char *__string)); - int libc_system_init(void) { -#if defined(RT_USING_DFS) & defined(RT_USING_DFS_DEVFS) & defined(RT_USING_CONSOLE) +#ifdef RT_LIBC_USING_FILEIO rt_device_t dev_console; dev_console = rt_console_get_device(); if (dev_console) { - #if defined(RT_USING_POSIX) libc_stdio_set_console(dev_console->parent.name, O_RDWR); - #else - libc_stdio_set_console(dev_console->parent.name, O_WRONLY); - #endif } - - /* set PATH and HOME */ - putenv("PATH=/bin"); - putenv("HOME=/home"); -#endif +#endif /* RT_LIBC_USING_FILEIO */ #if defined RT_USING_PTHREADS && !defined RT_USING_COMPONENTS_INIT pthread_system_init(); diff --git a/components/libc/compilers/gcc/newlib/libc.h b/components/libc/compilers/gcc/newlib/libc.h index c470698aa6..fdb0a45472 100644 --- a/components/libc/compilers/gcc/newlib/libc.h +++ b/components/libc/compilers/gcc/newlib/libc.h @@ -10,16 +10,15 @@ #ifndef __RTT_LIBC_H__ #define __RTT_LIBC_H__ -#ifndef _EXFUN -#define _EXFUN(name, proto) name proto -#endif - #ifdef __cplusplus extern "C" { #endif + int libc_system_init(void); +#ifdef RT_LIBC_USING_FILEIO int libc_stdio_get_console(void); int libc_stdio_set_console(const char* device_name, int mode); +#endif /* RT_LIBC_USING_FILEIO */ #ifdef __cplusplus } diff --git a/components/libc/compilers/gcc/newlib/stdio.c b/components/libc/compilers/gcc/newlib/stdio.c index 1875d50e3f..5f9dd2de4c 100644 --- a/components/libc/compilers/gcc/newlib/stdio.c +++ b/components/libc/compilers/gcc/newlib/stdio.c @@ -7,16 +7,16 @@ * Date Author Notes * 2017/10/15 bernard the first version */ +#include + +#ifdef RT_LIBC_USING_FILEIO #include #include #include -#include #include "libc.h" #define STDIO_DEVICE_NAME_MAX 32 -int _EXFUN(fileno, (FILE *)); - static FILE* std_console = NULL; int libc_stdio_set_console(const char* device_name, int mode) @@ -79,3 +79,5 @@ int libc_stdio_get_console(void) else return -1; } + +#endif /* RT_LIBC_USING_FILEIO */ diff --git a/components/libc/compilers/gcc/newlib/syscalls.c b/components/libc/compilers/gcc/newlib/syscalls.c index f5a2c16ecc..6cb60e1776 100644 --- a/components/libc/compilers/gcc/newlib/syscalls.c +++ b/components/libc/compilers/gcc/newlib/syscalls.c @@ -13,9 +13,16 @@ #include #include +#include #include +#include #include #include +#include +#include "libc.h" +#ifdef RT_USING_MODULE +#include +#endif #define DBG_TAG "newlib.syscalls" #define DBG_LVL DBG_INFO @@ -83,18 +90,8 @@ void __libc_init_array(void) } #ifdef RT_USING_LIBC -#include -#include -#include "libc.h" -#ifdef RT_USING_DFS -#include -#endif -#ifdef RT_USING_MODULE -#include -#endif /* Reentrant versions of system calls. */ - #ifndef _REENT_ONLY int *__errno () { @@ -109,39 +106,29 @@ int _getpid_r(struct _reent *ptr) int _close_r(struct _reent *ptr, int fd) { -#ifndef RT_USING_DFS - /* return "not supported" */ - ptr->_errno = ENOTSUP; - return -1; -#else return close(fd); -#endif } int _execve_r(struct _reent *ptr, const char * name, char *const *argv, char *const *env) { - /* return "not supported" */ ptr->_errno = ENOTSUP; return -1; } int _fcntl_r(struct _reent *ptr, int fd, int cmd, int arg) { - /* return "not supported" */ ptr->_errno = ENOTSUP; return -1; } int _fork_r(struct _reent *ptr) { - /* return "not supported" */ ptr->_errno = ENOTSUP; return -1; } int _fstat_r(struct _reent *ptr, int fd, struct stat *pstat) { - /* return "not supported" */ ptr->_errno = ENOTSUP; return -1; } @@ -160,67 +147,74 @@ int _isatty_r(struct _reent *ptr, int fd) int _kill_r(struct _reent *ptr, int pid, int sig) { - /* return "not supported" */ ptr->_errno = ENOTSUP; return -1; } int _link_r(struct _reent *ptr, const char *old, const char *new) { - /* return "not supported" */ ptr->_errno = ENOTSUP; return -1; } -_off_t _lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence) +int _wait_r(struct _reent *ptr, int *status) { -#ifndef RT_USING_DFS - /* return "not supported" */ ptr->_errno = ENOTSUP; return -1; -#else +} + +mode_t umask(mode_t mask) +{ + return 022; +} + +int flock(int fd, int operation) +{ + return 0; +} + +_off_t _lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence) +{ +#ifdef RT_LIBC_USING_FILEIO _off_t rc; rc = lseek(fd, pos, whence); return rc; -#endif +#else + ptr->_errno = ENOTSUP; + return -1; +#endif /* RT_LIBC_USING_FILEIO */ } int _mkdir_r(struct _reent *ptr, const char *name, int mode) { -#ifndef RT_USING_DFS - /* return "not supported" */ - ptr->_errno = ENOTSUP; - return -1; -#else +#ifdef RT_LIBC_USING_FILEIO int rc; rc = mkdir(name, mode); return rc; -#endif +#else + ptr->_errno = ENOTSUP; + return -1; +#endif /* RT_LIBC_USING_FILEIO */ } int _open_r(struct _reent *ptr, const char *file, int flags, int mode) { -#ifndef RT_USING_DFS - /* return "not supported" */ - ptr->_errno = ENOTSUP; - return -1; -#else +#ifdef RT_LIBC_USING_FILEIO int rc; rc = open(file, flags, mode); return rc; -#endif +#else + ptr->_errno = ENOTSUP; + return -1; +#endif /* RT_LIBC_USING_FILEIO */ } _ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes) { -#ifndef RT_USING_DFS - /* return "not supported" */ - ptr->_errno = ENOTSUP; - return -1; -#else +#ifdef RT_LIBC_USING_FILEIO _ssize_t rc; if (libc_stdio_get_console() < 0 && fd == STDIN_FILENO) { @@ -229,74 +223,51 @@ _ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes) } rc = read(fd, buf, nbytes); return rc; -#endif +#else + ptr->_errno = ENOTSUP; + return -1; +#endif /* RT_LIBC_USING_FILEIO */ } int _rename_r(struct _reent *ptr, const char *old, const char *new) { -#ifndef RT_USING_DFS - /* return "not supported" */ - ptr->_errno = ENOTSUP; - return -1; -#else +#ifdef RT_LIBC_USING_FILEIO int rc; rc = rename(old, new); return rc; -#endif +#else + ptr->_errno = ENOTSUP; + return -1; +#endif /* RT_LIBC_USING_FILEIO */ } int _stat_r(struct _reent *ptr, const char *file, struct stat *pstat) { -#ifndef RT_USING_DFS - /* return "not supported" */ - ptr->_errno = ENOTSUP; - return -1; -#else +#ifdef RT_LIBC_USING_FILEIO int rc; rc = stat(file, pstat); return rc; -#endif -} - -int _unlink_r(struct _reent *ptr, const char *file) -{ -#ifndef RT_USING_DFS - /* return "not supported" */ +#else ptr->_errno = ENOTSUP; return -1; -#else - return unlink(file); -#endif +#endif /* RT_LIBC_USING_FILEIO */ } -int _wait_r(struct _reent *ptr, int *status) +int _unlink_r(struct _reent *ptr, const char *file) { - /* return "not supported" */ +#ifdef RT_LIBC_USING_FILEIO + return unlink(file); +#else ptr->_errno = ENOTSUP; return -1; +#endif /* RT_LIBC_USING_FILEIO */ } _ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes) { -#ifndef RT_USING_DFS -#if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE) - if (STDOUT_FILENO == fd) - { - rt_device_t console; - - console = rt_console_get_device(); - if (console) return rt_device_write(console, -1, buf, nbytes); - } - - return 0; -#else - /* return "not supported" */ - ptr->_errno = ENOTSUP; - return -1; -#endif /*RT_USING_DEVICE*/ -#else +#ifdef RT_LIBC_USING_FILEIO _ssize_t rc; if (libc_stdio_get_console() < 0 && fd == STDOUT_FILENO) { @@ -305,7 +276,18 @@ _ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes) } rc = write(fd, buf, nbytes); return rc; -#endif +#elif defined(RT_USING_CONSOLE) + if (STDOUT_FILENO == fd) + { + rt_device_t console; + + console = rt_console_get_device(); + if (console) + return rt_device_write(console, -1, buf, nbytes); + } +#endif /* RT_LIBC_USING_FILEIO */ + ptr->_errno = ENOTSUP; + return -1; } /* for exit() and abort() */ @@ -316,16 +298,6 @@ __attribute__ ((noreturn)) void _exit (int status) while(1); } -mode_t umask(mode_t mask) -{ - return 022; -} - -int flock(int fd, int operation) -{ - return 0; -} - /* These functions are implemented and replaced by the 'common/time.c' file int _gettimeofday_r(struct _reent *ptr, struct timeval *__tp, void *__tzp); -- cgit v1.3.1 From 4b9fb8f39caae9057a494611e8dae70d2809512d Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Wed, 27 Oct 2021 14:42:25 -0400 Subject: [libc] 消除代码中依赖于RT_LIBC_USING_FILEIO的判断 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/armlibc/syscalls.c | 42 ++++++++++++------------ components/libc/compilers/dlib/SConscript | 2 +- components/libc/compilers/dlib/syscall_close.c | 4 +-- components/libc/compilers/dlib/syscall_lseek.c | 4 +-- components/libc/compilers/dlib/syscall_open.c | 4 +-- components/libc/compilers/dlib/syscall_read.c | 4 +-- components/libc/compilers/dlib/syscall_write.c | 12 +++---- components/libc/compilers/gcc/newlib/libc.h | 2 ++ components/libc/compilers/gcc/newlib/stdio.c | 43 ++++--------------------- components/libc/compilers/gcc/newlib/syscalls.c | 34 +++++++++---------- 10 files changed, 61 insertions(+), 90 deletions(-) (limited to 'components/libc/compilers/dlib/syscall_write.c') diff --git a/components/libc/compilers/armlibc/syscalls.c b/components/libc/compilers/armlibc/syscalls.c index ecb1a9da5a..3b40a5b7b5 100644 --- a/components/libc/compilers/armlibc/syscalls.c +++ b/components/libc/compilers/armlibc/syscalls.c @@ -54,7 +54,7 @@ const char __stderr_name[] = "STDERR"; */ FILEHANDLE _sys_open(const char *name, int openmode) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX int fd; int mode = O_RDONLY; #endif @@ -67,7 +67,7 @@ FILEHANDLE _sys_open(const char *name, int openmode) if (strcmp(name, __stderr_name) == 0) return (STDERR); -#ifndef RT_LIBC_USING_FILEIO +#ifndef RT_USING_POSIX return 0; /* error */ #else /* Correct openmode from fopen to open */ @@ -101,19 +101,19 @@ FILEHANDLE _sys_open(const char *name, int openmode) return 0; /* error */ else return fd; -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ } int _sys_close(FILEHANDLE fh) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX if (fh <= STDERR) return 0; /* error */ return close(fh); #else return 0; -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ } /* @@ -143,7 +143,7 @@ int _sys_close(FILEHANDLE fh) */ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX int size; if (fh == STDIN) @@ -168,7 +168,7 @@ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode) return 0; /* error */ #else return 0; /* error */ -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ } /* @@ -178,13 +178,13 @@ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode) */ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX int size; -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ if ((fh == STDOUT) || (fh == STDERR)) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX if (libc_stdio_get_console() < 0) { LOG_W("Do not invoke standard input before initializing libc"); @@ -199,14 +199,14 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode) } return 0; /* error */ -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ } else if (fh == STDIN) { return 0; /* error */ } -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX size = write(fh, buf, len); if (size >= 0) return len - size; @@ -214,7 +214,7 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode) return 0; /* error */ #else return 0; -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ } /* @@ -223,7 +223,7 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode) */ int _sys_seek(FILEHANDLE fh, long pos) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX if (fh < STDERR) return 0; /* error */ @@ -231,7 +231,7 @@ int _sys_seek(FILEHANDLE fh, long pos) return lseek(fh, pos, 0); #else return 0; /* error */ -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ } /** @@ -276,7 +276,7 @@ RT_WEAK void _sys_exit(int return_code) */ long _sys_flen(FILEHANDLE fh) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX struct stat stat; if (fh < STDERR) @@ -286,7 +286,7 @@ long _sys_flen(FILEHANDLE fh) return stat.st_size; #else return 0; -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ } int _sys_istty(FILEHANDLE fh) @@ -299,11 +299,11 @@ int _sys_istty(FILEHANDLE fh) int remove(const char *filename) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX return unlink(filename); #else return 0; /* error */ -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ } #ifdef __MICROLIB @@ -324,7 +324,7 @@ int fputc(int c, FILE *f) int fgetc(FILE *f) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX char ch; if (libc_stdio_get_console() < 0) @@ -335,7 +335,7 @@ int fgetc(FILE *f) if(read(STDIN_FILENO, &ch, 1) == 1) return ch; -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ return 0; /* error */ } diff --git a/components/libc/compilers/dlib/SConscript b/components/libc/compilers/dlib/SConscript index 3eee0e0184..348cbf311f 100644 --- a/components/libc/compilers/dlib/SConscript +++ b/components/libc/compilers/dlib/SConscript @@ -11,7 +11,7 @@ CPPDEFINES = ['RT_USING_DLIBC'] if rtconfig.PLATFORM == 'iar': - if GetDepend('RT_LIBC_USING_FILEIO'): + if GetDepend('RT_USING_POSIX'): from distutils.version import LooseVersion from iar import IARVersion diff --git a/components/libc/compilers/dlib/syscall_close.c b/components/libc/compilers/dlib/syscall_close.c index bafe21aa4b..2897c2418a 100644 --- a/components/libc/compilers/dlib/syscall_close.c +++ b/components/libc/compilers/dlib/syscall_close.c @@ -18,9 +18,9 @@ int __close(int handle) handle == _LLIO_STDERR || handle == _LLIO_STDIN) return _LLIO_ERROR; -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX return close(handle); #else return _LLIO_ERROR; -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ } diff --git a/components/libc/compilers/dlib/syscall_lseek.c b/components/libc/compilers/dlib/syscall_lseek.c index 4a3a5c6a46..4ea55ef1c3 100644 --- a/components/libc/compilers/dlib/syscall_lseek.c +++ b/components/libc/compilers/dlib/syscall_lseek.c @@ -18,9 +18,9 @@ long __lseek(int handle, long offset, int whence) handle == _LLIO_STDERR || handle == _LLIO_STDIN) return _LLIO_ERROR; -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX return lseek(handle, offset, whence); #else return _LLIO_ERROR; -#endif +#endif /* RT_USING_POSIX */ } diff --git a/components/libc/compilers/dlib/syscall_open.c b/components/libc/compilers/dlib/syscall_open.c index 891b9afe58..8fb3c3a11f 100644 --- a/components/libc/compilers/dlib/syscall_open.c +++ b/components/libc/compilers/dlib/syscall_open.c @@ -16,7 +16,7 @@ int __open(const char *filename, int mode) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX int handle; int open_mode = O_RDONLY; @@ -68,5 +68,5 @@ int __open(const char *filename, int mode) return handle; #else return _LLIO_ERROR; -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ } diff --git a/components/libc/compilers/dlib/syscall_read.c b/components/libc/compilers/dlib/syscall_read.c index f65b502966..447ca03112 100644 --- a/components/libc/compilers/dlib/syscall_read.c +++ b/components/libc/compilers/dlib/syscall_read.c @@ -20,7 +20,7 @@ #pragma module_name = "?__read" size_t __read(int handle, unsigned char *buf, size_t len) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX int size; if (handle == _LLIO_STDIN) @@ -41,5 +41,5 @@ size_t __read(int handle, unsigned char *buf, size_t len) return size; #else return _LLIO_ERROR; -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ } diff --git a/components/libc/compilers/dlib/syscall_write.c b/components/libc/compilers/dlib/syscall_write.c index af47d64a3e..ae2d4a1559 100644 --- a/components/libc/compilers/dlib/syscall_write.c +++ b/components/libc/compilers/dlib/syscall_write.c @@ -21,13 +21,13 @@ size_t __write(int handle, const unsigned char *buf, size_t len) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX int size; -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR)) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX if (libc_stdio_get_console() < 0) { LOG_W("Do not invoke standard output before initializing libc"); @@ -46,17 +46,17 @@ size_t __write(int handle, const unsigned char *buf, size_t len) return len; #else return _LLIO_ERROR; -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ } else if (handle == _LLIO_STDIN) { return _LLIO_ERROR; } -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX size = write(handle, buf, len); return size; #else return _LLIO_ERROR; -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ } diff --git a/components/libc/compilers/gcc/newlib/libc.h b/components/libc/compilers/gcc/newlib/libc.h index 0ae1057730..2ea27b09f9 100644 --- a/components/libc/compilers/gcc/newlib/libc.h +++ b/components/libc/compilers/gcc/newlib/libc.h @@ -15,11 +15,13 @@ 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 diff --git a/components/libc/compilers/gcc/newlib/stdio.c b/components/libc/compilers/gcc/newlib/stdio.c index c0da1b1cec..e6ebc8c303 100644 --- a/components/libc/compilers/gcc/newlib/stdio.c +++ b/components/libc/compilers/gcc/newlib/stdio.c @@ -7,16 +7,14 @@ * Date Author Notes * 2017/10/15 bernard the first version */ -#include +#include +#ifdef RT_USING_POSIX #include +#include #include #include "libc.h" #define STDIO_DEVICE_NAME_MAX 32 - -#ifdef RT_LIBC_USING_FILEIO -#include - static FILE* std_console = NULL; int libc_stdio_set_console(const char* device_name, int mode) @@ -76,7 +74,8 @@ int libc_stdio_set_console(const char* device_name, int mode) _GLOBAL_REENT->__sdidinit = 1; } - if (std_console) return fileno(std_console); + if (std_console) + return fileno(std_console); return -1; } @@ -89,34 +88,4 @@ int libc_stdio_get_console(void) return -1; } -#elif defined(RT_USING_POSIX) -#include -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_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ diff --git a/components/libc/compilers/gcc/newlib/syscalls.c b/components/libc/compilers/gcc/newlib/syscalls.c index 6cb60e1776..9e9df3f625 100644 --- a/components/libc/compilers/gcc/newlib/syscalls.c +++ b/components/libc/compilers/gcc/newlib/syscalls.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -175,7 +176,7 @@ int flock(int fd, int operation) _off_t _lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX _off_t rc; rc = lseek(fd, pos, whence); @@ -183,12 +184,12 @@ _off_t _lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence) #else ptr->_errno = ENOTSUP; return -1; -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ } int _mkdir_r(struct _reent *ptr, const char *name, int mode) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX int rc; rc = mkdir(name, mode); @@ -196,25 +197,24 @@ int _mkdir_r(struct _reent *ptr, const char *name, int mode) #else ptr->_errno = ENOTSUP; return -1; -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ } int _open_r(struct _reent *ptr, const char *file, int flags, int mode) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX int rc; - rc = open(file, flags, mode); return rc; #else ptr->_errno = ENOTSUP; return -1; -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ } _ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX _ssize_t rc; if (libc_stdio_get_console() < 0 && fd == STDIN_FILENO) { @@ -226,12 +226,12 @@ _ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes) #else ptr->_errno = ENOTSUP; return -1; -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ } int _rename_r(struct _reent *ptr, const char *old, const char *new) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX int rc; rc = rename(old, new); @@ -239,12 +239,12 @@ int _rename_r(struct _reent *ptr, const char *old, const char *new) #else ptr->_errno = ENOTSUP; return -1; -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ } int _stat_r(struct _reent *ptr, const char *file, struct stat *pstat) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX int rc; rc = stat(file, pstat); @@ -252,22 +252,22 @@ int _stat_r(struct _reent *ptr, const char *file, struct stat *pstat) #else ptr->_errno = ENOTSUP; return -1; -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ } int _unlink_r(struct _reent *ptr, const char *file) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX return unlink(file); #else ptr->_errno = ENOTSUP; return -1; -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ } _ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX _ssize_t rc; if (libc_stdio_get_console() < 0 && fd == STDOUT_FILENO) { @@ -285,7 +285,7 @@ _ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes) if (console) return rt_device_write(console, -1, buf, nbytes); } -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ ptr->_errno = ENOTSUP; return -1; } -- 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/dlib/syscall_write.c') 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