23 #ifndef _XENO_NUCLEUS_TIMEBASE_H
24 #define _XENO_NUCLEUS_TIMEBASE_H
29 #include <nucleus/queue.h>
31 #if defined(__KERNEL__) || defined(__XENO_SIM__)
37 typedef struct xntbops {
39 int (*start_timer)(
struct xntimer *timer,
43 void (*stop_timer)(
struct xntimer *timer);
44 xnticks_t (*get_timer_date)(
struct xntimer *timer);
45 xnticks_t (*get_timer_timeout)(
struct xntimer *timer);
46 xnticks_t (*get_timer_interval)(
struct xntimer *timer);
47 xnticks_t (*get_timer_raw_expiry)(
struct xntimer *timer);
48 void (*move_timer)(
struct xntimer *timer);
52 #define XNTBRUN 0x00000001
53 #define XNTBSET 0x00000002
54 #define XNTBLCK 0x00000004
55 #define XNTBISO 0x00000008
57 typedef struct xntbase {
65 xnticks_t wallclock_offset;
77 #define link2tbase(ln) container_of(ln, xntbase_t, link)
79 #ifdef CONFIG_XENO_OPT_STATS
82 struct xnqueue timerq;
91 extern xntbase_t nktbase;
93 extern xnqueue_t nktimebaseq;
95 static inline u_long xntbase_get_ticks2sec(xntbase_t *base)
97 return base->ticks2sec;
100 static inline u_long xntbase_get_tickval(xntbase_t *base)
103 return base->tickvalue;
106 static inline xnticks_t xntbase_get_wallclock_offset(xntbase_t *base)
108 return base->wallclock_offset;
111 static inline void xntbase_set_hook(xntbase_t *base,
void (*hook)(
void))
116 static inline int xntbase_timeset_p(xntbase_t *base)
118 return !!testbits(base->status, XNTBSET);
121 static inline int xntbase_enabled_p(xntbase_t *base)
123 return !!testbits(base->status, XNTBRUN);
126 static inline int xntbase_isolated_p(xntbase_t *base)
128 return !!testbits(base->status, XNTBISO);
131 static inline const char *xntbase_name(xntbase_t *base)
136 #ifdef CONFIG_XENO_OPT_TIMING_PERIODIC
138 static inline xntime_t xntbase_ticks2ns(xntbase_t *base, xnticks_t ticks)
141 return ticks * xntbase_get_tickval(base);
144 static inline xnticks_t xntbase_ns2ticks(xntbase_t *base, xntime_t t)
146 return xnarch_ulldiv(t, xntbase_get_tickval(base), NULL);
149 static inline int xntbase_master_p(xntbase_t *base)
151 return base == &nktbase;
154 static inline int xntbase_periodic_p(xntbase_t *base)
156 return !xntbase_master_p(base);
159 static inline xnticks_t xntbase_get_jiffies(xntbase_t *base)
161 return xntbase_periodic_p(base) ? base->jiffies : xnarch_get_cpu_time();
164 static inline xnticks_t xntbase_get_rawclock(xntbase_t *base)
166 return xntbase_periodic_p(base) ? base->jiffies : xnarch_get_cpu_tsc();
189 xnticks_t xntbase_ns2ticks_ceil(xntbase_t *base, xntime_t t);
199 static inline xntime_t xntbase_ticks2ns(xntbase_t *base, xnticks_t ticks)
204 static inline xnticks_t xntbase_ns2ticks(xntbase_t *base, xntime_t t)
209 static inline xnticks_t xntbase_ns2ticks_ceil(xntbase_t *base, xntime_t t)
214 static inline int xntbase_master_p(xntbase_t *base)
219 static inline xnticks_t
xntbase_convert(xntbase_t *srcbase, xnticks_t ticks, xntbase_t *dstbase)
224 static inline int xntbase_periodic_p(xntbase_t *base)
229 static inline xnticks_t xntbase_get_jiffies(xntbase_t *base)
231 return xnarch_get_cpu_time();
234 static inline xnticks_t xntbase_get_rawclock(xntbase_t *base)
236 return xnarch_get_cpu_tsc();
239 static inline int xntbase_alloc(
const char *name, u_long period, u_long flags, xntbase_t **basep)
254 static inline int xntbase_switch(
const char *name, u_long period, xntbase_t **basep)
256 return period == XN_APERIODIC_TICK ? 0 : -ENODEV;
305 return xntbase_get_jiffies(base) + base->wallclock_offset;
314 #define xntbase_mount() \
316 inith(&nktbase.link); \
317 appendq(&nktimebaseq, &nktbase.link); \
318 xntbase_declare_proc(&nktbase); \
321 #define xntbase_umount() \
323 xntbase_remove_proc(&nktbase); \
324 removeq(&nktimebaseq, &nktbase.link); \
327 void xntbase_init_proc(
void);
329 void xntbase_cleanup_proc(
void);
331 #ifdef CONFIG_XENO_OPT_STATS
332 void xntbase_declare_proc(xntbase_t *base);
333 void xntbase_remove_proc(xntbase_t *base);
335 static inline void xntbase_declare_proc(xntbase_t *base) { }
336 static inline void xntbase_remove_proc(xntbase_t *base) { }
xnticks_t xntbase_convert(xntbase_t *srcbase, xnticks_t ticks, xntbase_t *dstbase)
Convert a clock value into another time base.
Definition: timebase.c:531
This file is part of the Xenomai project.
void xntimer_tick_aperiodic(void)
Process a timer tick for the aperiodic master time base.
Definition: timer.c:339
int xntbase_alloc(const char *name, u_long period, u_long flags, xntbase_t **basep)
Allocate a time base.
Definition: timebase.c:125
Snapshot revision tag.
Definition: vfile.h:490
void xntbase_adjust_time(xntbase_t *base, xnsticks_t delta)
Adjust the clock time for the system.
Definition: timebase.c:586
static xnticks_t xntbase_get_time(xntbase_t *base)
Get the clock time for a given time base.
Definition: timebase.h:301
void xntbase_free(xntbase_t *base)
Free a time base.
Definition: timebase.c:201
int xntbase_switch(const char *name, u_long period, xntbase_t **basep)
Replace a time base.
Definition: timebase.c:318
void xntbase_tick(xntbase_t *base)
Announce a clock tick to a time base.
Definition: timebase.c:478
void xntbase_start(xntbase_t *base)
Start a time base.
Definition: timebase.c:381
int xntbase_update(xntbase_t *base, u_long period)
Change the period of a time base.
Definition: timebase.c:251
Snapshot vfile descriptor.
Definition: vfile.h:514
void xntbase_stop(xntbase_t *base)
Stop a time base.
Definition: timebase.c:438