RTEMS: cpukit/include/rtems/score/timestampimpl.h Source File

| RTEMS 5.4-rc2

Loading...
Searching...
No Matches
timestampimpl.h
Go to the documentation of this file.
1
11/*
12 * COPYRIGHT (c) 1989-2009.
13 * On-Line Applications Research Corporation (OAR).
14 *
15 * The license and distribution terms for this file may be
16 * found in the file LICENSE in this distribution or at
17 * http://www.rtems.org/license/LICENSE.
18 */
19
20#ifndef _RTEMS_SCORE_TIMESTAMPIMPL_H
21#define _RTEMS_SCORE_TIMESTAMPIMPL_H
22
29#include <rtems/score/timestamp.h>
30#include <rtems/score/basedefs.h>
31
32#include <sys/time.h>
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
48 RTEMS_INLINE_ROUTINE void _Timestamp_Set(
49 Timestamp_Control *_time,
50 time_t _seconds,
51 long _nanoseconds
52)
53{
54 struct timespec _ts;
55
56 _ts.tv_sec = _seconds;
57 _ts.tv_nsec = _nanoseconds;
58
59 *_time = tstosbt(_ts);
60}
61
71 RTEMS_INLINE_ROUTINE void _Timestamp_Set_to_zero(
72 Timestamp_Control *_time
73)
74{
75 *_time = 0;
76}
77
90 RTEMS_INLINE_ROUTINE bool _Timestamp_Less_than(
91 const Timestamp_Control *_lhs,
92 const Timestamp_Control *_rhs
93)
94{
95 return *_lhs < *_rhs;
96}
97
110 RTEMS_INLINE_ROUTINE bool _Timestamp_Greater_than(
111 const Timestamp_Control *_lhs,
112 const Timestamp_Control *_rhs
113)
114{
115 return *_lhs > *_rhs;
116}
117
130 RTEMS_INLINE_ROUTINE bool _Timestamp_Equal_to(
131 const Timestamp_Control *_lhs,
132 const Timestamp_Control *_rhs
133)
134{
135 return *_lhs == *_rhs;
136}
137
147 RTEMS_INLINE_ROUTINE void _Timestamp_Add_to(
148 Timestamp_Control *_time,
149 const Timestamp_Control *_add
150)
151{
152 *_time += *_add;
153}
154
166 RTEMS_INLINE_ROUTINE void _Timestamp_Subtract(
167 const Timestamp_Control *_start,
168 const Timestamp_Control *_end,
169 Timestamp_Control *_result
170)
171{
172 *_result = *_end - *_start;
173}
174
186 RTEMS_INLINE_ROUTINE void _Timestamp_Divide(
187 const Timestamp_Control *_lhs,
188 const Timestamp_Control *_rhs,
189 uint32_t *_ival_percentage,
190 uint32_t *_fval_percentage
191)
192{
193 struct timespec _ts_left;
194 struct timespec _ts_right;
195
196 _ts_left = sbttots( *_lhs );
197 _ts_right = sbttots( *_rhs );
198
199 _Timespec_Divide(
200 &_ts_left,
201 &_ts_right,
202 _ival_percentage,
203 _fval_percentage
204 );
205}
206
216 RTEMS_INLINE_ROUTINE time_t _Timestamp_Get_seconds(
217 const Timestamp_Control *_time
218)
219{
220 return (*_time >> 32);
221}
222
232 RTEMS_INLINE_ROUTINE uint32_t _Timestamp_Get_nanoseconds(
233 const Timestamp_Control *_time
234)
235{
236 struct timespec _ts;
237
238 _ts = sbttots( *_time );
239
240 return (uint32_t) _ts.tv_nsec;
241}
242
252 RTEMS_INLINE_ROUTINE uint64_t _Timestamp_Get_as_nanoseconds(
253 const Timestamp_Control *_time
254)
255{
256 struct timespec _ts;
257
258 _ts = sbttots( *_time );
259
260 return _Timespec_Get_as_nanoseconds( &_ts );
261}
262
269 RTEMS_INLINE_ROUTINE void _Timestamp_To_timespec(
270 const Timestamp_Control *_timestamp,
271 struct timespec *_timespec
272)
273{
274 *_timespec = sbttots( *_timestamp );
275}
276
283 RTEMS_INLINE_ROUTINE void _Timestamp_To_timeval(
284 const Timestamp_Control *_timestamp,
285 struct timeval *_timeval
286)
287{
288 *_timeval = sbttotv( *_timestamp );
289}
290
291#ifdef __cplusplus
292}
293#endif
294
297#endif
298/* end of include file */
basedefs.h
Basic Definitions.
RTEMS_INLINE_ROUTINE
#define RTEMS_INLINE_ROUTINE
Definition: basedefs.h:66
_Timestamp_Divide
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: timestampimpl.h:186
_Timestamp_Get_nanoseconds
RTEMS_INLINE_ROUTINE uint32_t _Timestamp_Get_nanoseconds(const Timestamp_Control *_time)
Gets nanoseconds portion of timestamp.
Definition: timestampimpl.h:232
_Timestamp_Equal_to
RTEMS_INLINE_ROUTINE bool _Timestamp_Equal_to(const Timestamp_Control *_lhs, const Timestamp_Control *_rhs)
Checks if the timestamps are equal.
Definition: timestampimpl.h:130
_Timestamp_Set
RTEMS_INLINE_ROUTINE void _Timestamp_Set(Timestamp_Control *_time, time_t _seconds, long _nanoseconds)
Sets timestamp to specified seconds and nanoseconds.
Definition: timestampimpl.h:48
_Timestamp_Get_as_nanoseconds
RTEMS_INLINE_ROUTINE uint64_t _Timestamp_Get_as_nanoseconds(const Timestamp_Control *_time)
Gets the timestamp as nanoseconds.
Definition: timestampimpl.h:252
_Timestamp_Greater_than
RTEMS_INLINE_ROUTINE bool _Timestamp_Greater_than(const Timestamp_Control *_lhs, const Timestamp_Control *_rhs)
Checks if the left hand side timestamp is greater than the right one.
Definition: timestampimpl.h:110
_Timestamp_Set_to_zero
RTEMS_INLINE_ROUTINE void _Timestamp_Set_to_zero(Timestamp_Control *_time)
Sets the timestamp to zero.
Definition: timestampimpl.h:71
_Timestamp_To_timespec
RTEMS_INLINE_ROUTINE void _Timestamp_To_timespec(const Timestamp_Control *_timestamp, struct timespec *_timespec)
Converts timestamp to struct timespec.
Definition: timestampimpl.h:269
Timestamp_Control
int64_t Timestamp_Control
Definition: timestamp.h:57
_Timestamp_Add_to
RTEMS_INLINE_ROUTINE void _Timestamp_Add_to(Timestamp_Control *_time, const Timestamp_Control *_add)
Adds two timestamps.
Definition: timestampimpl.h:147
_Timestamp_Less_than
RTEMS_INLINE_ROUTINE bool _Timestamp_Less_than(const Timestamp_Control *_lhs, const Timestamp_Control *_rhs)
Checks if the left hand side timestamp is less than the right one.
Definition: timestampimpl.h:90
_Timestamp_Get_seconds
RTEMS_INLINE_ROUTINE time_t _Timestamp_Get_seconds(const Timestamp_Control *_time)
Gets seconds portion of timestamp.
Definition: timestampimpl.h:216
_Timestamp_To_timeval
RTEMS_INLINE_ROUTINE void _Timestamp_To_timeval(const Timestamp_Control *_timestamp, struct timeval *_timeval)
Converts timestamp to struct timeval.
Definition: timestampimpl.h:283
_Timestamp_Subtract
RTEMS_INLINE_ROUTINE void _Timestamp_Subtract(const Timestamp_Control *_start, const Timestamp_Control *_end, Timestamp_Control *_result)
Subtracts two timestamps.
Definition: timestampimpl.h:166
_Timespec_Divide
void _Timespec_Divide(const struct timespec *lhs, const struct timespec *rhs, uint32_t *ival_percentage, uint32_t *fval_percentage)
Divides a timespec by another timespec.
Definition: timespecdivide.c:25
_Timespec_Get_as_nanoseconds
uint64_t _Timespec_Get_as_nanoseconds(const struct timespec *time)
Gets the timestamp as nanoseconds.
Definition: timespecgetasnanoseconds.c:23
_start
void _start(void)
System start entry.
timestamp.h
Helpers for Manipulating Timestamps.