From 66b7289ee75653f6024ca3b9c0bdff96fe0bc046 Mon Sep 17 00:00:00 2001 From: guozhanxin Date: Tue, 15 Jun 2021 18:29:58 +0800 Subject: [PATCH] [update] usleep supports calling in interrupts. --- components/libc/compilers/common/unistd.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/components/libc/compilers/common/unistd.c b/components/libc/compilers/common/unistd.c index 6c81fc7662..4385643f31 100644 --- a/components/libc/compilers/common/unistd.c +++ b/components/libc/compilers/common/unistd.c @@ -55,7 +55,14 @@ RTM_EXPORT(sleep); int usleep(useconds_t usec) { - rt_thread_mdelay(usec / 1000u); + if (rt_thread_self() != RT_NULL) + { + rt_thread_mdelay(usec / 1000u); + } + else + { + rt_hw_us_delay(usec / 1000u); + } rt_hw_us_delay(usec % 1000u); return 0; }