source: rtems/cpukit/include/rtems/score/timestampimpl.h @ ef23838

5
Last change on this file since ef23838 was ef23838, checked in by Sebastian Huber <sebastian.huber@…>, on 12/03/18 at 12:10:21

score: Avoid sbintime_t in API headers

The sbintime_t is a non-POSIX type and not visible if strict standard
options are selected.

Move implementation details from <rtems/score/timestamp.h> to
<rtems/score/timestampimpl.h>.

Update #3598.

  • Property mode set to 100644
File size: 6.8 KB
Line 
1/**
2 *  @file  rtems/score/timestamp.h
3 *
4 *  @brief Helpers for Manipulating Timestamps
5 *
6 *  This include file contains helpers for manipulating timestamps.
7 */
8
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_TIMESTAMPIMPL_H
19#define _RTEMS_SCORE_TIMESTAMPIMPL_H
20
21/**
22 * @addtogroup SuperCoreTimeStamp
23 *
24 * @{
25 */
26
27#include <rtems/score/timestamp.h>
28#include <rtems/score/basedefs.h>
29
30#include <sys/time.h>
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36/**
37 *  @brief Set timestamp to specified seconds and nanoseconds.
38 *
39 *  This method sets the timestamp to the specified @a _seconds and @a _nanoseconds
40 *  value.
41 *
42 *  @param[in] _time points to the timestamp instance to validate.
43 *  @param[in] _seconds is the seconds portion of the timestamp
44 *  @param[in] _nanoseconds is the nanoseconds portion of the timestamp
45 */
46RTEMS_INLINE_ROUTINE void _Timestamp_Set(
47  Timestamp_Control *_time,
48  time_t             _seconds,
49  long               _nanoseconds
50)
51{
52  struct timespec _ts;
53
54  _ts.tv_sec = _seconds;
55  _ts.tv_nsec = _nanoseconds;
56
57  *_time = tstosbt(_ts);
58}
59
60/**
61 *  @brief Sets the timestamp to zero.
62 *
63 *  This method sets the timestamp to zero.
64 *  value.
65 *
66 *  @param[in] _time points to the timestamp instance to zero.
67 */
68
69RTEMS_INLINE_ROUTINE void _Timestamp_Set_to_zero(
70  Timestamp_Control *_time
71)
72{
73  *_time = 0;
74}
75
76/**
77 *  @brief Less than operator for timestamps.
78 *
79 *  This method is the less than operator for timestamps.
80 *
81 *  @param[in] _lhs points to the left hand side timestamp
82 *  @param[in] _rhs points to the right hand side timestamp
83 *
84 *  @retval This method returns true if @a _lhs is less than the @a _rhs and
85 *          false otherwise.
86 */
87
88RTEMS_INLINE_ROUTINE bool _Timestamp_Less_than(
89  const Timestamp_Control *_lhs,
90  const Timestamp_Control *_rhs
91)
92{
93  return *_lhs < *_rhs;
94}
95
96/**
97 *  @brief Greater than operator for timestamps.
98 *
99 *  This method is the greater than operator for timestamps.
100 *
101 *  @param[in] _lhs points to the left hand side timestamp
102 *  @param[in] _rhs points to the right hand side timestamp
103 *
104 *  @retval This method returns true if @a _lhs is greater than the @a _rhs and
105 *          false otherwise.
106 */
107
108RTEMS_INLINE_ROUTINE bool _Timestamp_Greater_than(
109  const Timestamp_Control *_lhs,
110  const Timestamp_Control *_rhs
111)
112{
113  return *_lhs > *_rhs;
114}
115
116/**
117 *  @brief Equal to than operator for timestamps.
118 *
119 *  This method is the is equal to than operator for timestamps.
120 *
121 *  @param[in] _lhs points to the left hand side timestamp
122 *  @param[in] _rhs points to the right hand side timestamp
123 *
124 *  @retval This method returns true if @a _lhs is equal to  @a _rhs and
125 *          false otherwise.
126 */
127
128RTEMS_INLINE_ROUTINE bool _Timestamp_Equal_to(
129  const Timestamp_Control *_lhs,
130  const Timestamp_Control *_rhs
131)
132{
133  return *_lhs == *_rhs;
134}
135
136/**
137 *  @brief Adds two timestamps.
138 *
139 *  This routine adds two timestamps.  The second argument is added
140 *  to the first.
141 *
142 *  @param[in] _time points to the base time to be added to
143 *  @param[in] _add points to the timestamp to add to the first argument
144 */
145RTEMS_INLINE_ROUTINE void _Timestamp_Add_to(
146  Timestamp_Control *_time,
147  const Timestamp_Control *_add
148)
149{
150  *_time += *_add;
151}
152
153/**
154 *  @brief Subtracts two timestamps.
155 *
156 *  This routine subtracts two timestamps.  @a result is set to
157 *  @a end - @a start.
158 *
159 *  @param[in] _start points to the starting time
160 *  @param[in] _end points to the ending time
161 *  @param[in] _result points to the difference between
162 *             starting and ending time.
163 *
164 *  @retval This method fills in @a _result.
165 */
166RTEMS_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
175/**
176 *  @brief Divides a timestamp by another timestamp.
177 *
178 *  This routine divides a timestamp by another timestamp.  The
179 *  intended use is for calculating percentages to three decimal points.
180 *
181 *  @param[in] _lhs points to the left hand number
182 *  @param[in] _rhs points to the right hand number
183 *  @param[in] _ival_percentage points to the integer portion of the average
184 *  @param[in] _fval_percentage points to the thousandths of percentage
185 *
186 *  @retval This method fills in @a result.
187 */
188RTEMS_INLINE_ROUTINE void _Timestamp_Divide(
189  const Timestamp_Control *_lhs,
190  const Timestamp_Control *_rhs,
191  uint32_t                *_ival_percentage,
192  uint32_t                *_fval_percentage
193)
194{
195  struct timespec _ts_left;
196  struct timespec _ts_right;
197
198  _ts_left = sbttots( *_lhs );
199  _ts_right = sbttots( *_rhs );
200
201  _Timespec_Divide(
202    &_ts_left,
203    &_ts_right,
204    _ival_percentage,
205    _fval_percentage
206  );
207}
208
209/**
210 *  @brief Get seconds portion of timestamp.
211 *
212 *  This method returns the seconds portion of the specified timestamp
213 *
214 *  @param[in] _time points to the timestamp
215 *
216 *  @retval The seconds portion of @a _time.
217 */
218RTEMS_INLINE_ROUTINE time_t _Timestamp_Get_seconds(
219  const Timestamp_Control *_time
220)
221{
222  return (*_time >> 32);
223}
224
225/**
226 *  @brief Get nanoseconds portion of timestamp.
227 *
228 *  This method returns the nanoseconds portion of the specified timestamp
229 *
230 *  @param[in] _time points to the timestamp
231 *
232 *  @retval The nanoseconds portion of @a _time.
233 */
234RTEMS_INLINE_ROUTINE uint32_t _Timestamp_Get_nanoseconds(
235  const Timestamp_Control *_time
236)
237{
238  struct timespec _ts;
239
240  _ts = sbttots( *_time );
241
242  return (uint32_t) _ts.tv_nsec;
243}
244
245/**
246 *  @brief Get the timestamp as nanoseconds.
247 *
248 *  This method returns the timestamp as nanoseconds.
249 *
250 *  @param[in] _time points to the timestamp
251 *
252 *  @retval The time in nanoseconds.
253 */
254RTEMS_INLINE_ROUTINE uint64_t _Timestamp_Get_as_nanoseconds(
255  const Timestamp_Control *_time
256)
257{
258  struct timespec _ts;
259
260  _ts = sbttots( *_time );
261
262  return _Timespec_Get_as_nanoseconds( &_ts );
263}
264
265/**
266 *  @brief Convert timestamp to struct timespec.
267 *
268 *  This method returns the seconds portion of the specified @a _timestamp.
269 *
270 *  @param[in] _timestamp points to the timestamp
271 *  @param[in] _timespec points to the timespec
272 */
273RTEMS_INLINE_ROUTINE void _Timestamp_To_timespec(
274  const Timestamp_Control *_timestamp,
275  struct timespec         *_timespec
276)
277{
278  *_timespec = sbttots( *_timestamp );
279}
280
281/**
282 *  @brief Convert timestamp to struct timeval.
283 *
284 *  @param[in] _timestamp points to the timestamp
285 *  @param[in] _timeval points to the timeval
286 */
287RTEMS_INLINE_ROUTINE void _Timestamp_To_timeval(
288  const Timestamp_Control *_timestamp,
289  struct timeval          *_timeval
290)
291{
292  *_timeval = sbttotv( *_timestamp );
293}
294
295#ifdef __cplusplus
296}
297#endif
298
299/**@}*/
300
301#endif
302/* end of include file */
Note: See TracBrowser for help on using the repository browser.