RTEMS CPU Kit with SuperCore  4.11.2
timestamp.h
Go to the documentation of this file.
1 
9 /*
10  * COPYRIGHT (c) 1989-2009.
11  * On-Line Applications Research Corporation (OAR).
12  *
13  * The license and distribution terms for this file may be
14  * found in the file LICENSE in this distribution or at
15  * http://www.rtems.org/license/LICENSE.
16  */
17 
18 #ifndef _RTEMS_SCORE_TIMESTAMP_H
19 #define _RTEMS_SCORE_TIMESTAMP_H
20 
43 #include <sys/time.h>
44 
45 #include <rtems/score/basedefs.h>
46 #include <rtems/score/timespec.h>
47 
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51 
55 typedef struct bintime Timestamp_Control;
56 
68  Timestamp_Control *_time,
69  time_t _seconds,
70  long _nanoseconds
71 )
72 {
73  struct timespec _ts;
74 
75  _ts.tv_sec = _seconds;
76  _ts.tv_nsec = _nanoseconds;
77 
78  timespec2bintime( &_ts, _time );
79 }
80 
91  Timestamp_Control *_time
92 )
93 {
94  _time->sec = 0;
95  _time->frac = 0;
96 }
97 
111  const Timestamp_Control *_lhs,
112  const Timestamp_Control *_rhs
113 )
114 {
115  if ( _lhs->sec < _rhs->sec )
116  return true;
117 
118  if ( _lhs->sec > _rhs->sec )
119  return false;
120 
121  return _lhs->frac < _rhs->frac;
122 }
123 
137  const Timestamp_Control *_lhs,
138  const Timestamp_Control *_rhs
139 )
140 {
141  if ( _lhs->sec > _rhs->sec )
142  return true;
143 
144  if ( _lhs->sec < _rhs->sec )
145  return false;
146 
147  return _lhs->frac > _rhs->frac;
148 }
149 
163  const Timestamp_Control *_lhs,
164  const Timestamp_Control *_rhs
165 )
166 {
167  return _lhs->sec == _rhs->sec && _lhs->frac == _rhs->frac;
168 }
169 
182  Timestamp_Control *_time,
183  const Timestamp_Control *_add
184 )
185 {
186  time_t seconds = _time->sec;
187 
188  bintime_add( _time, _add );
189 
190  return _time->sec - seconds;
191 }
192 
207  const Timestamp_Control *_start,
208  const Timestamp_Control *_end,
209  Timestamp_Control *_result
210 )
211 {
212  _result->sec = _end->sec;
213  _result->frac = _end->frac;
214 
215  bintime_sub( _result, _start );
216 }
217 
232  const Timestamp_Control *_lhs,
233  const Timestamp_Control *_rhs,
234  uint32_t *_ival_percentage,
235  uint32_t *_fval_percentage
236 )
237 {
238  struct timespec _ts_left;
239  struct timespec _ts_right;
240 
241  bintime2timespec( _lhs, &_ts_left );
242  bintime2timespec( _rhs, &_ts_right );
243 
245  &_ts_left,
246  &_ts_right,
247  _ival_percentage,
248  _fval_percentage
249  );
250 }
251 
262  const Timestamp_Control *_time
263 )
264 {
265  return _time->sec;
266 }
267 
278  const Timestamp_Control *_time
279 )
280 {
281  struct timespec _ts;
282 
283  bintime2timespec( _time, &_ts );
284 
285  return _ts.tv_nsec;
286 }
287 
298  const Timestamp_Control *_time
299 )
300 {
301  struct timespec _ts;
302 
303  bintime2timespec( _time, &_ts );
304 
305  return _Timespec_Get_as_nanoseconds( &_ts );
306 }
307 
317  const Timestamp_Control *_timestamp,
318  struct timespec *_timespec
319 )
320 {
321  bintime2timespec( _timestamp, _timespec );
322 }
323 
331  const Timestamp_Control *_timestamp,
332  struct timeval *_timeval
333 )
334 {
335  bintime2timeval( _timestamp, _timeval );
336 }
337 
338 #ifdef __cplusplus
339 }
340 #endif
341 
344 #endif
345 /* end of include file */
This include file contains helpers for manipulating timespecs.
RTEMS_INLINE_ROUTINE void _Timestamp_To_timeval(const Timestamp_Control *_timestamp, struct timeval *_timeval)
Convert timestamp to struct timeval.
Definition: timestamp.h:330
#define RTEMS_INLINE_ROUTINE
The following (in conjunction with compiler arguments) are used to choose between the use of static i...
Definition: basedefs.h:135
RTEMS_INLINE_ROUTINE bool _Timestamp_Equal_to(const Timestamp_Control *_lhs, const Timestamp_Control *_rhs)
Equal to than operator for timestamps.
Definition: timestamp.h:162
RTEMS_INLINE_ROUTINE uint32_t _Timestamp_Get_nanoseconds(const Timestamp_Control *_time)
Get nanoseconds portion of timestamp.
Definition: timestamp.h:277
RTEMS_INLINE_ROUTINE bool _Timestamp_Greater_than(const Timestamp_Control *_lhs, const Timestamp_Control *_rhs)
Greater than operator for timestamps.
Definition: timestamp.h:136
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
RTEMS_INLINE_ROUTINE time_t _Timestamp_Add_to(Timestamp_Control *_time, const Timestamp_Control *_add)
Adds two timestamps.
Definition: timestamp.h:181
struct bintime Timestamp_Control
Define the Timestamp control type.
Definition: timestamp.h:55
RTEMS_INLINE_ROUTINE void _Timestamp_Subtract(const Timestamp_Control *_start, const Timestamp_Control *_end, Timestamp_Control *_result)
Subtracts two timestamps.
Definition: timestamp.h:206
RTEMS_INLINE_ROUTINE time_t _Timestamp_Get_seconds(const Timestamp_Control *_time)
Get seconds portion of timestamp.
Definition: timestamp.h:261
RTEMS_INLINE_ROUTINE uint64_t _Timestamp_Get_as_nanoseconds(const Timestamp_Control *_time)
Get the timestamp as nanoseconds.
Definition: timestamp.h:297
RTEMS_INLINE_ROUTINE void _Timestamp_Set(Timestamp_Control *_time, time_t _seconds, long _nanoseconds)
Set timestamp to specified seconds and nanoseconds.
Definition: timestamp.h:67
RTEMS_INLINE_ROUTINE void _Timestamp_Divide(const Timestamp_Control *_lhs, const Timestamp_Control *_rhs, uint32_t *_ival_percentage, uint32_t *_fval_percentage)
Divides a timestamp by another timestamp.
Definition: timestamp.h:231
Basic Definitions.
RTEMS_INLINE_ROUTINE void _Timestamp_Set_to_zero(Timestamp_Control *_time)
Sets the timestamp to zero.
Definition: timestamp.h:90
RTEMS_INLINE_ROUTINE bool _Timestamp_Less_than(const Timestamp_Control *_lhs, const Timestamp_Control *_rhs)
Less than operator for timestamps.
Definition: timestamp.h:110
uint64_t _Timespec_Get_as_nanoseconds(const struct timespec *time)
Get the timestamp as nanoseconds.
Definition: timespecgetasnanoseconds.c:23
RTEMS_INLINE_ROUTINE void _Timestamp_To_timespec(const Timestamp_Control *_timestamp, struct timespec *_timespec)
Convert timestamp to struct timespec.
Definition: timestamp.h:316