18 #ifndef _COBALT_POSIX_CLOCK_H
19 #define _COBALT_POSIX_CLOCK_H
21 #include <linux/types.h>
22 #include <linux/time.h>
23 #include <cobalt/uapi/time.h>
24 #include <xenomai/posix/syscall.h>
26 #define ONE_BILLION 1000000000
28 static inline void ns2ts(
struct timespec *ts, xnticks_t nsecs)
30 ts->tv_sec = xnclock_divrem_billion(nsecs, &ts->tv_nsec);
33 static inline xnticks_t ts2ns(
const struct timespec *ts)
35 xnticks_t nsecs = ts->tv_nsec;
38 nsecs += (xnticks_t)ts->tv_sec * ONE_BILLION;
43 static inline xnticks_t tv2ns(
const struct timeval *tv)
45 xnticks_t nsecs = tv->tv_usec * 1000;
48 nsecs += (xnticks_t)tv->tv_sec * ONE_BILLION;
53 static inline void ticks2tv(
struct timeval *tv, xnticks_t ticks)
57 tv->tv_sec = xnclock_divrem_billion(ticks, &nsecs);
58 tv->tv_usec = nsecs / 1000;
61 static inline xnticks_t clock_get_ticks(clockid_t clock_id)
63 return clock_id == CLOCK_REALTIME ?
64 xnclock_read_realtime(&nkclock) :
65 xnclock_read_monotonic(&nkclock);
68 static inline int clock_flag(
int flag, clockid_t clock_id)
70 switch(flag & TIMER_ABSTIME) {
77 case CLOCK_MONOTONIC_RAW:
87 int __cobalt_clock_getres(clockid_t clock_id,
90 int __cobalt_clock_gettime(clockid_t clock_id,
93 int __cobalt_clock_settime(clockid_t clock_id,
94 const struct timespec *ts);
96 int __cobalt_clock_nanosleep(clockid_t clock_id,
int flags,
97 const struct timespec *rqt,
98 struct timespec *rmt);
101 (clockid_t clock_id,
struct timespec __user *u_ts));
104 (clockid_t clock_id,
struct timespec __user *u_ts));
107 (clockid_t clock_id,
const struct timespec __user *u_ts));
110 (clockid_t clock_id,
int flags,
111 const struct timespec __user *u_rqt,
112 struct timespec __user *u_rmt));
114 int cobalt_clock_register(
struct xnclock *clock,
117 void cobalt_clock_deregister(
struct xnclock *clock);
119 extern DECLARE_BITMAP(cobalt_clock_extids, COBALT_MAX_EXTCLOCKS);
int clock_getres(clockid_t clock_id, struct timespec *tp)
Get the resolution of the specified clock.
Definition: clock.c:99
int clock_settime(clockid_t clock_id, const struct timespec *tp)
Set the specified clock.
Definition: clock.c:233
int clock_gettime(clockid_t clock_id, struct timespec *tp)
Read the specified clock.
Definition: clock.c:179
int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *rqtp, struct timespec *rmtp)
Sleep some amount of time.
Definition: clock.c:287