diff --git a/bsp/gd32303e-eval/rtconfig.h b/bsp/gd32303e-eval/rtconfig.h index 7a47c83787608ff322e4bb9a7e7ffb94c7b087ca..365fd296e062693a459631c35d3bdf3821084299 100644 --- a/bsp/gd32303e-eval/rtconfig.h +++ b/bsp/gd32303e-eval/rtconfig.h @@ -125,6 +125,7 @@ /* 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/lm3s8962/applications/startup.c b/bsp/lm3s8962/applications/startup.c index 87df6e8788d0c24ad6bb463fafa5d2cde892f16b..0742c5453ca140423b9d0ae0bc3012bc382d6f00 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(); -#ifdef RT_USING_DEVICE +#if !defined(RT_USING_LIBC) && defined(RT_USING_DEVICE) finsh_set_device("uart1"); #endif #endif diff --git a/bsp/lm3s8962/rtconfig.h b/bsp/lm3s8962/rtconfig.h index b154688a6deaadf2750cb788792ee01bc63ee670..dd583205baf5c6940e85e28c0c5a9aa91f5451b9 100644 --- a/bsp/lm3s8962/rtconfig.h +++ b/bsp/lm3s8962/rtconfig.h @@ -75,8 +75,10 @@ #define FINSH_USING_SYMTAB #define FINSH_USING_DESCRIPTION +#define RT_USING_LIBC #define RT_USING_DFS -/* SECTION: DFS options */ +#define RT_USING_POSIX +#define RT_USING_DFS_DEVFS #define RT_USING_DFS_ELMFAT #define RT_DFS_ELM_WORD_ACCESS @@ -144,6 +146,5 @@ /* the size of each pbuf in the pbuf pool. */ #define RT_LWIP_PBUF_POOL_BUFSIZE 1500 -#define RT_USING_LIBC #define RT_USING_LWIP141 #endif diff --git a/components/dfs/SConscript b/components/dfs/SConscript index e449c849114ac9e88d1ba1d627f990901707da93..5a0b394ce2de5e19474327e942237eb788fd108f 100644 --- a/components/dfs/SConscript +++ b/components/dfs/SConscript @@ -5,14 +5,10 @@ src = Split(''' src/dfs.c src/dfs_file.c src/dfs_fs.c -src/dfs_posix.c ''') cwd = GetCurrentDir() CPPPATH = [cwd + "/include"] -if GetDepend('RT_USING_POSIX'): - src += ['src/dfs_poll.c', 'src/dfs_select.c'] - group = DefineGroup('Filesystem', src, depend = ['RT_USING_DFS'], CPPPATH = CPPPATH) if GetDepend('RT_USING_DFS'): diff --git a/components/dfs/src/dfs.c b/components/dfs/src/dfs.c index 8155b088f0f38ef1c5dfe3b1463d8442bd138f16..fa93afd74959285d72525d1d11a62fded2818f2f 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) +#ifdef 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) +#ifdef RT_USING_LIBC if ((0 <= fd) && (fd <= 2)) fd = libc_stdio_get_console(); #endif diff --git a/components/dfs/src/dfs_file.c b/components/dfs/src/dfs_file.c index fa0f6000b440cd0d94dc08f7da351d8221cd5c82..978c1056c2ad5ffddb32a9a2afd023f70b7a2fe8 100644 --- a/components/dfs/src/dfs_file.c +++ b/components/dfs/src/dfs_file.c @@ -621,6 +621,7 @@ void cat(const char *filename) } FINSH_FUNCTION_EXPORT(cat, print file); +#ifdef RT_USING_POSIX #define BUF_SZ 4096 static void copyfile(const char *src, const char *dst) { @@ -749,6 +750,7 @@ static const char *_get_path_lastname(const char *path) /* skip the '/' then return */ return ++ptr; } + void copy(const char *src, const char *dst) { #define FLAG_SRC_TYPE 0x03 @@ -841,7 +843,8 @@ void copy(const char *src, const char *dst) } } FINSH_FUNCTION_EXPORT(copy, copy file or dir) +#endif /* RT_USING_POSIX */ -#endif +#endif /* RT_USING_FINSH */ /* @} */ diff --git a/components/finsh/SConscript b/components/finsh/SConscript index 28fe02bac53de3fa8756714eaa43d2034baadb5f..5eabe47c0e00d63eee5147c6cd2b18020137ea56 100644 --- a/components/finsh/SConscript +++ b/components/finsh/SConscript @@ -9,7 +9,7 @@ msh.c if GetDepend('MSH_USING_BUILT_IN_COMMANDS'): src += ['cmd.c'] -if GetDepend('RT_USING_DFS'): +if GetDepend('RT_USING_POSIX'): src += ['msh_file.c'] CPPPATH = [cwd] diff --git a/components/finsh/finsh.h b/components/finsh/finsh.h index 98048ebad4301bfa0d31d062624618b2ff42559d..f5e4df9e493bb195c638efb4d37c822d47ad7acf 100644 --- a/components/finsh/finsh.h +++ b/components/finsh/finsh.h @@ -169,7 +169,7 @@ extern struct finsh_syscall *_syscall_table_begin, *_syscall_table_end; struct finsh_syscall *finsh_syscall_lookup(const char *name); #ifdef RT_USING_DEVICE - void finsh_set_device(const char *device_name); +void finsh_set_device(const char *device_name); #endif #endif diff --git a/components/finsh/msh.c b/components/finsh/msh.c index 18182ca2646a094587c3cb9ad2c985550f06ce24..5cb54c26e720c727dde7f4e7791b2dd74aacbdf3 100644 --- a/components/finsh/msh.c +++ b/components/finsh/msh.c @@ -21,7 +21,7 @@ #include "msh.h" #include "shell.h" -#ifdef RT_USING_DFS +#ifdef RT_USING_POSIX #include #endif @@ -186,7 +186,7 @@ static cmd_function_t msh_get_cmd(char *cmd, int size) return cmd_func; } -#if defined(RT_USING_MODULE) && defined(RT_USING_DFS) +#if defined(RT_USING_MODULE) && defined(RT_USING_POSIX) /* Return 0 on module executed. Other value indicate error. */ int msh_exec_module(const char *cmd_line, int size) @@ -257,7 +257,7 @@ int msh_exec_module(const char *cmd_line, int size) rt_free(pg_name); return ret; } -#endif /* defined(RT_USING_MODULE) && defined(RT_USING_DFS) */ +#endif /* defined(RT_USING_MODULE) && defined(RT_USING_POSIX) */ static int _msh_exec_cmd(char *cmd, rt_size_t length, int *retp) { @@ -290,7 +290,7 @@ static int _msh_exec_cmd(char *cmd, rt_size_t length, int *retp) return 0; } -#if defined(RT_USING_LWP) && defined(RT_USING_DFS) +#if defined(RT_USING_LWP) && defined(RT_USING_POSIX) static int _msh_exec_lwp(char *cmd, rt_size_t length) { int argc; @@ -350,7 +350,7 @@ int msh_exec(char *cmd, rt_size_t length) { return cmd_ret; } -#ifdef RT_USING_DFS +#ifdef RT_USING_POSIX #ifdef DFS_USING_WORKDIR if (msh_exec_script(cmd, length) == 0) { @@ -371,7 +371,7 @@ int msh_exec(char *cmd, rt_size_t length) return 0; } #endif /* RT_USING_LWP */ -#endif /* RT_USING_DFS */ +#endif /* RT_USING_POSIX */ /* truncate the cmd at the first space. */ { @@ -400,7 +400,7 @@ static int str_common(const char *str1, const char *str2) return (str - str1); } -#ifdef RT_USING_DFS +#ifdef RT_USING_POSIX void msh_auto_complete_path(char *path) { DIR *dir = RT_NULL; @@ -521,7 +521,7 @@ void msh_auto_complete_path(char *path) closedir(dir); rt_free(full_path); } -#endif /* RT_USING_DFS */ +#endif /* RT_USING_POSIX */ void msh_auto_complete(char *prefix) { @@ -538,7 +538,7 @@ void msh_auto_complete(char *prefix) return; } -#ifdef RT_USING_DFS +#ifdef RT_USING_POSIX /* check whether a spare in the command */ { char *ptr; diff --git a/components/finsh/msh_file.c b/components/finsh/msh_file.c index 8f067efd98645697427ef5102c9311bcbdc0fc3a..4e9ed53b31282200318d2f7c9181c9ddc99e4f39 100644 --- a/components/finsh/msh_file.c +++ b/components/finsh/msh_file.c @@ -11,7 +11,7 @@ #include -#if defined(RT_USING_FINSH) && defined(RT_USING_DFS) +#if defined(RT_USING_FINSH) && defined(RT_USING_POSIX) #include #include "msh.h" @@ -702,5 +702,5 @@ static int cmd_tail(int argc, char **argv) } MSH_CMD_EXPORT_ALIAS(cmd_tail, tail, print the last N - lines data of the given file); -#endif /* defined(RT_USING_FINSH) && defined(RT_USING_DFS) */ +#endif /* defined(RT_USING_FINSH) && defined(RT_USING_POSIX) */ diff --git a/components/finsh/shell.c b/components/finsh/shell.c index 20f1bdef0ff335e4c8d43040b9c9166a5b66d6ef..292ea588cf08a1fba6ed402af1ff4a5c6484bb89 100644 --- a/components/finsh/shell.c +++ b/components/finsh/shell.c @@ -27,9 +27,9 @@ #include "shell.h" #include "msh.h" -#if defined(RT_USING_DFS) - #include -#endif /* RT_USING_DFS */ +#ifdef RT_USING_POSIX +#include +#endif /* RT_USING_POSIX */ /* finsh thread */ #ifndef RT_USING_HEAP @@ -104,7 +104,7 @@ const char *finsh_get_prompt(void) } strcpy(finsh_prompt, _MSH_PROMPT); -#if defined(RT_USING_DFS) && defined(DFS_USING_WORKDIR) +#if defined(RT_USING_POSIX) && defined(DFS_USING_WORKDIR) /* get current working directory */ getcwd(&finsh_prompt[rt_strlen(finsh_prompt)], RT_CONSOLEBUF_SIZE - rt_strlen(finsh_prompt)); #endif @@ -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_POSIX +#ifdef RT_USING_LIBC 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_POSIX */ +#endif /* RT_USING_LIBC */ #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_LIBC) && 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_POSIX) && defined(RT_USING_DEVICE) +#if !defined(RT_USING_LIBC) && 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 985d3b3fbd4db7cece6f401c098212a5064cf42e..598596ce00f398b8033c35e6318cf11e892f324f 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_LIBC) && defined(RT_USING_DEVICE) rt_device_t device; #endif diff --git a/components/libc/Kconfig b/components/libc/Kconfig index b9600ef38987c98b711c5449ac928bba80cb1a79..812b1ce48c73226ec768cb2d2e6b76712cdef3c6 100644 --- a/components/libc/Kconfig +++ b/components/libc/Kconfig @@ -2,6 +2,8 @@ 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 config RT_USING_PTHREADS @@ -14,9 +16,9 @@ if RT_USING_PTHREADS default 8 endif -if RT_USING_LIBC && RT_USING_DFS +if RT_USING_DFS config RT_USING_POSIX - bool "Enable POSIX layer for compatibility with UNIX APIs, poll/select etc" + bool "Enable POSIX layer, open/read/write/select etc" select RT_USING_DFS_DEVFS default y @@ -49,9 +51,9 @@ if RT_USING_LIBC default n if RT_USING_MODULE - config RT_USING_CUSTOM_DLMODULE - bool "Enable load dynamic module by custom" - default n + config RT_USING_CUSTOM_DLMODULE + bool "Enable load dynamic module by custom" + default n endif endif diff --git a/components/libc/compilers/common/SConscript b/components/libc/compilers/common/SConscript index fbdb2f11ec39d3909dc27d092a9ede728d3653dd..b7a6626a3636ea73953f959b5213bda911eabbda 100644 --- a/components/libc/compilers/common/SConscript +++ b/components/libc/compilers/common/SConscript @@ -6,18 +6,15 @@ src = [] cwd = GetCurrentDir() group = [] CPPPATH = [cwd] +CPPDEFINES = [] if GetDepend('RT_USING_LIBC'): src += Glob('*.c') - if GetDepend('RT_USING_POSIX') == False: - SrcRemove(src, ['unistd.c', 'delay.c']) elif GetDepend('RT_LIBC_USING_TIME'): src += Glob('time.c') if rtconfig.CROSS_TOOL == 'keil': - CPPDEFINES = ['__CLK_TCK=RT_TICK_PER_SECOND'] -else: - CPPDEFINES = [] + CPPDEFINES += ['__CLK_TCK=RT_TICK_PER_SECOND'] group = DefineGroup('libc', src, depend = [], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES) diff --git a/components/libc/compilers/common/readme.md b/components/libc/compilers/common/readme.md index 856ddeb0456ebea642bcc4ad5b6a91dcc595d0af..82e23f8970f5029e898fc6074abd148e65c36fb4 100644 --- a/components/libc/compilers/common/readme.md +++ b/components/libc/compilers/common/readme.md @@ -1,10 +1 @@ -## Attentions - -1. This folder is "common" for all toolchains. - -2. If you want to add new `.c` files, please do not forget to fix SConscript file too. eg: - -```python -if GetDepend('RT_USING_POSIX') == False: - SrcRemove(src, ['unistd.c']) -``` \ No newline at end of file +This folder is "common" for all toolchains. \ No newline at end of file diff --git a/components/libc/compilers/common/unistd.c b/components/libc/compilers/common/unistd.c deleted file mode 100644 index 9a457c42000426a69068b723d7e842243db0001d..0000000000000000000000000000000000000000 --- a/components/libc/compilers/common/unistd.c +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2020-09-01 Meco Man first Version - * 2021-02-12 Meco Man move all functions located in to this file - */ - -#include -#include -#include - -#ifdef RT_USING_POSIX_TERMIOS -#include "termios.h" -int isatty(int fd) -{ - struct termios ts; - return(tcgetattr(fd, &ts) != -1); /*true if no error (is a tty)*/ -} -#else -int isatty(int fd) -{ - if (fd >=0 && fd < 3) - { - return 1; - } - else - { - return 0; - } -} -#endif -RTM_EXPORT(isatty); - -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) - { - rt_thread_delay(seconds * RT_TICK_PER_SECOND); - } - else /* scheduler has not run yet */ - { - while(seconds > 0) - { - rt_hw_us_delay(1000000u); - seconds --; - } - } - - return 0; -} -RTM_EXPORT(sleep); - -int usleep(useconds_t usec) -{ - if (rt_thread_self() != RT_NULL) - { - rt_thread_mdelay(usec / 1000u); - } - else /* scheduler has not run yet */ - { - rt_hw_us_delay(usec / 1000u); - } - rt_hw_us_delay(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/libc/posix/aio/SConscript b/components/libc/posix/aio/SConscript index f10462e9c438c0f30226e8fd5af58beca50cae69..445efaade53c85608646bb090bd46edbb66a5dac 100644 --- a/components/libc/posix/aio/SConscript +++ b/components/libc/posix/aio/SConscript @@ -3,9 +3,9 @@ from building import * cwd = GetCurrentDir() -src = Glob('*.c') + Glob('*.cpp') +src = Glob('*.c') CPPPATH = [cwd] -group = DefineGroup('libc', src, depend = ['RT_USING_POSIX', 'RT_USING_POSIX_AIO'], CPPPATH = CPPPATH) +group = DefineGroup('POSIX', src, depend = ['RT_USING_POSIX', 'RT_USING_POSIX_AIO'], CPPPATH = CPPPATH) Return('group') diff --git a/components/libc/posix/getline/SConscript b/components/libc/posix/getline/SConscript index fa4c8618c181e3b64c15c989c88259b45d0c4cf2..bb18dc04c525eaf6fd052d158acd53b7f4afed0b 100644 --- a/components/libc/posix/getline/SConscript +++ b/components/libc/posix/getline/SConscript @@ -6,7 +6,7 @@ cwd = GetCurrentDir() src = Glob('*.c') + Glob('*.cpp') CPPPATH = [cwd] -group = DefineGroup('libc', src, +group = DefineGroup('POSIX', src, depend = ['RT_USING_LIBC', 'RT_USING_POSIX','RT_USING_POSIX_GETLINE'], CPPPATH = CPPPATH) diff --git a/components/libc/posix/mmap/SConscript b/components/libc/posix/mmap/SConscript index 1a36a15710d552ac4052f72041279399c62ce609..fd5b2b953e83d2f2e81909bef3b76fffcf976c79 100644 --- a/components/libc/posix/mmap/SConscript +++ b/components/libc/posix/mmap/SConscript @@ -6,7 +6,7 @@ cwd = GetCurrentDir() src = Glob('*.c') + Glob('*.cpp') CPPPATH = [cwd] -group = DefineGroup('libc', src, +group = DefineGroup('POSIX', src, depend = ['RT_USING_DFS', 'RT_USING_POSIX_MMAP'], CPPPATH = CPPPATH) diff --git a/components/libc/posix/pthreads/SConscript b/components/libc/posix/pthreads/SConscript index 767b406d4c7b1fa361525e99842cf8cd60c7cb07..7cd78300b2a5d0a43fcc2284fe40b8952eb2fee1 100644 --- a/components/libc/posix/pthreads/SConscript +++ b/components/libc/posix/pthreads/SConscript @@ -16,7 +16,7 @@ try: except : pass -group = DefineGroup('libc', src, +group = DefineGroup('POSIX', src, depend = ['RT_USING_PTHREADS', 'RT_USING_LIBC'], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES) Return('group') diff --git a/components/libc/posix/signal/SConscript b/components/libc/posix/signal/SConscript index f07ff58f6e5f737f2e00541ff5ec0df20ea3ebc1..07cd98cbe02810a3159fa409b916b611ed2bc9cb 100644 --- a/components/libc/posix/signal/SConscript +++ b/components/libc/posix/signal/SConscript @@ -6,7 +6,7 @@ cwd = GetCurrentDir() src = Glob('*.c') + Glob('*.cpp') CPPPATH = [cwd] -group = DefineGroup('libc', src, +group = DefineGroup('POSIX', src, depend = ['RT_USING_SIGNALS', 'RT_USING_PTHREADS', 'RT_USING_LIBC'], CPPPATH = CPPPATH) diff --git a/components/libc/posix/src/SConscript b/components/libc/posix/src/SConscript new file mode 100644 index 0000000000000000000000000000000000000000..5640181ac52908e831fdaefa9144c4ebabc47231 --- /dev/null +++ b/components/libc/posix/src/SConscript @@ -0,0 +1,10 @@ +# RT-Thread building script for component + +from building import * + +cwd = GetCurrentDir() +src = Glob('*.c') + +group = DefineGroup('POSIX', src, depend = ['RT_USING_POSIX']) + +Return('group') diff --git a/components/libc/compilers/common/delay.c b/components/libc/posix/src/delay.c similarity index 75% rename from components/libc/compilers/common/delay.c rename to components/libc/posix/src/delay.c index 4666258d3b56dab6c150b5d878e36dfac863d6f2..1638caafbf51c1edbe455b8772378ace1b671be3 100644 --- a/components/libc/compilers/common/delay.c +++ b/components/libc/posix/src/delay.c @@ -9,6 +9,15 @@ */ #include #include +#define DBG_TAG "POSIX.delay" +#define DBG_LVL DBG_INFO +#include + +RT_WEAK void rt_hw_us_delay(rt_uint32_t us) +{ + (void) us; + LOG_W("Please consider implementing rt_hw_us_delay() in another file."); +} void msleep(unsigned int msecs) { diff --git a/components/dfs/src/dfs_poll.c b/components/libc/posix/src/poll.c similarity index 98% rename from components/dfs/src/dfs_poll.c rename to components/libc/posix/src/poll.c index 607b3487befc0a796ad0aac2f89771b44da2af5f..2109fb310bff6d831c4213c8ce724825e7b485a9 100644 --- a/components/dfs/src/dfs_poll.c +++ b/components/libc/posix/src/poll.c @@ -9,14 +9,9 @@ * 2018-03-09 Bernard Add protection for pt->triggered. */ #include - #include -#include #include - -#include #include -#include #include #ifdef RT_USING_POSIX diff --git a/components/dfs/src/dfs_select.c b/components/libc/posix/src/select.c similarity index 98% rename from components/dfs/src/dfs_select.c rename to components/libc/posix/src/select.c index 795b816354f0e75e059c536df04186af617ecbe4..25cda0f0d138ea466826da1b503c6707d9aac354 100644 --- a/components/dfs/src/dfs_select.c +++ b/components/libc/posix/src/select.c @@ -7,10 +7,7 @@ * Date Author Notes * 2016-12-28 Bernard first version */ -#include -#include -#include - +#include #include #include diff --git a/components/dfs/src/dfs_posix.c b/components/libc/posix/src/unistd.c similarity index 91% rename from components/dfs/src/dfs_posix.c rename to components/libc/posix/src/unistd.c index acc05fcd53ec551befce0449a63ab40873d72c5e..ef2df2c2feb0ca97dd4157c1f8ed8047660fd497 100644 --- a/components/dfs/src/dfs_posix.c +++ b/components/libc/posix/src/unistd.c @@ -5,19 +5,15 @@ * * Change Logs: * Date Author Notes - * 2009-05-27 Yi.qiu The first version - * 2018-02-07 Bernard Change the 3rd parameter of open/fcntl/ioctl to '...' + * 2020-09-01 Meco Man first Version + * 2021-02-12 Meco Man move all functions located in to this file */ - -#include -#include -#include "dfs_private.h" - -/** - * @addtogroup FsPosixApi - */ - -/*@{*/ +#include +#include +#include +#include +#include +#include /** * this function is a POSIX compliant version, which will open a file and @@ -585,11 +581,6 @@ int mkdir(const char *path, mode_t mode) } RTM_EXPORT(mkdir); -#ifdef RT_USING_FINSH -#include -FINSH_FUNCTION_EXPORT(mkdir, create a directory); -#endif - /** * this function is a POSIX compliant version, which will remove a directory. * @@ -947,4 +938,107 @@ char *getcwd(char *buf, size_t size) } RTM_EXPORT(getcwd); -/* @} */ +#ifdef RT_USING_POSIX_TERMIOS +#include "termios.h" +int isatty(int fd) +{ + struct termios ts; + return(tcgetattr(fd, &ts) != -1); /*true if no error (is a tty)*/ +} +#else +int isatty(int fd) +{ + if (fd >=0 && fd < 3) + { + return 1; + } + else + { + return 0; + } +} +#endif +RTM_EXPORT(isatty); + +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/libc/posix/termios/SConscript b/components/libc/posix/termios/SConscript index 381eb5ad8bba4e86e55f5800e6ed258dadaf9348..bd9a5284613bb413a899db209990e5e32e078c2d 100644 --- a/components/libc/posix/termios/SConscript +++ b/components/libc/posix/termios/SConscript @@ -6,7 +6,7 @@ cwd = GetCurrentDir() src = Glob('*.c') + Glob('*.cpp') CPPPATH = [cwd] -group = DefineGroup('libc', src, +group = DefineGroup('POSIX', src, depend = ['RT_USING_LIBC', 'RT_USING_POSIX', 'RT_USING_POSIX_TERMIOS'], CPPPATH = CPPPATH) diff --git a/include/rtdebug.h b/include/rtdebug.h index 8c7d450ad4e6762b441e20a8acc2f996ad275e80..c170d148c10d25e1cdfc712ba08d8cd0f8121178 100644 --- a/include/rtdebug.h +++ b/include/rtdebug.h @@ -17,18 +17,7 @@ #if !defined(RT_USING_DFS) || !defined(RT_USING_DFS_DEVFS) #error "POSIX poll/select, stdin need file system(RT_USING_DFS) and device file system(RT_USING_DFS_DEVFS)" #endif - -#if !defined(RT_USING_LIBC) -#error "POSIX layer need standard C library(RT_USING_LIBC)" -#endif - -#endif - -#ifdef RT_USING_POSIX_TERMIOS -#if !defined(RT_USING_POSIX) -#error "termios need POSIX layer(RT_USING_POSIX)" -#endif -#endif +#endif /* RT_USING_POSIX */ /* Using this macro to control all kernel debug features. */ #ifdef RT_DEBUG