File tree Expand file tree Collapse file tree 3 files changed +12
-22
lines changed Expand file tree Collapse file tree 3 files changed +12
-22
lines changed Original file line number Diff line number Diff line change 15
15
16
16
#include <zephyr/sys_clock.h>
17
17
#include <zephyr/sys/__assert.h>
18
+ #include <zephyr/posix/sys/time.h>
18
19
19
20
#ifdef __cplusplus
20
21
extern "C" {
@@ -38,6 +39,12 @@ static inline int64_t ts_to_ms(const struct timespec *ts)
38
39
return ts -> tv_sec * MSEC_PER_SEC + ts -> tv_nsec / NSEC_PER_MSEC ;
39
40
}
40
41
42
+ static inline void tv_to_ts (const struct timeval * tv , struct timespec * ts )
43
+ {
44
+ ts -> tv_sec = tv -> tv_sec ;
45
+ ts -> tv_nsec = tv -> tv_usec * NSEC_PER_USEC ;
46
+ }
47
+
41
48
static inline bool tp_ge (const struct timespec * a , const struct timespec * b )
42
49
{
43
50
return ts_to_ns (a ) >= ts_to_ns (b );
Original file line number Diff line number Diff line change @@ -10,3 +10,4 @@ zephyr_include_directories(${ZEPHYR_BASE}/lib/posix)
10
10
target_sources (app PRIVATE ${app_sources} )
11
11
12
12
target_compile_options (app PRIVATE -U_POSIX_C_SOURCE -D_POSIX_C_SOURCE=200809L )
13
+ target_include_directories (app PRIVATE ${ZEPHYR_BASE} /lib/posix/options )
Original file line number Diff line number Diff line change 4
4
*
5
5
* SPDX-License-Identifier: Apache-2.0
6
6
*/
7
+
8
+ #include "posix_clock.h"
9
+
10
+ #include <limits.h>
7
11
#include <sys/time.h>
8
- #include <time.h>
9
12
#include <unistd.h>
10
13
11
14
#include <zephyr/ztest.h>
12
15
#include <zephyr/logging/log.h>
13
16
14
- static inline int64_t ts_to_ns (const struct timespec * ts )
15
- {
16
- return ts -> tv_sec * NSEC_PER_SEC + ts -> tv_nsec ;
17
- }
18
-
19
- static inline void tv_to_ts (const struct timeval * tv , struct timespec * ts )
20
- {
21
- ts -> tv_sec = tv -> tv_sec ;
22
- ts -> tv_nsec = tv -> tv_usec * NSEC_PER_USEC ;
23
- }
24
-
25
- #define _tp_op (_a , _b , _op ) (ts_to_ns(_a) _op ts_to_ns(_b))
26
-
27
- #define _decl_op (_type , _name , _op ) \
28
- static inline _type _name(const struct timespec *_a, const struct timespec *_b) \
29
- { \
30
- return _tp_op(_a, _b, _op); \
31
- }
32
-
33
- _decl_op (bool , tp_ge , >=); /* a >= b */
34
-
35
17
ZTEST (clock , test_gettimeofday )
36
18
{
37
19
struct timeval tv ;
You can’t perform that action at this time.
0 commit comments