RTEMS  5.0.0
timespec.h
Go to the documentation of this file.
1 
7 /*
8  * COPYRIGHT (c) 1989-2009.
9  * On-Line Applications Research Corporation (OAR).
10  *
11  * The license and distribution terms for this file may be
12  * found in the file LICENSE in this distribution or at
13  * http://www.rtems.org/license/LICENSE.
14  */
15 
16 #ifndef _RTEMS_SCORE_TIMESPEC_H
17 #define _RTEMS_SCORE_TIMESPEC_H
18 
29 #include <stdbool.h> /* bool */
30 #include <stdint.h> /* uint32_t */
31 #include <time.h> /* struct timespec */
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
47 #define _Timespec_Set( _time, _seconds, _nanoseconds ) \
48  do { \
49  (_time)->tv_sec = (_seconds); \
50  (_time)->tv_nsec = (_nanoseconds); \
51  } while (0)
52 
61 #define _Timespec_Set_to_zero( _time ) \
62  do { \
63  (_time)->tv_sec = 0; \
64  (_time)->tv_nsec = 0; \
65  } while (0)
66 
76 #define _Timespec_Get_seconds( _time ) \
77  ((_time)->tv_sec)
78 
88 #define _Timespec_Get_nanoseconds( _time ) \
89  ((_time)->tv_nsec)
90 
101  const struct timespec *time
102 );
103 
114 bool _Timespec_Is_valid(
115  const struct timespec *time
116 );
117 
130  const struct timespec *lhs,
131  const struct timespec *rhs
132 );
133 
145 #define _Timespec_Greater_than( _lhs, _rhs ) \
146  _Timespec_Less_than( _rhs, _lhs )
147 
159 #define _Timespec_Equal_to( lhs, rhs ) \
160  ( ((lhs)->tv_sec == (rhs)->tv_sec) && \
161  ((lhs)->tv_nsec == (rhs)->tv_nsec) \
162  )
163 
175 uint32_t _Timespec_Add_to(
176  struct timespec *time,
177  const struct timespec *add
178 );
179 
190 uint32_t _Timespec_To_ticks(
191  const struct timespec *time
192 );
193 
204  uint32_t ticks,
205  struct timespec *time
206 );
207 
220 void _Timespec_Subtract(
221  const struct timespec *start,
222  const struct timespec *end,
223  struct timespec *result
224 );
225 
240  const struct timespec *time,
241  uint32_t iterations,
242  struct timespec *result
243 );
244 
258 void _Timespec_Divide(
259  const struct timespec *lhs,
260  const struct timespec *rhs,
261  uint32_t *ival_percentage,
262  uint32_t *fval_percentage
263 );
264 
265 #ifdef __cplusplus
266 }
267 #endif
268 
271 #endif
272 /* end of include file */
uint32_t _Timespec_To_ticks(const struct timespec *time)
Convert timespec to number of ticks.
Definition: timespectoticks.c:27
bool _Timespec_Is_valid(const struct timespec *time)
Check if timespec is valid.
Definition: timespecisvalid.c:24
void _Timespec_Divide_by_integer(const struct timespec *time, uint32_t iterations, struct timespec *result)
Divide timespec by an integer.
Definition: timespecdividebyinteger.c:25
void _Timespec_Subtract(const struct timespec *start, const struct timespec *end, struct timespec *result)
Subtract two timespec.
Definition: timespecsubtract.c:24
void _Timespec_Divide(const struct timespec *lhs, const struct timespec *rhs, uint32_t *ival_percentage, uint32_t *fval_percentage)
Divide a timespec by anonther timespec.
Definition: timespecdivide.c:24
bool _Timespec_Less_than(const struct timespec *lhs, const struct timespec *rhs)
The Timespec "less than" operator.
Definition: timespeclessthan.c:25
void _Timespec_From_ticks(uint32_t ticks, struct timespec *time)
Convert ticks to timespec.
Definition: timespecfromticks.c:25
uint64_t _Timespec_Get_as_nanoseconds(const struct timespec *time)
Get the timestamp as nanoseconds.
Definition: timespecgetasnanoseconds.c:23
uint32_t _Timespec_Add_to(struct timespec *time, const struct timespec *add)
Add two timespecs.
Definition: timespecaddto.c:25