2021-06-16 14:02:43 +08:00
|
|
|
/*
|
2023-03-30 11:25:18 +08:00
|
|
|
* Copyright (c) 2006-2023, RT-Thread Development Team
|
2021-06-16 14:02:43 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2021-05-07 Meco Man first Version
|
|
|
|
*/
|
2022-01-08 23:29:41 +08:00
|
|
|
|
2021-11-08 15:07:07 +08:00
|
|
|
#include <sys/types.h>
|
2021-06-16 14:02:43 +08:00
|
|
|
#include <rtthread.h>
|
|
|
|
#include <rthw.h>
|
|
|
|
|
|
|
|
void msleep(unsigned int msecs)
|
|
|
|
{
|
|
|
|
rt_thread_mdelay(msecs);
|
|
|
|
}
|
|
|
|
RTM_EXPORT(msleep);
|
|
|
|
|
|
|
|
void ssleep(unsigned int seconds)
|
|
|
|
{
|
|
|
|
msleep(seconds * 1000);
|
|
|
|
}
|
|
|
|
RTM_EXPORT(ssleep);
|
|
|
|
|
|
|
|
void mdelay(unsigned long msecs)
|
|
|
|
{
|
|
|
|
rt_hw_us_delay(msecs * 1000);
|
|
|
|
}
|
|
|
|
RTM_EXPORT(mdelay);
|
|
|
|
|
|
|
|
void udelay(unsigned long usecs)
|
|
|
|
{
|
|
|
|
rt_hw_us_delay(usecs);
|
|
|
|
}
|
|
|
|
RTM_EXPORT(udelay);
|
|
|
|
|
|
|
|
void ndelay(unsigned long nsecs)
|
|
|
|
{
|
|
|
|
rt_hw_us_delay(1);
|
|
|
|
}
|
|
|
|
RTM_EXPORT(ndelay);
|
2021-11-08 10:03:16 +08:00
|
|
|
|
|
|
|
unsigned int sleep(unsigned int seconds)
|
|
|
|
{
|
|
|
|
if (rt_thread_self() != RT_NULL)
|
|
|
|
{
|
|
|
|
ssleep(seconds);
|
|
|
|
}
|
|
|
|
else /* scheduler has not run yet */
|
|
|
|
{
|
|
|
|
while(seconds > 0)
|
|
|
|
{
|
|
|
|
udelay(1000000u);
|
|
|
|
seconds --;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
RTM_EXPORT(sleep);
|
|
|
|
|
|
|
|
int usleep(useconds_t usec)
|
|
|
|
{
|
|
|
|
if (rt_thread_self() != RT_NULL)
|
|
|
|
{
|
|
|
|
msleep(usec / 1000u);
|
2023-03-30 11:25:18 +08:00
|
|
|
udelay(usec % 1000u);
|
2021-11-08 10:03:16 +08:00
|
|
|
}
|
|
|
|
else /* scheduler has not run yet */
|
|
|
|
{
|
2023-03-30 11:25:18 +08:00
|
|
|
udelay(usec);
|
2021-11-08 10:03:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
RTM_EXPORT(usleep);
|