diff options
| author | Bernard Xiong <[email protected]> | 2021-11-10 22:23:43 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-11-10 22:23:43 +0800 |
| commit | e6ae01e3326a5feb6d11176c3407bee7c920399c (patch) | |
| tree | 80dc67ad821469bed720e01880a2901e5732d6a2 /components | |
| parent | fdbaa2a808d12d522ad90702795c08ae8443aab9 (diff) | |
| parent | 219d1e20f579cda0aac62d90bf926e8a0a9dd688 (diff) | |
Merge pull request #5259 from mysterywolf/posix
[posix] 优化posix若干
Diffstat (limited to 'components')
22 files changed, 129 insertions, 161 deletions
diff --git a/components/dfs/Kconfig b/components/dfs/Kconfig index 7a4fbb655d..1ec36784d7 100644 --- a/components/dfs/Kconfig +++ b/components/dfs/Kconfig @@ -133,7 +133,7 @@ if RT_USING_DFS config RT_USING_DFS_DEVFS bool "Using devfs for device objects" - default y + default n config RT_USING_DFS_ROMFS bool "Enable ReadOnly file system on flash" diff --git a/components/dfs/include/dfs_fs.h b/components/dfs/include/dfs_fs.h index 3d194515df..0a13040c21 100644 --- a/components/dfs/include/dfs_fs.h +++ b/components/dfs/include/dfs_fs.h @@ -12,10 +12,9 @@ #define __DFS_FS_H__ #include <dfs.h> -#ifdef RT_USING_LIBC #include <sys/types.h> -#endif #include <sys/errno.h> + #ifdef __cplusplus extern "C" { #endif diff --git a/components/dfs/src/dfs.c b/components/dfs/src/dfs.c index ed8d8094aa..29b2068a6c 100644 --- a/components/dfs/src/dfs.c +++ b/components/dfs/src/dfs.c @@ -18,9 +18,9 @@ #include <lwp.h> #endif -#ifdef RT_USING_POSIX +#ifdef RT_USING_POSIX_STDIO #include <libc.h> -#endif /* RT_USING_POSIX */ +#endif /* RT_USING_POSIX_STDIO */ /* Global variables */ const struct dfs_filesystem_ops *filesystem_operation_table[DFS_FILESYSTEM_TYPES_MAX]; @@ -216,10 +216,10 @@ struct dfs_fd *fd_get(int fd) struct dfs_fd *d; struct dfs_fdtable *fdt; -#ifdef RT_USING_POSIX +#ifdef RT_USING_POSIX_STDIO if ((0 <= fd) && (fd <= 2)) fd = libc_stdio_get_console(); -#endif /* RT_USING_POSIX */ +#endif /* RT_USING_POSIX_STDIO */ fdt = dfs_fdtable_get(); fd = fd - DFS_FD_OFFSET; diff --git a/components/finsh/shell.c b/components/finsh/shell.c index 6938ed1f24..c2f6e2a550 100644 --- a/components/finsh/shell.c +++ b/components/finsh/shell.c @@ -146,7 +146,7 @@ int finsh_getchar(void) { #ifdef RT_USING_DEVICE char ch = 0; -#ifdef RT_USING_POSIX +#ifdef RT_USING_POSIX_STDIO if(read(STDIN_FILENO, &ch, 1) > 0) { return ch; @@ -170,14 +170,14 @@ int finsh_getchar(void) rt_sem_take(&shell->rx_sem, RT_WAITING_FOREVER); return ch; -#endif /* RT_USING_POSIX */ +#endif /* RT_USING_POSIX_STDIO */ #else extern char rt_hw_console_getchar(void); return rt_hw_console_getchar(); #endif /* RT_USING_DEVICE */ } -#if !defined(RT_USING_POSIX) && defined(RT_USING_DEVICE) +#if !defined(RT_USING_POSIX_STDIO) && defined(RT_USING_DEVICE) static rt_err_t finsh_rx_ind(rt_device_t dev, rt_size_t size) { RT_ASSERT(shell != RT_NULL); @@ -241,7 +241,7 @@ const char *finsh_get_device() RT_ASSERT(shell != RT_NULL); return shell->device->parent.name; } -#endif +#endif /* !defined(RT_USING_POSIX_STDIO) && defined(RT_USING_DEVICE) */ /** * @ingroup finsh @@ -443,7 +443,7 @@ void finsh_thread_entry(void *parameter) shell->echo_mode = 0; #endif -#if !defined(RT_USING_POSIX) && defined(RT_USING_DEVICE) +#if !defined(RT_USING_POSIX_STDIO) && defined(RT_USING_DEVICE) /* set console device as shell device */ if (shell->device == RT_NULL) { @@ -453,7 +453,7 @@ void finsh_thread_entry(void *parameter) finsh_set_device(console->parent.name); } } -#endif +#endif /* !defined(RT_USING_POSIX_STDIO) && defined(RT_USING_DEVICE) */ #ifdef FINSH_USING_AUTH /* set the default password when the password isn't setting */ diff --git a/components/finsh/shell.h b/components/finsh/shell.h index 985d3b3fbd..d421f60374 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_POSIX) && defined(RT_USING_DEVICE) +#if !defined(RT_USING_POSIX_STDIO) && defined(RT_USING_DEVICE) rt_device_t device; #endif diff --git a/components/libc/Kconfig b/components/libc/Kconfig index b2af15e841..4506001d42 100644 --- a/components/libc/Kconfig +++ b/components/libc/Kconfig @@ -10,8 +10,8 @@ if RT_USING_LIBC config RT_LIBC_USING_FILEIO bool "Enable libc with file operation, eg.fopen/fwrite/fread/getchar" - select RT_USING_DFS select RT_USING_POSIX + select RT_USING_POSIX_STDIO default n config RT_USING_MODULE @@ -37,40 +37,59 @@ config RT_LIBC_DEFAULT_TIMEZONE range -12 12 default 8 -config RT_USING_PTHREADS - bool "Enable pthreads APIs" +config RT_USING_POSIX + bool "Enable basic POSIX layer, open/read/write/close etc" + select RT_USING_DFS default n -if RT_USING_PTHREADS - config PTHREAD_NUM_MAX - int "Maximum number of pthreads" - default 8 -endif - -if RT_USING_DFS - config RT_USING_POSIX - bool "Enable POSIX layer, open/read/write/select etc" +if RT_USING_POSIX + config RT_USING_POSIX_STDIO + bool "Enable standard I/O" + select RT_USING_DFS select RT_USING_DFS_DEVFS - default y + default n - if RT_USING_POSIX - config RT_USING_POSIX_MMAP - bool "Enable mmap() API" - default n + config RT_USING_POSIX_POLL + bool "Enable poll()" + select RT_USING_DFS + default n - config RT_USING_POSIX_TERMIOS - bool "Enable termios APIs" - default n + config RT_USING_POSIX_SELECT + bool "Enable select()" + select RT_USING_DFS + select RT_USING_POSIX_POLL + default n - config RT_USING_POSIX_GETLINE - bool "Enable getline()/getdelim() APIs" - default n + config RT_USING_POSIX_DELAY + bool "Enable delay functions" + default n - config RT_USING_POSIX_AIO - bool "Enable AIO" - default n - endif + config RT_USING_POSIX_GETLINE + bool "Enable getline()/getdelim() APIs" + default n + + config RT_USING_POSIX_MMAP + bool "Enable mmap() API" + select RT_USING_DFS + default n + + config RT_USING_POSIX_TERMIOS + bool "Enable termios APIs" + default n + config RT_USING_POSIX_AIO + bool "Enable AIO" + default n +endif + +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 endif endmenu diff --git a/components/libc/compilers/armlibc/syscalls.c b/components/libc/compilers/armlibc/syscalls.c index 755ffef1a6..62657a4b64 100644 --- a/components/libc/compilers/armlibc/syscalls.c +++ b/components/libc/compilers/armlibc/syscalls.c @@ -21,7 +21,7 @@ #include <fcntl.h> #include <unistd.h> #include <sys/stat.h> -#ifdef RT_USING_POSIX +#ifdef RT_USING_POSIX_STDIO #include "libc.h" #endif @@ -144,7 +144,7 @@ int _sys_close(FILEHANDLE fh) */ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode) { -#ifdef RT_USING_POSIX +#ifdef RT_USING_POSIX_STDIO int size; if (fh == STDIN) @@ -169,7 +169,7 @@ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode) return 0; /* error */ #else return 0; /* error */ -#endif /* RT_USING_POSIX */ +#endif /* RT_USING_POSIX_STDIO */ } /* @@ -185,7 +185,7 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode) if ((fh == STDOUT) || (fh == STDERR)) { -#ifdef RT_USING_POSIX +#ifdef RT_USING_POSIX_STDIO if (libc_stdio_get_console() < 0) { LOG_W("Do not invoke standard input before initializing libc"); @@ -200,7 +200,7 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode) } return 0; /* error */ -#endif /* RT_USING_POSIX */ +#endif /* RT_USING_POSIX_STDIO */ } else if (fh == STDIN) { @@ -325,7 +325,7 @@ int fputc(int c, FILE *f) int fgetc(FILE *f) { -#ifdef RT_USING_POSIX +#ifdef RT_USING_POSIX_STDIO char ch; if (libc_stdio_get_console() < 0) @@ -336,7 +336,7 @@ int fgetc(FILE *f) if(read(STDIN_FILENO, &ch, 1) == 1) return ch; -#endif /* RT_USING_POSIX */ +#endif /* RT_USING_POSIX_STDIO */ return 0; /* error */ } diff --git a/components/libc/compilers/dlib/syscall_read.c b/components/libc/compilers/dlib/syscall_read.c index 74cedb966a..c926c577b5 100644 --- a/components/libc/compilers/dlib/syscall_read.c +++ b/components/libc/compilers/dlib/syscall_read.c @@ -11,7 +11,7 @@ #include <rtthread.h> #include <yfuns.h> #include <unistd.h> -#ifdef RT_USING_POSIX +#ifdef RT_USING_POSIX_STDIO #include "libc.h" #endif @@ -22,7 +22,7 @@ #pragma module_name = "?__read" size_t __read(int handle, unsigned char *buf, size_t len) { -#ifdef RT_USING_POSIX +#ifdef RT_USING_POSIX_STDIO int size; if (handle == _LLIO_STDIN) diff --git a/components/libc/compilers/dlib/syscall_write.c b/components/libc/compilers/dlib/syscall_write.c index ab011c1096..72bac6ba49 100644 --- a/components/libc/compilers/dlib/syscall_write.c +++ b/components/libc/compilers/dlib/syscall_write.c @@ -11,7 +11,7 @@ #include <rtthread.h> #include <yfuns.h> #include <unistd.h> -#ifdef RT_USING_POSIX +#ifdef RT_USING_POSIX_STDIO #include "libc.h" #endif @@ -29,7 +29,7 @@ size_t __write(int handle, const unsigned char *buf, size_t len) if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR)) { -#ifdef RT_USING_POSIX +#ifdef RT_USING_POSIX_STDIO if (libc_stdio_get_console() < 0) { LOG_W("Do not invoke standard output before initializing libc"); diff --git a/components/libc/compilers/gcc/newlib/syscalls.c b/components/libc/compilers/gcc/newlib/syscalls.c index f95e695a85..e957aaf003 100644 --- a/components/libc/compilers/gcc/newlib/syscalls.c +++ b/components/libc/compilers/gcc/newlib/syscalls.c @@ -20,7 +20,7 @@ #include <unistd.h> #include <sys/errno.h> #include <sys/stat.h> -#ifdef RT_USING_POSIX +#ifdef RT_USING_POSIX_STDIO #include "libc.h" #endif #ifdef RT_USING_MODULE @@ -216,7 +216,7 @@ int _open_r(struct _reent *ptr, const char *file, int flags, int mode) _ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes) { -#ifdef RT_USING_POSIX +#ifdef RT_USING_POSIX_STDIO _ssize_t rc; if (libc_stdio_get_console() < 0 && fd == STDIN_FILENO) { @@ -271,11 +271,13 @@ _ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes) { #ifdef RT_USING_POSIX _ssize_t rc; +#ifdef RT_USING_POSIX_STDIO if (libc_stdio_get_console() < 0 && fd == STDOUT_FILENO) { LOG_W("Do not invoke standard output before initializing libc"); return 0; } +#endif /* RT_USING_POSIX_STDIO */ rc = write(fd, buf, nbytes); return rc; #elif defined(RT_USING_CONSOLE) diff --git a/components/libc/compilers/readme.md b/components/libc/compilers/readme.md new file mode 100644 index 0000000000..e376cc704f --- /dev/null +++ b/components/libc/compilers/readme.md @@ -0,0 +1 @@ +This folder provides uniformed header files crossing different compiler platforms, and supports basic standard C library functions, such as memory management and time management, etc.
\ No newline at end of file diff --git a/components/libc/posix/mmap/SConscript b/components/libc/posix/mmap/SConscript deleted file mode 100644 index fd5b2b953e..0000000000 --- a/components/libc/posix/mmap/SConscript +++ /dev/null @@ -1,13 +0,0 @@ -# RT-Thread building script for component - -from building import * - -cwd = GetCurrentDir() -src = Glob('*.c') + Glob('*.cpp') -CPPPATH = [cwd] - -group = DefineGroup('POSIX', src, - depend = ['RT_USING_DFS', 'RT_USING_POSIX_MMAP'], - CPPPATH = CPPPATH) - -Return('group') diff --git a/components/libc/posix/readme.md b/components/libc/posix/readme.md new file mode 100644 index 0000000000..787b9ddefa --- /dev/null +++ b/components/libc/posix/readme.md @@ -0,0 +1 @@ +This folder provides functions that are not part of the standard C library but are part of the POSIX.1 (IEEE Standard 1003.1) standard.
\ No newline at end of file diff --git a/components/libc/posix/src/SConscript b/components/libc/posix/src/SConscript index f338b52cec..0f5d0e9911 100644 --- a/components/libc/posix/src/SConscript +++ b/components/libc/posix/src/SConscript @@ -1,12 +1,22 @@ +# RT-Thread building script for component + from building import * -Import('rtconfig') -src = Glob('*.c') +src = ['unistd.c', 'delay.c'] cwd = GetCurrentDir() CPPPATH = [cwd] -if rtconfig.ARCH == 'sim': # the vs simulator does not support select and poll - SrcRemove(src, ['select.c', 'poll.c']) +if GetDepend('RT_USING_POSIX_STDIO'): + src += ['libc.c'] + +if GetDepend('RT_USING_POSIX_POLL'): + src += ['poll.c'] + +if GetDepend('RT_USING_POSIX_SELECT'): + src += ['select.c'] + +if GetDepend('RT_USING_POSIX_MMAP'): + src += ['mmap.c'] group = DefineGroup('POSIX', src, depend = ['RT_USING_POSIX'], CPPPATH = CPPPATH) diff --git a/components/libc/posix/src/delay.c b/components/libc/posix/src/delay.c index 1638caafbf..c8564dc54e 100644 --- a/components/libc/posix/src/delay.c +++ b/components/libc/posix/src/delay.c @@ -7,6 +7,7 @@ * Date Author Notes * 2021-05-07 Meco Man first Version */ +#include <sys/types.h> #include <rtthread.h> #include <rthw.h> #define DBG_TAG "POSIX.delay" @@ -48,3 +49,38 @@ void ndelay(unsigned long nsecs) rt_hw_us_delay(1); } RTM_EXPORT(ndelay); + +unsigned int sleep(unsigned int seconds) +{ + if (rt_thread_self() != RT_NULL) + { + ssleep(seconds); + } + else /* scheduler has not run yet */ + { + while(seconds > 0) + { + udelay(1000000u); + seconds --; + } + } + + return 0; +} +RTM_EXPORT(sleep); + +int usleep(useconds_t usec) +{ + if (rt_thread_self() != RT_NULL) + { + msleep(usec / 1000u); + } + else /* scheduler has not run yet */ + { + udelay(usec / 1000u); + } + udelay(usec % 1000u); + + return 0; +} +RTM_EXPORT(usleep); diff --git a/components/libc/posix/mmap/posix_mmap.c b/components/libc/posix/src/mmap.c index e68b82e640..e68b82e640 100644 --- a/components/libc/posix/mmap/posix_mmap.c +++ b/components/libc/posix/src/mmap.c diff --git a/components/libc/posix/src/poll.c b/components/libc/posix/src/poll.c index 2109fb310b..0c773b306c 100644 --- a/components/libc/posix/src/poll.c +++ b/components/libc/posix/src/poll.c @@ -14,8 +14,6 @@ #include <dfs_file.h> #include <poll.h> -#ifdef RT_USING_POSIX - struct rt_poll_node; struct rt_poll_table @@ -226,5 +224,3 @@ int poll(struct pollfd *fds, nfds_t nfds, int timeout) return num; } - -#endif diff --git a/components/libc/posix/src/select.c b/components/libc/posix/src/select.c index 25cda0f0d1..55d320e921 100644 --- a/components/libc/posix/src/select.c +++ b/components/libc/posix/src/select.c @@ -11,8 +11,6 @@ #include <poll.h> #include <sys/select.h> -#ifdef RT_USING_POSIX - static void fdszero(fd_set *set, int nfds) { fd_mask *m; @@ -176,5 +174,3 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struc return ret; } - -#endif diff --git a/components/libc/posix/src/unistd.c b/components/libc/posix/src/unistd.c index ef2df2c2fe..85235965ea 100644 --- a/components/libc/posix/src/unistd.c +++ b/components/libc/posix/src/unistd.c @@ -13,7 +13,6 @@ #include <dfs_private.h> #include <sys/errno.h> #include <unistd.h> -#include <delay.h> /** * this function is a POSIX compliant version, which will open a file and @@ -965,80 +964,3 @@ char *ttyname(int fd) return "/dev/tty"; /* TODO: need to add more specific */ } RTM_EXPORT(ttyname); - -unsigned int sleep(unsigned int seconds) -{ - if (rt_thread_self() != RT_NULL) - { - ssleep(seconds); - } - else /* scheduler has not run yet */ - { - while(seconds > 0) - { - udelay(1000000u); - seconds --; - } - } - - return 0; -} -RTM_EXPORT(sleep); - -int usleep(useconds_t usec) -{ - if (rt_thread_self() != RT_NULL) - { - msleep(usec / 1000u); - } - else /* scheduler has not run yet */ - { - udelay(usec / 1000u); - } - udelay(usec % 1000u); - - return 0; -} -RTM_EXPORT(usleep); - -pid_t gettid(void) -{ - /*TODO*/ - return 0; -} - -pid_t getpid(void) -{ - return gettid(); -} -RTM_EXPORT(getpid); - -pid_t getppid(void) -{ - return 0; -} -RTM_EXPORT(getppid); - -uid_t getuid(void) -{ - return 0; /*ROOT*/ -} -RTM_EXPORT(getuid); - -uid_t geteuid(void) -{ - return 0; /*ROOT*/ -} -RTM_EXPORT(geteuid); - -gid_t getgid(void) -{ - return 0; /*ROOT*/ -} -RTM_EXPORT(getgid); - -gid_t getegid(void) -{ - return 0; /*ROOT*/ -} -RTM_EXPORT(getegid); diff --git a/components/lwp/Kconfig b/components/lwp/Kconfig index 1b37829935..3e1982001e 100644 --- a/components/lwp/Kconfig +++ b/components/lwp/Kconfig @@ -1,6 +1,7 @@ config RT_USING_LWP bool "Using light-weight process" - select RT_USING_DFS + select RT_USING_POSIX + select RT_USING_POSIX_SELECT select RT_USING_LIBC depends on ARCH_ARM_CORTEX_M || ARCH_ARM_ARM9 || ARCH_ARM_CORTEX_A default n diff --git a/components/lwp/lwp_syscall.c b/components/lwp/lwp_syscall.c index f9bc84ea97..f2aec9303f 100644 --- a/components/lwp/lwp_syscall.c +++ b/components/lwp/lwp_syscall.c @@ -18,7 +18,6 @@ #if (defined(RT_USING_SAL) && defined(SAL_USING_POSIX)) #include <sys/socket.h> - #define SYSCALL_NET(f) ((void*)(f)) #else #define SYSCALL_NET(f) ((void*)sys_notimpl) diff --git a/components/net/Kconfig b/components/net/Kconfig index 0fede3eb90..4d6317bac6 100644 --- a/components/net/Kconfig +++ b/components/net/Kconfig @@ -41,9 +41,8 @@ config RT_USING_SAL config SAL_USING_POSIX bool "Enable BSD socket operated by file system API" default n - select RT_USING_DFS - select RT_USING_LIBC select RT_USING_POSIX + select RT_USING_POSIX_SELECT help Let BSD socket operated by file system API, such as read/write and involveed in select/poll POSIX APIs. |
