2018-10-14 19:28:18 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2006-2018, RT-Thread Development Team
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
2020-12-16 15:25:08 +08:00
|
|
|
* 2020-12-16 Meco Man add usleep
|
2018-10-14 19:28:18 +08:00
|
|
|
*/
|
2017-10-15 22:41:59 +08:00
|
|
|
#include <rtthread.h>
|
2020-12-16 15:34:41 +08:00
|
|
|
#include <rthw.h>
|
2017-10-15 22:41:59 +08:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2020-12-16 15:25:08 +08:00
|
|
|
|
|
|
|
int usleep(useconds_t usec)
|
|
|
|
{
|
2020-12-16 15:34:41 +08:00
|
|
|
rt_thread_mdelay(usec / 1000u);
|
|
|
|
rt_hw_us_delay(usec % 1000u);
|
|
|
|
return 0;
|
2020-12-16 15:25:08 +08:00
|
|
|
}
|