source: rtems/cpukit/score/include/rtems/score/timestamp.h @ 9b4422a2

4.115
Last change on this file since 9b4422a2 was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 15:09:24

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was removed.

  • Property mode set to 100644
File size: 11.5 KB
Line 
1/**
2 *  @file  rtems/score/timestamp.h
3 *
4 *  This include file contains helpers for manipulating timestamps.
5 */
6
7/*
8 *  COPYRIGHT (c) 1989-2009.
9 *  On-Line Applications Research Corporation (OAR).
10 *
11 *  The license and distribution terms for this file may be
12 *  found in the file LICENSE in this distribution or at
13 *  http://www.rtems.com/license/LICENSE.
14 */
15
16#ifndef _RTEMS_SCORE_TIMESTAMP_H
17#define _RTEMS_SCORE_TIMESTAMP_H
18
19/**
20 *  @defgroup SuperCore Timestamp
21 *
22 *  @ingroup Score
23 *
24 *  This handler encapsulates functionality related to manipulating
25 *  SuperCore Timestamps.  SuperCore Timestamps may be used to
26 *  represent time of day, uptime, or intervals.
27 *
28 *  The key attribute of the SuperCore Timestamp handler is that it
29 *  is a completely opaque handler.  There can be multiple implementations
30 *  of the required functionality and with a recompile, RTEMS can use
31 *  any implementation.  It is intended to be a simple wrapper.
32 *
33 *  This handler can be implemented as either struct timespec or
34 *  unsigned64 bit numbers.  The use of a wrapper class allows the
35 *  the implementation of timestamps to change on a per architecture
36 *  basis.  This is an important option as the performance of this
37 *  handler is critical.
38 */
39/**@{*/
40
41#include <rtems/score/cpu.h>
42#include <rtems/score/timespec.h>
43
44#ifdef __cplusplus
45extern "C" {
46#endif
47
48#if ! ( ( CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE \
49    && CPU_TIMESTAMP_USE_INT64 == FALSE \
50    && CPU_TIMESTAMP_USE_INT64_INLINE == FALSE ) \
51  || ( CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == FALSE \
52    && CPU_TIMESTAMP_USE_INT64 == TRUE \
53    && CPU_TIMESTAMP_USE_INT64_INLINE == FALSE ) \
54  || ( CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == FALSE \
55    && CPU_TIMESTAMP_USE_INT64 == FALSE \
56    && CPU_TIMESTAMP_USE_INT64_INLINE == TRUE ) )
57  #error "Invalid SuperCore Timestamp implementations selection."
58#endif
59
60#if CPU_TIMESTAMP_USE_INT64 == TRUE || CPU_TIMESTAMP_USE_INT64_INLINE == TRUE
61  #include <rtems/score/timestamp64.h>
62#endif
63
64/**
65 *   Define the Timestamp control type.
66 */
67#if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
68  typedef struct timespec Timestamp_Control;
69#else
70  typedef Timestamp64_Control Timestamp_Control;
71#endif
72
73/**
74 *  @brief Set Timestamp to Seconds Nanosecond
75 *
76 *  This method sets the timestamp to the specified seconds and nanoseconds
77 *  value.
78 *
79 *  @param[in] _time points to the timestamp instance to validate.
80 *  @param[in] _seconds is the seconds portion of the timestamp
81 *  @param[in] _nanoseconds is the nanoseconds portion of the timestamp
82 */
83#if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
84  #define _Timestamp_Set( _time, _seconds, _nanoseconds ) \
85          _Timespec_Set( _time, _seconds, _nanoseconds )
86#else
87  #define _Timestamp_Set( _time, _seconds, _nanoseconds ) \
88          _Timestamp64_Set( _time, _seconds, _nanoseconds )
89#endif
90
91/**
92 *  @brief Zero Timestamp
93 *
94 *  This method sets the timestamp to zero.
95 *  value.
96 *
97 *  @param[in] _time points to the timestamp instance to zero.
98 */
99#if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
100  #define _Timestamp_Set_to_zero( _time ) \
101          _Timespec_Set_to_zero( _time )
102#else
103  #define _Timestamp_Set_to_zero( _time ) \
104          _Timestamp64_Set_to_zero( _time )
105#endif
106
107/**
108 *  @brief Is Timestamp Valid
109 *
110 *  This method determines the validity of a timestamp.
111 *
112 *  @param[in] _time points to the timestamp instance to validate.
113 *
114 *  @return This method returns true if @a time is valid and
115 *          false otherwise.
116 */
117#if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
118  #define _Timestamp_Is_valid( _time ) \
119          _Timespec_Is_valid( _time )
120#else
121  #define _Timestamp_Is_valid( _time ) \
122          _Timestamp64_Is_valid( _time )
123#endif
124
125/**
126 *  @brief Timestamp Less Than Operator
127 *
128 *  This method is the less than operator for timestamps.
129 *
130 *  @param[in] _lhs points to the left hand side timestamp
131 *  @param[in] _rhs points to the right hand side timestamp
132 *
133 *  @return This method returns true if @a _lhs is less than the @a _rhs and
134 *          false otherwise.
135 */
136#if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
137  #define _Timestamp_Less_than( _lhs, _rhs ) \
138          _Timespec_Less_than( _lhs, _rhs )
139#else
140  #define _Timestamp_Less_than( _lhs, _rhs ) \
141          _Timestamp64_Less_than( _lhs, _rhs )
142#endif
143
144/**
145 *  @brief Timestamp Greater Than Operator
146 *
147 *  This method is the greater than operator for timestamps.
148 *
149 *  @param[in] _lhs points to the left hand side timestamp
150 *  @param[in] _rhs points to the right hand side timestamp
151 *
152 *  @return This method returns true if @a _lhs is greater than the @a _rhs and
153 *          false otherwise.
154 */
155#define _Timestamp_Greater_than( _lhs, _rhs ) \
156  _Timestamp_Less_than( _rhs, _lhs )
157
158/**
159 *  @brief Timestamp equal to Operator
160 *
161 *  This method is the is equal to than operator for timestamps.
162 *
163 *  @param[in] _lhs points to the left hand side timestamp
164 *  @param[in] _rhs points to the right hand side timestamp
165 *
166 *  @return This method returns true if @a _lhs is equal to  @a _rhs and
167 *          false otherwise.
168 */
169#if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
170  #define _Timestamp_Equal_to( _lhs, _rhs ) \
171          _Timespec_Equal_to( _lhs, _rhs )
172#else
173  #define _Timestamp_Equal_to( _lhs, _rhs ) \
174          _Timestamp64_Equal_to( _lhs, _rhs )
175#endif
176
177/**
178 *  @brief Add to a Timestamp
179 *
180 *  This routine adds two timestamps.  The second argument is added
181 *  to the first.
182 *
183 *  @param[in] _time points to the base time to be added to
184 *  @param[in] _add points to the timestamp to add to the first argument
185 *
186 *  @return This method returns the number of seconds @a time increased by.
187 */
188#if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
189  #define _Timestamp_Add_to( _time, _add ) \
190          _Timespec_Add_to( _time, _add )
191#else
192  #define _Timestamp_Add_to( _time, _add ) \
193          _Timestamp64_Add_to( _time, _add )
194#endif
195
196/**
197 *  @brief Add to a Timestamp (At Clock Tick)
198 *
199 *  This routine adds two timestamps.  The second argument is added
200 *  to the first.
201 *
202 *  @node This routine places a special requirement on the addition
203 *        operation.  It must return the number of units that the
204 *        seconds field changed as the result of the addition.  Since this
205 *        operation is ONLY used as part of processing a clock tick,
206 *        it is generally safe to assume that only one second changed.
207 *
208 *  @param[in] _time points to the base time to be added to
209 *  @param[in] _add points to the timestamp to add to the first argument
210 *
211 *  @return This method returns the number of seconds @a time increased by.
212 */
213#if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
214  #define _Timestamp_Add_to_at_tick( _time, _add ) \
215          _Timespec_Add_to( _time, _add )
216#else
217  #define _Timestamp_Add_to_at_tick( _time, _add ) \
218          _Timestamp64_Add_to_at_tick( _time, _add )
219#endif
220
221/**
222 *  @brief Convert Timestamp to Number of Ticks
223 *
224 *  This routine convert the @a time timestamp to the corresponding number
225 *  of clock ticks.
226 *
227 *  @param[in] _time points to the time to be converted
228 *
229 *  @return This method returns the number of ticks computed.
230 */
231#if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
232  #define _Timestamp_To_ticks( _time ) \
233          _Timespec_To_ticks( _time )
234#else
235  #define _Timestamp_To_ticks( _time ) \
236          _Timestamp64_To_ticks( _time )
237#endif
238
239/**
240 *  @brief Convert Ticks to Timestamp
241 *
242 *  This routine converts the @a _ticks value to the corresponding
243 *  timestamp format @a _time.
244 *
245 *  @param[in] _time points to the timestamp format time result
246 *  @param[in] _ticks points to the number of ticks to be filled in
247 */
248#if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
249  #define _Timestamp_From_ticks( _ticks, _time ) \
250          _Timespec_From_ticks( _ticks, _time )
251#else
252  #define _Timestamp_From_ticks( _ticks, _time ) \
253          _Timestamp64_From_ticks( _ticks, _time )
254#endif
255
256/**
257 *  @brief Subtract Two Timestamp
258 *
259 *  This routine subtracts two timestamps.  @a result is set to
260 *  @a end - @a start.
261 *
262 *  @param[in] _start points to the starting time
263 *  @param[in] _end points to the ending time
264 *  @param[in] _result points to the difference between
265 *             starting and ending time.
266 *
267 *  @return This method fills in @a _result.
268 */
269#if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
270  #define _Timestamp_Subtract( _start, _end, _result ) \
271          _Timespec_Subtract( _start, _end, _result )
272#else
273  #define _Timestamp_Subtract( _start, _end, _result ) \
274          _Timestamp64_Subtract( _start, _end, _result )
275#endif
276
277/**
278 *  @brief Divide Timestamp By Integer
279 *
280 *  This routine divides a timestamp by an integer value.  The expected
281 *  use is to assist in benchmark calculations where you typically
282 *  divide a duration by a number of iterations.
283 *
284 *  @param[in] _time points to the total
285 *  @param[in] _iterations is the number of iterations
286 *  @param[in] _result points to the average time.
287 *
288 *  @return This method fills in @a result.
289 */
290#if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
291  #define _Timestamp_Divide_by_integer( _time, _iterations, _result ) \
292          _Timespec_Divide_by_integer(_time, _iterations, _result )
293#else
294  #define _Timestamp_Divide_by_integer( _time, _iterations, _result ) \
295          _Timestamp64_Divide_by_integer( _time, _iterations, _result )
296#endif
297
298/**
299 *  @brief Divide Timestamp
300 *
301 *  This routine divides a timestamp by another timestamp.  The
302 *  intended use is for calculating percentages to three decimal points.
303 *
304 *  @param[in] _lhs points to the left hand number
305 *  @param[in] _rhs points to the right hand number
306 *  @param[in] _ival_percentage points to the integer portion of the average
307 *  @param[in] _fval_percentage points to the thousandths of percentage
308 *
309 *  @return This method fills in @a result.
310 */
311#if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
312  #define _Timestamp_Divide( _lhs, _rhs, _ival_percentage, _fval_percentage ) \
313          _Timespec_Divide( _lhs, _rhs, _ival_percentage, _fval_percentage )
314#else
315  #define _Timestamp_Divide( _lhs, _rhs, _ival_percentage, _fval_percentage ) \
316          _Timestamp64_Divide( _lhs, _rhs, _ival_percentage, _fval_percentage )
317#endif
318
319/**
320 *  @brief Get Seconds Portion of Timestamp
321 *
322 *  This method returns the seconds portion of the specified timestamp
323 *
324 *  @param[in] _time points to the timestamp
325 *
326 *  @return The seconds portion of @a _time.
327 */
328#if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
329  #define _Timestamp_Get_seconds( _time ) \
330          _Timespec_Get_seconds( _time )
331#else
332  #define _Timestamp_Get_seconds( _time ) \
333          _Timestamp64_Get_seconds( _time )
334#endif
335
336/**
337 *  @brief Get Nanoseconds Portion of Timestamp
338 *
339 *  This method returns the nanoseconds portion of the specified timestamp
340 *
341 *  @param[in] _time points to the timestamp
342 *
343 *  @return The nanoseconds portion of @a _time.
344 */
345#if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
346  #define _Timestamp_Get_nanoseconds( _time ) \
347          _Timespec_Get_nanoseconds( _time )
348#else
349  #define _Timestamp_Get_nanoseconds( _time ) \
350          _Timestamp64_Get_nanoseconds( _time )
351#endif
352
353/**
354 *  @brief Convert Timestamp to struct timespec
355 *
356 *  This method returns the seconds portion of the specified timestamp
357 *
358 *  @param[in] _timestamp points to the timestamp
359 *  @param[in] _timespec points to the timespec
360 */
361#if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
362  /* in this case we know they are the same type so use simple assignment */
363  #define _Timestamp_To_timespec( _timestamp, _timespec  ) \
364          *(_timespec) = *(_timestamp)
365#else
366  #define _Timestamp_To_timespec( _timestamp, _timespec  ) \
367          _Timestamp64_To_timespec( _timestamp, _timespec  )
368#endif
369
370#ifdef __cplusplus
371}
372#endif
373
374/**@}*/
375
376#endif
377/* end of include file */
Note: See TracBrowser for help on using the repository browser.