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