summaryrefslogtreecommitdiff
path: root/components/libc/compilers
diff options
context:
space:
mode:
authorMeco Man <[email protected]>2021-02-12 02:12:33 +0800
committerMeco Man <[email protected]>2021-02-12 02:12:33 +0800
commit789f1a875346d47edc7b11dd423ce891acbae3a9 (patch)
tree4563a53291e9294d73e570c85c81443a23a6e845 /components/libc/compilers
parent417f8b9bed25d12a4b61150138125e8bd9c38fc4 (diff)
move all functions located in <pthread_sleep.c> to this file
Diffstat (limited to 'components/libc/compilers')
-rw-r--r--components/libc/compilers/common/unistd.c23
1 files changed, 22 insertions, 1 deletions
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 <pthread_sleep.c> to this file
*/
#include <unistd.h>
+#include <rtthread.h>
+#include <rthw.h>
#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;
+}