Xenomai  3.0.5
timer.h
1 /*
2  * Copyright (C) 2011 Philippe Gerum <rpm@xenomai.org>.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13 
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18 #ifndef _XENOMAI_ALCHEMY_TIMER_H
19 #define _XENOMAI_ALCHEMY_TIMER_H
20 
21 #include <stddef.h>
22 #include <copperplate/clockobj.h>
23 
29 typedef ticks_t RTIME;
30 
31 typedef sticks_t SRTIME;
32 
33 #define TM_INFINITE 0
34 #define TM_NOW 0
35 #define TM_NONBLOCK ((RTIME)-1ULL)
36 
44 typedef struct rt_timer_info {
48  RTIME period;
55  RTIME date;
57 
58 extern struct clockobj alchemy_clock;
59 
60 #define alchemy_abs_timeout(__t, __ts) \
61  ({ \
62  (__t) == TM_INFINITE ? NULL : \
63  (__t) == TM_NONBLOCK ? \
64  ({ (__ts)->tv_sec = (__ts)->tv_nsec = 0; (__ts); }) : \
65  ({ clockobj_ticks_to_timespec(&alchemy_clock, (__t), (__ts)); \
66  (__ts); }); \
67  })
68 
69 #define alchemy_rel_timeout(__t, __ts) \
70  ({ \
71  (__t) == TM_INFINITE ? NULL : \
72  (__t) == TM_NONBLOCK ? \
73  ({ (__ts)->tv_sec = (__ts)->tv_nsec = 0; (__ts); }) : \
74  ({ clockobj_ticks_to_timeout(&alchemy_clock, (__t), (__ts)); \
75  (__ts); }); \
76  })
77 
78 static inline
79 int alchemy_poll_mode(const struct timespec *abs_timeout)
80 {
81  return abs_timeout &&
82  abs_timeout->tv_sec == 0 &&
83  abs_timeout->tv_nsec == 0;
84 }
85 
86 #ifdef __cplusplus
87 extern "C" {
88 #endif
89 
104 static inline RTIME rt_timer_read(void)
105 {
106  return clockobj_get_time(&alchemy_clock);
107 }
108 
109 SRTIME rt_timer_ns2ticks(SRTIME ns);
110 
111 SRTIME rt_timer_ticks2ns(SRTIME ticks);
112 
113 RTIME rt_timer_read(void);
114 
115 void rt_timer_inquire(RT_TIMER_INFO *info);
116 
117 void rt_timer_spin(RTIME ns);
118 
119 #ifdef __cplusplus
120 }
121 #endif
122 
125 #endif /* _ALCHEMY_TIMER_H */
void rt_timer_spin(RTIME ns)
Busy wait burning CPU cycles.
Definition: timer.c:108
RTIME date
Current monotonic date expressed in clock ticks.
Definition: timer.h:55
static RTIME rt_timer_read(void)
Return the current system time.
Definition: timer.h:104
Timer status descriptor.
Definition: timer.h:44
RTIME period
Clock resolution in nanoseconds.
Definition: timer.h:48
struct rt_timer_info RT_TIMER_INFO
Timer status descriptor.
void rt_timer_inquire(RT_TIMER_INFO *info)
Inquire about the Alchemy clock.
Definition: timer.c:88
SRTIME rt_timer_ticks2ns(SRTIME ticks)
Convert Alchemy clock ticks to nanoseconds.
Definition: timer.c:72
SRTIME rt_timer_ns2ticks(SRTIME ns)
Convert nanoseconds to Alchemy clock ticks.
Definition: timer.c:50