18 #ifndef _COBALT_POSIX_CLOCK_H
19 #define _COBALT_POSIX_CLOCK_H
21 #include <linux/types.h>
22 #include <linux/time.h>
23 #include <linux/cpumask.h>
24 #include <cobalt/uapi/time.h>
25 #include <xenomai/posix/syscall.h>
27 #define ONE_BILLION 1000000000
29 static inline void ns2ts(
struct timespec *ts, xnticks_t nsecs)
31 ts->tv_sec = xnclock_divrem_billion(nsecs, &ts->tv_nsec);
34 static inline xnticks_t ts2ns(
const struct timespec *ts)
36 xnticks_t nsecs = ts->tv_nsec;
39 nsecs += (xnticks_t)ts->tv_sec * ONE_BILLION;
44 static inline xnticks_t tv2ns(
const struct timeval *tv)
46 xnticks_t nsecs = tv->tv_usec * 1000;
49 nsecs += (xnticks_t)tv->tv_sec * ONE_BILLION;
54 static inline void ticks2tv(
struct timeval *tv, xnticks_t ticks)
58 tv->tv_sec = xnclock_divrem_billion(ticks, &nsecs);
59 tv->tv_usec = nsecs / 1000;
62 static inline xnticks_t clock_get_ticks(clockid_t clock_id)
64 return clock_id == CLOCK_REALTIME ?
65 xnclock_read_realtime(&nkclock) :
66 xnclock_read_monotonic(&nkclock);
69 static inline int clock_flag(
int flag, clockid_t clock_id)
71 switch(flag & TIMER_ABSTIME) {
78 case CLOCK_MONOTONIC_RAW:
88 int __cobalt_clock_getres(clockid_t clock_id,
91 int __cobalt_clock_gettime(clockid_t clock_id,
94 int __cobalt_clock_settime(clockid_t clock_id,
95 const struct timespec *ts);
97 int __cobalt_clock_nanosleep(clockid_t clock_id,
int flags,
98 const struct timespec *rqt,
99 struct timespec *rmt);
102 (clockid_t clock_id,
struct timespec __user *u_ts));
105 (clockid_t clock_id,
struct timespec __user *u_ts));
108 (clockid_t clock_id,
const struct timespec __user *u_ts));
111 (clockid_t clock_id,
int flags,
112 const struct timespec __user *u_rqt,
113 struct timespec __user *u_rmt));
115 int cobalt_clock_register(
struct xnclock *clock,
116 const cpumask_t *affinity,
119 void cobalt_clock_deregister(
struct xnclock *clock);
121 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:100
int clock_settime(clockid_t clock_id, const struct timespec *tp)
Set the specified clock.
Definition: clock.c:236
int clock_gettime(clockid_t clock_id, struct timespec *tp)
Read the specified clock.
Definition: clock.c:181
int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *rqtp, struct timespec *rmtp)
Sleep some amount of time.
Definition: clock.c:291