Line data Source code
1 0 : /*
2 : * Copyright (c) 2018 Intel Corporation
3 : *
4 : * SPDX-License-Identifier: Apache-2.0
5 : */
6 : #ifndef ZEPHYR_INCLUDE_POSIX_TIME_H_
7 : #define ZEPHYR_INCLUDE_POSIX_TIME_H_
8 :
9 : /* Read standard header. This may find <posix/time.h> since they
10 : * refer to the same file when include/posix is in the search path.
11 : */
12 : #include <time.h>
13 :
14 : #ifdef CONFIG_NEWLIB_LIBC
15 : /* Kludge to support outdated newlib version as used in SDK 0.10 for Xtensa */
16 : #include <newlib.h>
17 :
18 : #ifdef __NEWLIB__
19 : /* Newever Newlib 3.x+ */
20 : #include <sys/timespec.h>
21 : #else /* __NEWLIB__ */
22 : /* Workaround for older Newlib 2.x, as used by Xtensa. It lacks sys/_timeval.h,
23 : * so mimic it here.
24 : */
25 : #include <sys/types.h>
26 : #ifndef __timespec_defined
27 :
28 : #ifdef __cplusplus
29 : extern "C" {
30 : #endif
31 :
32 : struct timespec {
33 : time_t tv_sec;
34 : long tv_nsec;
35 : };
36 :
37 : struct itimerspec {
38 : struct timespec it_interval; /* Timer interval */
39 : struct timespec it_value; /* Timer expiration */
40 : };
41 :
42 : #ifdef __cplusplus
43 : }
44 : #endif
45 :
46 : #endif /* __timespec_defined */
47 : #endif /* __NEWLIB__ */
48 :
49 : #else /* CONFIG_NEWLIB_LIBC */
50 : /* Not Newlib */
51 : # if defined(CONFIG_ARCH_POSIX) && defined(CONFIG_EXTERNAL_LIBC)
52 : # include <bits/types/struct_timespec.h>
53 : # include <bits/types/struct_itimerspec.h>
54 : # else
55 : # include <sys/timespec.h>
56 : # endif
57 : #endif /* CONFIG_NEWLIB_LIBC */
58 :
59 : #include <zephyr/kernel.h>
60 : #include <errno.h>
61 : #include <zephyr/posix/posix_types.h>
62 : #include <zephyr/posix/signal.h>
63 : #include <zephyr/sys/clock.h>
64 :
65 : #ifdef __cplusplus
66 : extern "C" {
67 : #endif
68 :
69 : #ifndef CLOCK_REALTIME
70 0 : #define CLOCK_REALTIME SYS_CLOCK_REALTIME
71 : #endif
72 :
73 : #ifndef CLOCK_PROCESS_CPUTIME_ID
74 0 : #define CLOCK_PROCESS_CPUTIME_ID 2
75 : #endif
76 :
77 : #ifndef CLOCK_THREAD_CPUTIME_ID
78 0 : #define CLOCK_THREAD_CPUTIME_ID 3
79 : #endif
80 :
81 : #ifndef CLOCK_MONOTONIC
82 0 : #define CLOCK_MONOTONIC SYS_CLOCK_MONOTONIC
83 : #endif
84 :
85 : #ifndef TIMER_ABSTIME
86 0 : #define TIMER_ABSTIME SYS_TIMER_ABSTIME
87 : #endif
88 :
89 0 : int clock_gettime(clockid_t clock_id, struct timespec *ts);
90 0 : int clock_getres(clockid_t clock_id, struct timespec *ts);
91 0 : int clock_settime(clockid_t clock_id, const struct timespec *ts);
92 0 : int clock_getcpuclockid(pid_t pid, clockid_t *clock_id);
93 : /* Timer APIs */
94 0 : int timer_create(clockid_t clockId, struct sigevent *evp, timer_t *timerid);
95 0 : int timer_delete(timer_t timerid);
96 : struct itimerspec;
97 0 : int timer_gettime(timer_t timerid, struct itimerspec *its);
98 0 : int timer_settime(timer_t timerid, int flags, const struct itimerspec *value,
99 : struct itimerspec *ovalue);
100 0 : int timer_getoverrun(timer_t timerid);
101 0 : int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
102 0 : int clock_nanosleep(clockid_t clock_id, int flags,
103 : const struct timespec *rqtp, struct timespec *rmtp);
104 :
105 : #ifdef __cplusplus
106 : }
107 : #endif
108 :
109 : #else /* ZEPHYR_INCLUDE_POSIX_TIME_H_ */
110 : /* Read the toolchain header when <posix/time.h> finds itself on the
111 : * first attempt.
112 : */
113 : #include_next <time.h>
114 : #endif /* ZEPHYR_INCLUDE_POSIX_TIME_H_ */
|