source: rtems/cpukit/score/include/rtems/score/timestamp.h @ c16bcc0

4.104.115
Last change on this file since c16bcc0 was c16bcc0, checked in by Joel Sherrill <joel.sherrill@…>, on 12/08/08 at 19:41:31

2008-12-08 Joel Sherrill <joel.sherrill@…>

  • libcsupport/src/times.c, libmisc/cpuuse/cpuusagereport.c, libmisc/cpuuse/cpuusagereset.c, posix/src/clockgettime.c, posix/src/pthread.c, posix/src/timersettime.c, rtems/include/rtems/rtems/ratemon.h, rtems/src/clockgetsecondssinceepoch.c, rtems/src/clockgetuptime.c, rtems/src/ratemongetstatus.c, rtems/src/ratemonperiod.c, rtems/src/ratemonreportstatistics.c, rtems/src/taskwakewhen.c, rtems/src/timerfirewhen.c, rtems/src/timerserver.c, rtems/src/timerserverfirewhen.c, score/Makefile.am, score/preinstall.am, score/include/rtems/score/thread.h, score/include/rtems/score/tod.h, score/src/coretod.c, score/src/coretodget.c, score/src/coretodgetuptime.c, score/src/coretodset.c, score/src/coretodtickle.c, score/src/threaddispatch.c, score/src/threadinitialize.c: Add SuperCore? handler Timestamp to provide an opaque class for the representation and manipulation of uptime, time of day, and the difference between two timestamps. By using SuperCore? Timestamp, it is clear which methods and APIs really have to be struct timespec and which can be in an optimized native format.
  • score/include/rtems/score/timestamp.h, score/src/coretodgetuptimetimespec.c: New files.
  • Property mode set to 100644
File size: 9.3 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-2008.
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 *  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#ifdef __cplusplus
42extern "C" {
43#endif
44
45#include <rtems/score/timespec.h>
46
47#define RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC
48
49/**
50 *   Define the Timestamp control type.
51 */
52#if defined(RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
53  typedef struct timespec Timestamp_Control;
54#else
55  #error "No Alternative implementations for SuperCore Timestamp."
56#endif
57
58/** @brief Set Timestamp to Seconds Nanosecond
59 *
60 *  This method sets the timestamp to the specified seconds and nanoseconds
61 *  value.
62 *
63 *  @param[in] _time points to the timestamp instance to validate.
64 *  @param[in] _seconds is the seconds portion of the timestamp
65 *  @param[in] _nanoseconds is the nanoseconds portion of the timestamp
66 */
67#if defined(RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
68  #define _Timestamp_Set( _time, _seconds, _nanoseconds ) \
69          do { \
70             (_time)->tv_sec = (_seconds); \
71             (_time)->tv_nsec = (_nanoseconds); \
72          } while (0)
73#endif
74
75/** @brief Zero Timestamp
76 *
77 *  This method sets the timestamp to zero.
78 *  value.
79 *
80 *  @param[in] _time points to the timestamp instance to zero.
81 */
82#if defined(RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
83  #define _Timestamp_Set_to_zero( _time ) \
84          do { \
85             (_time)->tv_sec = 0; \
86             (_time)->tv_nsec = 0; \
87          } while (0)
88#endif
89
90/** @brief Is Timestamp Valid
91 *
92 *  This method determines the validity of a timestamp.
93 *
94 *  @param[in] time is the timestamp instance to validate.
95 *
96 *  @return This method returns true if @a time is valid and
97 *          false otherwise.
98 */
99#if defined(RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
100  #define _Timestamp_Is_valid( _time ) \
101          _Timespec_Is_valid( _time )
102#endif
103
104/** @brief Timestamp Less Than Operator
105 *
106 *  This method is the less than operator for timestamps.
107 *
108 *  @param[in] lhs is the left hand side timestamp
109 *  @param[in] rhs is the right hand side timestamp
110 *
111 *  @return This method returns true if @a lhs is less than the @a rhs and
112 *          false otherwise.
113 */
114#if defined(RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
115  #define _Timestamp_Less_than( _lhs, _rhs ) \
116          _Timespec_Less_than( _lhs, _rhs )
117#endif
118
119/** @brief Timestamp Greater Than Operator
120 *
121 *  This method is the greater than operator for timestamps.
122 *
123 *  @param[in] lhs is the left hand side timestamp
124 *  @param[in] rhs is the right hand side timestamp
125 *
126 *  @return This method returns true if @a lhs is greater than the @a rhs and
127 *          false otherwise.
128 */
129#if defined(RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
130  #define _Timestamp_Greater_than( _lhs, _rhs ) \
131          _Timespec_Greater_than( _lhs, _rhs )
132#endif
133
134/** @brief Timestamp equal to Operator
135 *
136 *  This method is the is equal to than operator for timestamps.
137 *
138 *  @param[in] lhs is the left hand side timestamp
139 *  @param[in] rhs is the right hand side timestamp
140 *
141 *  @return This method returns true if @a lhs is equal to  @a rhs and
142 *          false otherwise.
143 */
144#if defined(RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
145  #define _Timestamp_Equal_to( _lhs, _rhs ) \
146          _Timespec_Equal_to( _lhs, _rhs )
147#endif
148
149/** @brief Add to a Timestamp
150 *
151 *  This routine adds two timestamps.  The second argument is added
152 *  to the first.
153 *
154 *  @param[in] time points to the base time to be added to
155 *  @param[in] add points to the timestamp to add to the first argument
156 */
157#if defined(RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
158  #define _Timestamp_Add_to( _time, _add ) \
159          _Timespec_Add_to( _time, _add )
160#endif
161
162/** @brief Add to a Timestamp (At Clock Tick)
163 *
164 *  This routine adds two timestamps.  The second argument is added
165 *  to the first.
166 * 
167 *  @node This routine places a special requirement on the addition
168 *        operation.  It must return the number of units that the
169 *        seconds field changed as the result of the addition.  Since this
170 *        operation is ONLY used as part of processing a clock tick,
171 *        it is generally safe to assume that only one second changed.
172 *
173 *  @param[in] time points to the base time to be added to
174 *  @param[in] add points to the timestamp to add to the first argument
175 *
176 *  @return This method returns the number of seconds @a time increased by.
177 */
178#if defined(RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
179  #define _Timestamp_Add_to_at_tick( _time, _add ) \
180          _Timespec_Add_to( _time, _add )
181#endif
182
183/** @brief Convert Timestamp to Number of Ticks
184 *
185 *  This routine convert the @a time timestamp to the corresponding number
186 *  of clock ticks.
187 *
188 *  @param[in] time points to the time to be converted
189 *
190 *  @return This method returns the number of ticks computed.
191 */
192#if defined(RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
193  #define _Timestamp_To_ticks( _time ) \
194          _Timespec_To_ticks( _time )
195#endif
196
197/** @brief Convert Ticks to Timestamp
198 *
199 *  This routine converts the @a ticks value to the corresponding
200 *  timestamp format @a time.
201 *
202 *  @param[in] time points to the timestamp format time result
203 *  @param[in] ticks points to the the number of ticks to be filled in
204 */
205#if defined(RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
206  #define _Timestamp_From_ticks( _ticks, _time ) \
207          _Timespec_From_ticks( _ticks, _time )
208#endif
209
210/** @brief Subtract Two Timestamp
211 *
212 *  This routine subtracts two timestamps.  @a result is set to
213 *  @a end - @a start.
214 *
215 *  @param[in] start points to the starting time
216 *  @param[in] end points to the ending time
217 *  @param[in] result points to the difference between starting and ending time.
218 *
219 *  @return This method fills in @a result.
220 */
221#if defined(RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
222  #define _Timestamp_Subtract( _start, _end, _result ) \
223          _Timespec_Subtract( _start, _end, _result )
224#endif
225
226/** @brief Divide Timestamp By Integer
227 *
228 *  This routine divides a timestamp by an integer value.  The expected
229 *  use is to assist in benchmark calculations where you typically
230 *  divide a duration by a number of iterations.
231 *
232 *  @param[in] time points to the total
233 *  @param[in] iterations is the number of iterations
234 *  @param[in] result points to the average time.
235 *
236 *  @return This method fills in @a result.
237 */
238#if defined(RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
239  #define _Timestamp_Divide_by_integer( _time, _iterations, _result ) \
240          _Timespec_Divide_by_integer(_time, _iterations, _result )
241#endif
242
243/** @brief Divide Timestamp
244 *
245 *  This routine divides a timestamp by another timestamp.  The
246 *  intended use is for calculating percentages to three decimal points.
247 *
248 *  @param[in] lhs points to the left hand number
249 *  @param[in] rhs points to the right hand number
250 *  @param[in] ival_percentage is the integer portion of the average
251 *  @param[in] fval_percentage is the thousandths of percentage
252 *
253 *  @return This method fills in @a result.
254 */
255#if defined(RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
256  #define _Timestamp_Divide( _lhs, _rhs, _ival_percentage, _fval_percentage ) \
257          _Timespec_Divide( _lhs, _rhs, _ival_percentage, _fval_percentage )
258#endif
259
260/** @brief Get Seconds Portion of Timestamp
261 *
262 *  This method returns the seconds portion of the specified timestamp
263 *
264 *  @param[in] _time points to the timestamp
265 *
266 *  @return The seconds portion of @a _time.
267 */
268#if defined(RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
269  #define _Timestamp_Get_seconds( _time ) \
270          ((_time)->tv_sec)
271#endif
272
273/** @brief Get Nanoseconds Portion of Timestamp
274 *
275 *  This method returns the nanoseconds portion of the specified timestamp
276 *
277 *  @param[in] _time points to the timestamp
278 *
279 *  @return The nanoseconds portion of @a _time.
280 */
281#if defined(RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
282  #define _Timestamp_Get_nanoseconds( _time ) \
283          ((_time)->tv_nsec)
284#endif
285
286/** @brief Convert Timestamp to struct timespec
287 *
288 *  This method returns the seconds portion of the specified timestamp
289 *
290 *  @param[in] _timestamp points to the timestamp
291 *  @param[in] _timespec points to the timespec
292 */
293#if defined(RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
294  #define _Timestamp_To_timespec( _timestamp, _timespec  ) \
295          *(_timespec) = *(_timestamp)
296#endif
297
298#ifdef __cplusplus
299}
300#endif
301
302/**@}*/
303
304#endif
305/* end of include file */
Note: See TracBrowser for help on using the repository browser.