4
0
mirror of https://github.com/RT-Thread/rt-thread.git synced 2025-02-21 06:07:10 +08:00

Merge pull request #4797 from Guozhanxin/usleep

[update] usleep supports calling in interrupts.
This commit is contained in:
guo 2021-06-15 18:49:57 +08:00 committed by GitHub
commit 302c8bf23f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;
}