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 |
---|
45 | extern "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 Convert Timestamp to Number of Ticks |
---|
198 | * |
---|
199 | * This routine convert the @a time timestamp to the corresponding number |
---|
200 | * of clock ticks. |
---|
201 | * |
---|
202 | * @param[in] _time points to the time to be converted |
---|
203 | * |
---|
204 | * @return This method returns the number of ticks computed. |
---|
205 | */ |
---|
206 | #if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE |
---|
207 | #define _Timestamp_To_ticks( _time ) \ |
---|
208 | _Timespec_To_ticks( _time ) |
---|
209 | #else |
---|
210 | #define _Timestamp_To_ticks( _time ) \ |
---|
211 | _Timestamp64_To_ticks( _time ) |
---|
212 | #endif |
---|
213 | |
---|
214 | /** |
---|
215 | * @brief Convert Ticks to Timestamp |
---|
216 | * |
---|
217 | * This routine converts the @a _ticks value to the corresponding |
---|
218 | * timestamp format @a _time. |
---|
219 | * |
---|
220 | * @param[in] _time points to the timestamp format time result |
---|
221 | * @param[in] _ticks points to the number of ticks to be filled in |
---|
222 | */ |
---|
223 | #if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE |
---|
224 | #define _Timestamp_From_ticks( _ticks, _time ) \ |
---|
225 | _Timespec_From_ticks( _ticks, _time ) |
---|
226 | #else |
---|
227 | #define _Timestamp_From_ticks( _ticks, _time ) \ |
---|
228 | _Timestamp64_From_ticks( _ticks, _time ) |
---|
229 | #endif |
---|
230 | |
---|
231 | /** |
---|
232 | * @brief Subtract Two Timestamp |
---|
233 | * |
---|
234 | * This routine subtracts two timestamps. @a result is set to |
---|
235 | * @a end - @a start. |
---|
236 | * |
---|
237 | * @param[in] _start points to the starting time |
---|
238 | * @param[in] _end points to the ending time |
---|
239 | * @param[in] _result points to the difference between |
---|
240 | * starting and ending time. |
---|
241 | * |
---|
242 | * @return This method fills in @a _result. |
---|
243 | */ |
---|
244 | #if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE |
---|
245 | #define _Timestamp_Subtract( _start, _end, _result ) \ |
---|
246 | _Timespec_Subtract( _start, _end, _result ) |
---|
247 | #else |
---|
248 | #define _Timestamp_Subtract( _start, _end, _result ) \ |
---|
249 | _Timestamp64_Subtract( _start, _end, _result ) |
---|
250 | #endif |
---|
251 | |
---|
252 | /** |
---|
253 | * @brief Divide Timestamp By Integer |
---|
254 | * |
---|
255 | * This routine divides a timestamp by an integer value. The expected |
---|
256 | * use is to assist in benchmark calculations where you typically |
---|
257 | * divide a duration by a number of iterations. |
---|
258 | * |
---|
259 | * @param[in] _time points to the total |
---|
260 | * @param[in] _iterations is the number of iterations |
---|
261 | * @param[in] _result points to the average time. |
---|
262 | * |
---|
263 | * @return This method fills in @a result. |
---|
264 | */ |
---|
265 | #if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE |
---|
266 | #define _Timestamp_Divide_by_integer( _time, _iterations, _result ) \ |
---|
267 | _Timespec_Divide_by_integer(_time, _iterations, _result ) |
---|
268 | #else |
---|
269 | #define _Timestamp_Divide_by_integer( _time, _iterations, _result ) \ |
---|
270 | _Timestamp64_Divide_by_integer( _time, _iterations, _result ) |
---|
271 | #endif |
---|
272 | |
---|
273 | /** |
---|
274 | * @brief Divide Timestamp |
---|
275 | * |
---|
276 | * This routine divides a timestamp by another timestamp. The |
---|
277 | * intended use is for calculating percentages to three decimal points. |
---|
278 | * |
---|
279 | * @param[in] _lhs points to the left hand number |
---|
280 | * @param[in] _rhs points to the right hand number |
---|
281 | * @param[in] _ival_percentage points to the integer portion of the average |
---|
282 | * @param[in] _fval_percentage points to the thousandths of percentage |
---|
283 | * |
---|
284 | * @return This method fills in @a result. |
---|
285 | */ |
---|
286 | #if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE |
---|
287 | #define _Timestamp_Divide( _lhs, _rhs, _ival_percentage, _fval_percentage ) \ |
---|
288 | _Timespec_Divide( _lhs, _rhs, _ival_percentage, _fval_percentage ) |
---|
289 | #else |
---|
290 | #define _Timestamp_Divide( _lhs, _rhs, _ival_percentage, _fval_percentage ) \ |
---|
291 | _Timestamp64_Divide( _lhs, _rhs, _ival_percentage, _fval_percentage ) |
---|
292 | #endif |
---|
293 | |
---|
294 | /** |
---|
295 | * @brief Get Seconds Portion of Timestamp |
---|
296 | * |
---|
297 | * This method returns the seconds portion of the specified timestamp |
---|
298 | * |
---|
299 | * @param[in] _time points to the timestamp |
---|
300 | * |
---|
301 | * @return The seconds portion of @a _time. |
---|
302 | */ |
---|
303 | #if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE |
---|
304 | #define _Timestamp_Get_seconds( _time ) \ |
---|
305 | _Timespec_Get_seconds( _time ) |
---|
306 | #else |
---|
307 | #define _Timestamp_Get_seconds( _time ) \ |
---|
308 | _Timestamp64_Get_seconds( _time ) |
---|
309 | #endif |
---|
310 | |
---|
311 | /** |
---|
312 | * @brief Get Nanoseconds Portion of Timestamp |
---|
313 | * |
---|
314 | * This method returns the nanoseconds portion of the specified timestamp |
---|
315 | * |
---|
316 | * @param[in] _time points to the timestamp |
---|
317 | * |
---|
318 | * @return The nanoseconds portion of @a _time. |
---|
319 | */ |
---|
320 | #if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE |
---|
321 | #define _Timestamp_Get_nanoseconds( _time ) \ |
---|
322 | _Timespec_Get_nanoseconds( _time ) |
---|
323 | #else |
---|
324 | #define _Timestamp_Get_nanoseconds( _time ) \ |
---|
325 | _Timestamp64_Get_nanoseconds( _time ) |
---|
326 | #endif |
---|
327 | |
---|
328 | /** |
---|
329 | * @brief Convert Timestamp to struct timespec |
---|
330 | * |
---|
331 | * This method returns the seconds portion of the specified timestamp |
---|
332 | * |
---|
333 | * @param[in] _timestamp points to the timestamp |
---|
334 | * @param[in] _timespec points to the timespec |
---|
335 | */ |
---|
336 | #if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE |
---|
337 | /* in this case we know they are the same type so use simple assignment */ |
---|
338 | #define _Timestamp_To_timespec( _timestamp, _timespec ) \ |
---|
339 | *(_timespec) = *(_timestamp) |
---|
340 | #else |
---|
341 | #define _Timestamp_To_timespec( _timestamp, _timespec ) \ |
---|
342 | _Timestamp64_To_timespec( _timestamp, _timespec ) |
---|
343 | #endif |
---|
344 | |
---|
345 | #ifdef __cplusplus |
---|
346 | } |
---|
347 | #endif |
---|
348 | |
---|
349 | /**@}*/ |
---|
350 | |
---|
351 | #endif |
---|
352 | /* end of include file */ |
---|