1 /*
2  * Copyright (c) 2018 Intel Corporation
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <errno.h>
8 
9 #include <zephyr/kernel.h>
10 #include <zephyr/posix/unistd.h>
11 
12 /**
13  * @brief Sleep for a specified number of seconds.
14  *
15  * See IEEE 1003.1
16  */
sleep(unsigned int seconds)17 unsigned sleep(unsigned int seconds)
18 {
19 	int rem;
20 
21 	rem = k_sleep(K_SECONDS(seconds));
22 	__ASSERT_NO_MSG(rem >= 0);
23 
24 	return rem / MSEC_PER_SEC;
25 }
26 /**
27  * @brief Suspend execution for microsecond intervals.
28  *
29  * See IEEE 1003.1
30  */
usleep(useconds_t useconds)31 int usleep(useconds_t useconds)
32 {
33 	int32_t rem;
34 
35 	if (useconds >= USEC_PER_SEC) {
36 		errno = EINVAL;
37 		return -1;
38 	}
39 
40 	rem = k_usleep(useconds);
41 	__ASSERT_NO_MSG(rem >= 0);
42 	if (rem > 0) {
43 		/* sleep was interrupted by a call to k_wakeup() */
44 		errno = EINTR;
45 		return -1;
46 	}
47 
48 	return 0;
49 }
50