2018-03-27 16:24:01 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 Intel Corporation
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
2018-04-06 01:11:15 +08:00
|
|
|
|
2022-11-24 10:54:22 +08:00
|
|
|
#include <errno.h>
|
|
|
|
|
2022-05-06 17:23:05 +08:00
|
|
|
#include <zephyr/kernel.h>
|
|
|
|
#include <zephyr/posix/unistd.h>
|
2018-03-27 16:24:01 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Sleep for a specified number of seconds.
|
|
|
|
*
|
|
|
|
* See IEEE 1003.1
|
|
|
|
*/
|
|
|
|
unsigned sleep(unsigned int seconds)
|
|
|
|
{
|
2022-11-24 10:44:27 +08:00
|
|
|
int rem;
|
|
|
|
|
|
|
|
rem = k_sleep(K_SECONDS(seconds));
|
|
|
|
__ASSERT_NO_MSG(rem >= 0);
|
|
|
|
|
|
|
|
return rem / MSEC_PER_SEC;
|
2018-03-27 16:24:01 +08:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @brief Suspend execution for microsecond intervals.
|
|
|
|
*
|
|
|
|
* See IEEE 1003.1
|
|
|
|
*/
|
|
|
|
int usleep(useconds_t useconds)
|
|
|
|
{
|
2022-11-24 10:54:22 +08:00
|
|
|
int32_t rem;
|
|
|
|
|
|
|
|
if (useconds >= USEC_PER_SEC) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
rem = k_usleep(useconds);
|
|
|
|
__ASSERT_NO_MSG(rem >= 0);
|
|
|
|
if (rem > 0) {
|
|
|
|
/* sleep was interrupted by a call to k_wakeup() */
|
|
|
|
errno = EINTR;
|
|
|
|
return -1;
|
2018-03-27 16:24:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|