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

4.115
Last change on this file since 3e1ed22 was d8cd045c, checked in by Joel Sherrill <joel.sherrill@…>, on 06/17/11 at 15:40:09

2011-06-17 Joel Sherrill <joel.sherrill@…>

  • rtems/include/rtems/rtems/types.h, score/include/rtems/score/address.h, score/include/rtems/score/apiext.h, score/include/rtems/score/bitfield.h, score/include/rtems/score/context.h, score/include/rtems/score/corebarrier.h, score/include/rtems/score/coremsg.h, score/include/rtems/score/coremutex.h, score/include/rtems/score/corerwlock.h, score/include/rtems/score/coresem.h, score/include/rtems/score/corespinlock.h, score/include/rtems/score/interr.h, score/include/rtems/score/isr.h, score/include/rtems/score/mpci.h, score/include/rtems/score/mppkt.h, score/include/rtems/score/objectmp.h, score/include/rtems/score/percpu.h, score/include/rtems/score/priority.h, score/include/rtems/score/rbtree.h, score/include/rtems/score/scheduler.h, score/include/rtems/score/smp.h, score/include/rtems/score/smplock.h, score/include/rtems/score/stack.h, score/include/rtems/score/states.h, score/include/rtems/score/thread.h, score/include/rtems/score/threadq.h, score/include/rtems/score/threadsync.h, score/include/rtems/score/timespec.h, score/include/rtems/score/timestamp.h, score/include/rtems/score/timestamp64.h, score/include/rtems/score/tod.h, score/include/rtems/score/tqdata.h, score/include/rtems/score/watchdog.h, score/include/rtems/score/wkspace.h: Mark Score files as in Score Group to improve Doxygen output.
  • Property mode set to 100644
File size: 10.1 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 !defined(CPU_RTEMS_SCORE_TIMESTAMP_IS_INT64)
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
56/**
57 *  @brief Set Timestamp to Seconds Nanosecond
58 *
59 *  This method sets the timestamp to the specified seconds and nanoseconds
60 *  value.
61 *
62 *  @param[in] _time points to the timestamp instance to validate.
63 *  @param[in] _seconds is the seconds portion of the timestamp
64 *  @param[in] _nanoseconds is the nanoseconds portion of the timestamp
65 */
66#if defined(CPU_RTEMS_SCORE_TIMESTAMP_INT64_INLINE)
67  #define _Timestamp64_Set( _time, _seconds, _nanoseconds ) \
68          do { \
69            *(_time) = ((int64_t)_seconds * 1000000000); \
70            *(_time) += (int64_t)(_nanoseconds); \
71          } while (0)
72#else
73  void _Timestamp64_Set(
74    Timestamp64_Control *_time,
75    long                _seconds,
76    long                _nanoseconds
77  );
78#endif
79
80/**
81 *  @brief Zero Timestamp
82 *
83 *  This method sets the timestamp to zero.
84 *  value.
85 *
86 *  @param[in] _time points to the timestamp instance to zero.
87 */
88#if defined(CPU_RTEMS_SCORE_TIMESTAMP_INT64_INLINE)
89  #define _Timestamp64_Set_to_zero( _time ) \
90          *(_time) = 0
91#else
92  void _Timestamp64_Set_to_zero(
93    Timestamp64_Control *_time
94  );
95#endif
96
97/**
98 *  @brief Is Timestamp Valid
99 *
100 *  This method determines the validity of a timestamp.
101 *
102 *  @param[in] _time points to the timestamp instance to validate.
103 *
104 *  @return This method returns true if @a time is valid and
105 *          false otherwise.
106 */
107#define _Timestamp64_Is_valid( _time ) \
108        (1)
109
110/**
111 *  @brief Timestamp Less Than Operator
112 *
113 *  This method is the less than operator for timestamps.
114 *
115 *  @param[in] _lhs points to the left hand side timestamp
116 *  @param[in] _rhs points to the right hand side timestamp
117 *
118 *  @return This method returns true if @a _lhs is less than the @a _rhs and
119 *          false otherwise.
120 */
121#if defined(CPU_RTEMS_SCORE_TIMESTAMP_INT64_INLINE)
122  #define _Timestamp64_Less_than( _lhs, _rhs ) \
123          (*(_lhs) < *(_rhs))
124#else
125  bool _Timestamp64_Less_than(
126    Timestamp64_Control *_lhs,
127    Timestamp64_Control *_rhs
128  );
129#endif
130
131/**
132 *  @brief Timestamp Greater Than Operator
133 *
134 *  This method is the greater than operator for timestamps.
135 *
136 *  @param[in] _lhs points to the left hand side timestamp
137 *  @param[in] _rhs points to the right hand side timestamp
138 *
139 *  @return This method returns true if @a _lhs is greater than the @a _rhs and
140 *          false otherwise.
141 */
142#if defined(CPU_RTEMS_SCORE_TIMESTAMP_INT64_INLINE)
143  #define _Timestamp64_Greater_than( _lhs, _rhs ) \
144          (*(_lhs) > *(_rhs))
145#else
146  bool _Timestamp64_Greater_than(
147    Timestamp64_Control *_lhs,
148    Timestamp64_Control *_rhs
149  );
150#endif
151
152/**
153 *  @brief Timestamp equal to Operator
154 *
155 *  This method is the is equal to than operator for timestamps.
156 *
157 *  @param[in] _lhs points to the left hand side timestamp
158 *  @param[in] _rhs points to the right hand side timestamp
159 *
160 *  @return This method returns true if @a _lhs is equal to  @a _rhs and
161 *          false otherwise.
162 */
163#if defined(CPU_RTEMS_SCORE_TIMESTAMP_INT64_INLINE)
164  #define _Timestamp64_Equal_to( _lhs, _rhs ) \
165          (*(_lhs) == *(_rhs))
166#else
167  bool _Timestamp64_Equal_to(
168    Timestamp64_Control *_lhs,
169    Timestamp64_Control *_rhs
170  );
171#endif
172
173/**
174 *  @brief Add to a Timestamp
175 *
176 *  This routine adds two timestamps.  The second argument is added
177 *  to the first.
178 *
179 *  @param[in] _time points to the base time to be added to
180 *  @param[in] _add points to the timestamp to add to the first argument
181 *
182 *  @return This method returns the number of seconds @a time increased by.
183 */
184#if defined(CPU_RTEMS_SCORE_TIMESTAMP_INT64_INLINE)
185  #define _Timestamp64_Add_to( _time, _add ) \
186          *(_time) += *(_add)
187#else
188  void _Timestamp64_Add_to(
189    Timestamp64_Control *_time,
190    Timestamp64_Control *_add
191  );
192#endif
193
194/**
195 *  @brief Add to a Timestamp (At Clock Tick)
196 *
197 *  This routine adds two timestamps.  The second argument is added
198 *  to the first.
199 *
200 *  @node This routine places a special requirement on the addition
201 *        operation.  It must return the number of units that the
202 *        seconds field changed as the result of the addition.  Since this
203 *        operation is ONLY used as part of processing a clock tick,
204 *        it is generally safe to assume that only one second changed.
205 *
206 *  @param[in] _time points to the base time to be added to
207 *  @param[in] _add points to the timestamp to add to the first argument
208 *
209 *  @return This method returns the number of seconds @a time increased by.
210 */
211static inline uint32_t _Timestamp64_Add_to_at_tick(
212  Timestamp64_Control *_time,
213  Timestamp64_Control *_add
214)
215{
216  Timestamp64_Control start = *_time / 1000000000;
217  *_time += *_add;
218  if ( ((*_time) / 1000000000) != start ) {
219    return 1;
220  }
221  return 0;
222}
223
224/**
225 *  @brief Convert Timestamp to Number of Ticks
226 *
227 *  This routine convert the @a time timestamp to the corresponding number
228 *  of clock ticks.
229 *
230 *  @param[in] _time points to the time to be converted
231 *
232 *  @return This method returns the number of ticks computed.
233 */
234uint32_t _Timestamp64_To_ticks(
235  const Timestamp64_Control *_time
236);
237
238/**
239 *  @brief Convert Ticks to Timestamp
240 *
241 *  This routine converts the @a _ticks value to the corresponding
242 *  timestamp format @a _time.
243 *
244 *  @param[in] _time points to the timestamp format time result
245 *  @param[in] _ticks points to the number of ticks to be filled in
246 */
247void _Timestamp64_From_ticks(
248  uint32_t             _ticks,
249  Timestamp64_Control *_time
250);
251
252/**
253 *  @brief Subtract Two Timestamp
254 *
255 *  This routine subtracts two timestamps.  @a result is set to
256 *  @a end - @a start.
257 *
258 *  @param[in] _start points to the starting time
259 *  @param[in] _end points to the ending time
260 *  @param[in] _result points to the difference between
261 *             starting and ending time.
262 *
263 *  @return This method fills in @a _result.
264 */
265#if defined(CPU_RTEMS_SCORE_TIMESTAMP_INT64_INLINE)
266  #define _Timestamp64_Subtract( _start, _end, _result ) \
267          do { \
268             *(_result) = *(_end) - *(_start); \
269          } while (0)
270#else
271  void _Timestamp64_Subtract(
272    Timestamp64_Control *_start,
273    Timestamp64_Control *_end,
274    Timestamp64_Control *_result
275  );
276#endif
277
278/**
279 *  @brief Divide Timestamp By Integer
280 *
281 *  This routine divides a timestamp by an integer value.  The expected
282 *  use is to assist in benchmark calculations where you typically
283 *  divide a duration by a number of iterations.
284 *
285 *  @param[in] _time points to the total
286 *  @param[in] _iterations is the number of iterations
287 *  @param[in] _result points to the average time.
288 *
289 *  @return This method fills in @a result.
290 */
291#if defined(CPU_RTEMS_SCORE_TIMESTAMP_INT64_INLINE)
292  #define _Timestamp64_Divide_by_integer( _time, _iterations, _result ) \
293          do { \
294             *(_result) = *(_time) / (_iterations); \
295          } while (0)
296#else
297  void _Timestamp64_Divide_by_integer(
298    Timestamp64_Control *_time,
299    uint32_t             _iterations,
300    Timestamp64_Control *_result
301  );
302#endif
303
304/**
305 *  @brief Divide Timestamp
306 *
307 *  This routine divides a timestamp by another timestamp.  The
308 *  intended use is for calculating percentages to three decimal points.
309 *
310 *  @param[in] _lhs points to the left hand number
311 *  @param[in] _rhs points to the right hand number
312 *  @param[in] _ival_percentage points to the integer portion of the average
313 *  @param[in] _fval_percentage points to the thousandths of percentage
314 *
315 *  @return This method fills in @a result.
316 */
317void _Timestamp64_Divide(
318  const Timestamp64_Control *_lhs,
319  const Timestamp64_Control *_rhs,
320  uint32_t                  *_ival_percentage,
321  uint32_t                  *_fval_percentage
322);
323
324/**
325 *  @brief Get Seconds Portion of Timestamp
326 *
327 *  This method returns the seconds portion of the specified timestamp
328 *
329 *  @param[in] _time points to the timestamp
330 *
331 *  @return The seconds portion of @a _time.
332 */
333#if defined(CPU_RTEMS_SCORE_TIMESTAMP_INT64_INLINE)
334  #define _Timestamp64_Get_seconds( _time ) \
335          (*(_time) / 1000000000)
336#else
337  uint32_t _Timestamp64_Get_seconds(
338    Timestamp64_Control *_time
339  );
340#endif
341
342/**
343 *  @brief Get Nanoseconds Portion of Timestamp
344 *
345 *  This method returns the nanoseconds portion of the specified timestamp
346 *
347 *  @param[in] _time points to the timestamp
348 *
349 *  @return The nanoseconds portion of @a _time.
350 */
351#if defined(CPU_RTEMS_SCORE_TIMESTAMP_INT64_INLINE)
352  #define _Timestamp64_Get_nanoseconds( _time ) \
353          (*(_time) % 1000000000)
354#else
355  uint32_t _Timestamp64_Get_nanoseconds(
356    Timestamp64_Control *_time
357  );
358#endif
359
360/**
361 *  @brief Convert Timestamp to struct timespec
362 *
363 *  This method returns the seconds portion of the specified timestamp
364 *
365 *  @param[in] _timestamp points to the timestamp
366 *  @param[in] _timespec points to the timespec
367 */
368#if defined(CPU_RTEMS_SCORE_TIMESTAMP_INT64_INLINE)
369  #define _Timestamp64_To_timespec( _timestamp, _timespec  ) \
370        do { \
371          (_timespec)->tv_sec = *(_timestamp) / 1000000000; \
372          (_timespec)->tv_nsec = *(_timestamp) % 1000000000; \
373        } while (0)
374#else
375  void _Timestamp64_To_timespec(
376    Timestamp64_Control *_timestamp,
377    struct timespec     *_timespec
378  );
379#endif
380
381#ifdef __cplusplus
382}
383#endif
384
385/**@}*/
386
387#endif
388/* end of include file */
Note: See TracBrowser for help on using the repository browser.