diff --git a/components/libc/compilers/common/unistd.c b/components/libc/compilers/common/unistd.c index df970b2b59..b7471ee029 100644 --- a/components/libc/compilers/common/unistd.c +++ b/components/libc/compilers/common/unistd.c @@ -5,10 +5,13 @@ * * Change Logs: * Date Author Notes - * 2020-09-01 Meco Man First Version + * 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" @@ -24,3 +27,21 @@ char *ttyname(int fd) { return "/dev/tty0"; /*TODO: need to add more specific*/ } + +unsigned int sleep(unsigned int seconds) +{ + rt_tick_t delta_tick; + + delta_tick = rt_tick_get(); + rt_thread_delay(seconds * RT_TICK_PER_SECOND); + delta_tick = rt_tick_get() - delta_tick; + + return seconds - delta_tick/RT_TICK_PER_SECOND; +} + +int usleep(useconds_t usec) +{ + rt_thread_mdelay(usec / 1000u); + rt_hw_us_delay(usec % 1000u); + return 0; +} diff --git a/components/libc/pthreads/posix_sleep.c b/components/libc/pthreads/posix_sleep.c deleted file mode 100644 index e50bda7d4a..0000000000 --- a/components/libc/pthreads/posix_sleep.c +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2006-2018, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2020-12-16 Meco Man add usleep - */ -#include -#include -#include - -unsigned int sleep(unsigned int seconds) -{ - rt_tick_t delta_tick; - - delta_tick = rt_tick_get(); - rt_thread_delay(seconds * RT_TICK_PER_SECOND); - delta_tick = rt_tick_get() - delta_tick; - - return seconds - delta_tick/RT_TICK_PER_SECOND; -} - -int usleep(useconds_t usec) -{ - rt_thread_mdelay(usec / 1000u); - rt_hw_us_delay(usec % 1000u); - return 0; -}