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 1515
1616#include <zephyr/sys_clock.h>
1717#include <zephyr/sys/__assert.h>
18+ #include <zephyr/posix/sys/time.h>
1819
1920#ifdef __cplusplus
2021extern "C" {
@@ -38,6 +39,12 @@ static inline int64_t ts_to_ms(const struct timespec *ts)
3839 return ts -> tv_sec * MSEC_PER_SEC + ts -> tv_nsec / NSEC_PER_MSEC ;
3940}
4041
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+
4148static inline bool tp_ge (const struct timespec * a , const struct timespec * b )
4249{
4350 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)
1010target_sources (app PRIVATE ${app_sources} )
1111
1212target_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 44 *
55 * SPDX-License-Identifier: Apache-2.0
66 */
7+
8+ #include "posix_clock.h"
9+
10+ #include <limits.h>
711#include <sys/time.h>
8- #include <time.h>
912#include <unistd.h>
1013
1114#include <zephyr/ztest.h>
1215#include <zephyr/logging/log.h>
1316
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-
3517ZTEST (clock , test_gettimeofday )
3618{
3719 struct timeval tv ;
You can’t perform that action at this time.
0 commit comments