diff options
| author | Meco Man <[email protected]> | 2021-06-16 12:15:24 +0800 |
|---|---|---|
| committer | Meco Man <[email protected]> | 2021-06-16 12:16:11 +0800 |
| commit | 6697fa0ff54219b6d0b4f65dd28cdcdd22e0158c (patch) | |
| tree | a93b377047940c4b1f2d62aefc7a876b408798c8 | |
| parent | ac50f5193ea8c11bf1d509a860d7989c51c53aea (diff) | |
[sleep] 加入调度器尚未运行时的延时情况
| -rw-r--r-- | components/libc/compilers/common/unistd.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/components/libc/compilers/common/unistd.c b/components/libc/compilers/common/unistd.c index 4385643f31..9a457c4200 100644 --- a/components/libc/compilers/common/unistd.c +++ b/components/libc/compilers/common/unistd.c @@ -37,19 +37,26 @@ RTM_EXPORT(isatty); char *ttyname(int fd) { - return "/dev/tty"; /*TODO: need to add more specific*/ + return "/dev/tty"; /* TODO: need to add more specific */ } RTM_EXPORT(ttyname); 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; + 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 seconds - delta_tick/RT_TICK_PER_SECOND; + return 0; } RTM_EXPORT(sleep); @@ -59,11 +66,12 @@ int usleep(useconds_t usec) { rt_thread_mdelay(usec / 1000u); } - else + else /* scheduler has not run yet */ { rt_hw_us_delay(usec / 1000u); } rt_hw_us_delay(usec % 1000u); + return 0; } RTM_EXPORT(usleep); |
