source: rtems/cpukit/score/include/rtems/score/timestamp64.h @ 3a42e6fd

4.115
Last change on this file since 3a42e6fd was 3a42e6fd, checked in by Sebastian Huber <sebastian.huber@…>, on 09/28/11 at 14:42:12

2011-09-28 Sebastian Huber <sebastian.huber@…>

PR 1914/cpukit

  • score/src/timespecgreaterthan.c, score/src/ts64greaterthan.c: Removed files.
  • score/Makefile.am: Reflect changes above.
  • score/include/rtems/score/timespec.h, score/include/rtems/score/timestamp.h, score/include/rtems/score/timestamp64.h, score/src/ts64addto.c, score/src/ts64divide.c, score/src/ts64dividebyinteger.c, score/src/ts64equalto.c, score/src/ts64getnanoseconds.c, score/src/ts64getseconds.c, score/src/ts64lessthan.c, score/src/ts64set.c, score/src/ts64settozero.c, score/src/ts64subtract.c, score/src/ts64toticks.c, score/src/ts64totimespec.c: Use CPU_TIMESTAMP_USE_STRUCT_TIMESPEC, CPU_TIMESTAMP_USE_INT64, and CPU_TIMESTAMP_USE_INT64_INLINE. Removed copy and paste.
  • Property mode set to 100644
File size: 11.4 KB
Line 
1/**
2 *  @file  rtems/score/timestamp64.h
3 *
4 *  This include file contains helpers for manipulating
5 *  64-bit integer timestamps.
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2009.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.com/license/LICENSE.
15 *
16 *  $Id$
17 */
18
19#ifndef _RTEMS_SCORE_TIMESTAMP64_H
20#define _RTEMS_SCORE_TIMESTAMP64_H
21
22/**
23 *  @defgroup SuperCore Timestamp64
24 *
25 *  @ingroup Score
26 *
27 *  This handler encapsulates functionality related to manipulating
28 *  the 64 bit integer implementation of SuperCore Timestamps.
29 */
30/**@{*/
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36/*
37 *  This .h file is not for general use.  It is an alternative
38 *  implementation of Timestamps and should only be used that way.
39 */
40#ifndef _RTEMS_SCORE_TIMESTAMP_H
41  #error "Should only be included by rtems/score/timestamp.h"
42#endif
43
44/*
45 *  Verify something is defined.
46 */
47#if CPU_TIMESTAMP_USE_INT64 != TRUE && CPU_TIMESTAMP_USE_INT64_INLINE != TRUE
48  #error "SuperCore Timestamp64 implementation included but not defined."
49#endif
50
51/**
52 *   Define the Timestamp control type.
53 */
54typedef int64_t Timestamp64_Control;
55
56static inline void _Timestamp64_implementation_Set(
57  Timestamp64_Control *_time,
58  long                 _seconds,
59  long                 _nanoseconds
60)
61{
62  Timestamp64_Control _seconds64 = _seconds;
63  Timestamp64_Control _nanoseconds64 = _nanoseconds;
64
65  *_time = _seconds64 * 1000000000L + _nanoseconds64;
66}
67
68/**
69 *  @brief Set Timestamp to Seconds Nanosecond
70 *
71 *  This method sets the timestamp to the specified seconds and nanoseconds
72 *  value.
73 *
74 *  @param[in] _time points to the timestamp instance to validate.
75 *  @param[in] _seconds is the seconds portion of the timestamp
76 *  @param[in] _nanoseconds is the nanoseconds portion of the timestamp
77 */
78#if CPU_TIMESTAMP_USE_INT64_INLINE == TRUE
79  #define _Timestamp64_Set( _time, _seconds, _nanoseconds ) \
80    _Timestamp64_implementation_Set( _time, _seconds, _nanoseconds )
81#else
82  void _Timestamp64_Set(
83    Timestamp64_Control *_time,
84    long                _seconds,
85    long                _nanoseconds
86  );
87#endif
88
89static inline void _Timestamp64_implementation_Set_to_zero(
90  Timestamp64_Control *_time
91)
92{
93  *_time = 0;
94}
95
96/**
97 *  @brief Zero Timestamp
98 *
99 *  This method sets the timestamp to zero.
100 *  value.
101 *
102 *  @param[in] _time points to the timestamp instance to zero.
103 */
104#if CPU_TIMESTAMP_USE_INT64_INLINE == TRUE
105  #define _Timestamp64_Set_to_zero( _time ) \
106    _Timestamp64_implementation_Set_to_zero( _time )
107#else
108  void _Timestamp64_Set_to_zero(
109    Timestamp64_Control *_time
110  );
111#endif
112
113/**
114 *  @brief Is Timestamp Valid
115 *
116 *  This method determines the validity of a timestamp.
117 *
118 *  @param[in] _time points to the timestamp instance to validate.
119 *
120 *  @return This method returns true if @a time is valid and
121 *          false otherwise.
122 */
123#define _Timestamp64_Is_valid( _time ) \
124  (1)
125
126static inline bool _Timestamp64_implementation_Less_than(
127  const Timestamp64_Control *_lhs,
128  const Timestamp64_Control *_rhs
129)
130{
131  return *_lhs < *_rhs;
132}
133
134/**
135 *  @brief Timestamp Less Than Operator
136 *
137 *  This method is the less than operator for timestamps.
138 *
139 *  @param[in] _lhs points to the left hand side timestamp
140 *  @param[in] _rhs points to the right hand side timestamp
141 *
142 *  @return This method returns true if @a _lhs is less than the @a _rhs and
143 *          false otherwise.
144 */
145#if CPU_TIMESTAMP_USE_INT64_INLINE == TRUE
146  #define _Timestamp64_Less_than( _lhs, _rhs ) \
147    _Timestamp64_implementation_Less_than( _lhs, _rhs )
148#else
149  bool _Timestamp64_Less_than(
150    const Timestamp64_Control *_lhs,
151    const Timestamp64_Control *_rhs
152  );
153#endif
154
155static inline bool _Timestamp64_implementation_Equal_to(
156  const Timestamp64_Control *_lhs,
157  const Timestamp64_Control *_rhs
158)
159{
160  return *_lhs == *_rhs;
161}
162
163#define _Timestamp64_Greater_than( _lhs, _rhs ) \
164  _Timestamp64_Less_than( _rhs, _lhs )
165
166/**
167 *  @brief Timestamp equal to Operator
168 *
169 *  This method is the is equal to than operator for timestamps.
170 *
171 *  @param[in] _lhs points to the left hand side timestamp
172 *  @param[in] _rhs points to the right hand side timestamp
173 *
174 *  @return This method returns true if @a _lhs is equal to  @a _rhs and
175 *          false otherwise.
176 */
177#if CPU_TIMESTAMP_USE_INT64_INLINE == TRUE
178  #define _Timestamp64_Equal_to( _lhs, _rhs ) \
179    _Timestamp64_implementation_Equal_to( _lhs, _rhs )
180#else
181  bool _Timestamp64_Equal_to(
182    const Timestamp64_Control *_lhs,
183    const Timestamp64_Control *_rhs
184  );
185#endif
186
187static inline void _Timestamp64_implementation_Add_to(
188  Timestamp64_Control       *_time,
189  const Timestamp64_Control *_add
190)
191{
192  *_time += *_add;
193}
194
195/**
196 *  @brief Add to a Timestamp
197 *
198 *  This routine adds two timestamps.  The second argument is added
199 *  to the first.
200 *
201 *  @param[in] _time points to the base time to be added to
202 *  @param[in] _add points to the timestamp to add to the first argument
203 *
204 *  @return This method returns the number of seconds @a time increased by.
205 */
206#if CPU_TIMESTAMP_USE_INT64_INLINE == TRUE
207  #define _Timestamp64_Add_to( _time, _add ) \
208    _Timestamp64_implementation_Add_to( _time, _add )
209#else
210  void _Timestamp64_Add_to(
211    Timestamp64_Control       *_time,
212    const Timestamp64_Control *_add
213  );
214#endif
215
216/**
217 *  @brief Add to a Timestamp (At Clock Tick)
218 *
219 *  This routine adds two timestamps.  The second argument is added
220 *  to the first.
221 *
222 *  @node This routine places a special requirement on the addition
223 *        operation.  It must return the number of units that the
224 *        seconds field changed as the result of the addition.  Since this
225 *        operation is ONLY used as part of processing a clock tick,
226 *        it is generally safe to assume that only one second changed.
227 *
228 *  @param[in] _time points to the base time to be added to
229 *  @param[in] _add points to the timestamp to add to the first argument
230 *
231 *  @return This method returns the number of seconds @a time increased by.
232 */
233static inline uint32_t _Timestamp64_Add_to_at_tick(
234  Timestamp64_Control *_time,
235  const Timestamp64_Control *_add
236)
237{
238  Timestamp64_Control _start = *_time / 1000000000L;
239  *_time += *_add;
240  if ( ((*_time) / 1000000000L) != _start ) {
241    return 1;
242  }
243  return 0;
244}
245
246/**
247 *  @brief Convert Timestamp to Number of Ticks
248 *
249 *  This routine convert the @a time timestamp to the corresponding number
250 *  of clock ticks.
251 *
252 *  @param[in] _time points to the time to be converted
253 *
254 *  @return This method returns the number of ticks computed.
255 */
256uint32_t _Timestamp64_To_ticks(
257  const Timestamp64_Control *_time
258);
259
260/**
261 *  @brief Convert Ticks to Timestamp
262 *
263 *  This routine converts the @a _ticks value to the corresponding
264 *  timestamp format @a _time.
265 *
266 *  @param[in] _time points to the timestamp format time result
267 *  @param[out] _ticks points to the number of ticks to be filled in
268 */
269void _Timestamp64_From_ticks(
270  uint32_t             _ticks,
271  Timestamp64_Control *_time
272);
273
274static inline void _Timestamp64_implementation_Subtract(
275  const Timestamp64_Control *_start,
276  const Timestamp64_Control *_end,
277  Timestamp64_Control       *_result
278)
279{
280  *_result = *_end - *_start;
281}
282
283/**
284 *  @brief Subtract Two Timestamp
285 *
286 *  This routine subtracts two timestamps.  @a result is set to
287 *  @a end - @a start.
288 *
289 *  @param[in] _start points to the starting time
290 *  @param[in] _end points to the ending time
291 *  @param[out] _result points to the difference between
292 *             starting and ending time.
293 */
294#if CPU_TIMESTAMP_USE_INT64_INLINE == TRUE
295  #define _Timestamp64_Subtract( _start, _end, _result ) \
296    _Timestamp64_implementation_Subtract( _start, _end, _result )
297#else
298  void _Timestamp64_Subtract(
299    const Timestamp64_Control *_start,
300    const Timestamp64_Control *_end,
301    Timestamp64_Control       *_result
302  );
303#endif
304
305static inline void _Timestamp64_implementation_Divide_by_integer(
306  const Timestamp64_Control *_time,
307  uint32_t             _iterations,
308  Timestamp64_Control *_result
309)
310{
311  *_result = *_time / _iterations;
312}
313
314/**
315 *  @brief Divide Timestamp By Integer
316 *
317 *  This routine divides a timestamp by an integer value.  The expected
318 *  use is to assist in benchmark calculations where you typically
319 *  divide a duration by a number of iterations.
320 *
321 *  @param[in] _time points to the total
322 *  @param[in] _iterations is the number of iterations
323 *  @param[out] _result points to the average time.
324 */
325#if CPU_TIMESTAMP_USE_INT64_INLINE == TRUE
326  #define _Timestamp64_Divide_by_integer( _time, _iterations, _result ) \
327    _Timestamp64_implementation_Divide_by_integer( _time, _iterations, _result )
328#else
329  void _Timestamp64_Divide_by_integer(
330    const Timestamp64_Control *_time,
331    uint32_t                   _iterations,
332    Timestamp64_Control       *_result
333  );
334#endif
335
336/**
337 *  @brief Divide Timestamp
338 *
339 *  This routine divides a timestamp by another timestamp.  The
340 *  intended use is for calculating percentages to three decimal points.
341 *
342 *  @param[in] _lhs points to the left hand number
343 *  @param[in] _rhs points to the right hand number
344 *  @param[out] _ival_percentage points to the integer portion of the average
345 *  @param[out] _fval_percentage points to the thousandths of percentage
346 */
347void _Timestamp64_Divide(
348  const Timestamp64_Control *_lhs,
349  const Timestamp64_Control *_rhs,
350  uint32_t                  *_ival_percentage,
351  uint32_t                  *_fval_percentage
352);
353
354static inline uint32_t _Timestamp64_implementation_Get_seconds(
355  const Timestamp64_Control *_time
356)
357{
358  return (uint32_t) (*_time / 1000000000L);
359}
360
361/**
362 *  @brief Get Seconds Portion of Timestamp
363 *
364 *  This method returns the seconds portion of the specified timestamp
365 *
366 *  @param[in] _time points to the timestamp
367 *
368 *  @return The seconds portion of @a _time.
369 */
370#if CPU_TIMESTAMP_USE_INT64_INLINE == TRUE
371  #define _Timestamp64_Get_seconds( _time ) \
372    _Timestamp64_implementation_Get_seconds( _time )
373#else
374  uint32_t _Timestamp64_Get_seconds(
375    const Timestamp64_Control *_time
376  );
377#endif
378
379static inline uint32_t _Timestamp64_implementation_Get_nanoseconds(
380  const Timestamp64_Control *_time
381)
382{
383  return (uint32_t) (*_time % 1000000000L);
384}
385
386/**
387 *  @brief Get Nanoseconds Portion of Timestamp
388 *
389 *  This method returns the nanoseconds portion of the specified timestamp
390 *
391 *  @param[in] _time points to the timestamp
392 *
393 *  @return The nanoseconds portion of @a _time.
394 */
395#if CPU_TIMESTAMP_USE_INT64_INLINE == TRUE
396  #define _Timestamp64_Get_nanoseconds( _time ) \
397    _Timestamp64_implementation_Get_nanoseconds( _time )
398#else
399  uint32_t _Timestamp64_Get_nanoseconds(
400    const Timestamp64_Control *_time
401  );
402#endif
403
404static inline void _Timestamp64_implementation_To_timespec(
405  const Timestamp64_Control *_timestamp,
406  struct timespec           *_timespec
407)
408{
409  _timespec->tv_sec = *_timestamp / 1000000000L;
410  _timespec->tv_nsec = *_timestamp % 1000000000L;
411}
412
413/**
414 *  @brief Convert Timestamp to struct timespec
415 *
416 *  This method returns the seconds portion of the specified timestamp
417 *
418 *  @param[in] _timestamp points to the timestamp
419 *  @param[out] _timespec points to the timespec
420 */
421#if CPU_TIMESTAMP_USE_INT64_INLINE == TRUE
422  #define _Timestamp64_To_timespec( _timestamp, _timespec  ) \
423    _Timestamp64_implementation_To_timespec( _timestamp, _timespec )
424#else
425  void _Timestamp64_To_timespec(
426    const Timestamp64_Control *_timestamp,
427    struct timespec           *_timespec
428  );
429#endif
430
431#ifdef __cplusplus
432}
433#endif
434
435/**@}*/
436
437#endif
438/* end of include file */
Note: See TracBrowser for help on using the repository browser.