From 2639171885a86a5b169a63a95cd2fb2776b97641 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 7 Nov 2021 21:03:16 -0500 Subject: [PATCH] add RT_USING_POSIX_DELAY --- components/libc/Kconfig | 4 ++++ components/libc/posix/src/SConscript | 8 +++++-- components/libc/posix/src/delay.c | 35 ++++++++++++++++++++++++++++ components/libc/posix/src/unistd.c | 35 ---------------------------- 4 files changed, 45 insertions(+), 37 deletions(-) diff --git a/components/libc/Kconfig b/components/libc/Kconfig index 04d59051b8..d10c0afd6a 100644 --- a/components/libc/Kconfig +++ b/components/libc/Kconfig @@ -53,6 +53,10 @@ if RT_USING_POSIX select RT_USING_POSIX_POLL default n + config RT_USING_POSIX_DELAY + bool "Enable delay functions" + default n + config RT_USING_POSIX_GETLINE bool "Enable getline()/getdelim() APIs" default n diff --git a/components/libc/posix/src/SConscript b/components/libc/posix/src/SConscript index ab649ec6bc..4c6d3e3b7b 100644 --- a/components/libc/posix/src/SConscript +++ b/components/libc/posix/src/SConscript @@ -1,7 +1,8 @@ +# RT-Thread building script for component + from building import * -Import('rtconfig') -src = ['libc.c','delay.c','unistd.c'] +src = ['libc.c', 'unistd.c'] cwd = GetCurrentDir() CPPPATH = [cwd] @@ -11,6 +12,9 @@ if GetDepend('RT_USING_POSIX_POLL'): if GetDepend('RT_USING_POSIX_SELECT'): src += ['select.c'] +if GetDepend('RT_USING_POSIX_DELAY'): + src += ['delay.c'] + group = DefineGroup('POSIX', src, depend = ['RT_USING_POSIX'], CPPPATH = CPPPATH) Return('group') diff --git a/components/libc/posix/src/delay.c b/components/libc/posix/src/delay.c index 1638caafbf..3842eb0aa8 100644 --- a/components/libc/posix/src/delay.c +++ b/components/libc/posix/src/delay.c @@ -48,3 +48,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/src/unistd.c b/components/libc/posix/src/unistd.c index 99ff768738..6527994c93 100644 --- a/components/libc/posix/src/unistd.c +++ b/components/libc/posix/src/unistd.c @@ -965,38 +965,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); -- GitLab