source: rtems/cpukit/score/include/rtems/score/timestamp64.h @ 4b72da4

4.115
Last change on this file since 4b72da4 was 4b72da4, checked in by Joel Sherrill <joel.sherrill@…>, on 06/17/11 at 14:55:27

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

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