1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Timespec API |
---|
5 | */ |
---|
6 | |
---|
7 | /* |
---|
8 | * Copyright (c) 2012. |
---|
9 | * Krzysztof Miesowicz <krzysztof.miesowicz@gmail.com> |
---|
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_TIMESPEC_H |
---|
17 | # error "Never use <rtems/timespec.inl> directly; include <rtems/timespec.h> instead." |
---|
18 | #endif |
---|
19 | |
---|
20 | #ifndef _RTEMS_TIMESPEC_INL |
---|
21 | #define _RTEMS_TIMESPEC_INL |
---|
22 | |
---|
23 | #include <rtems/score/timespec.h> |
---|
24 | |
---|
25 | /** |
---|
26 | * @addtogroup TimespecAPI Timespec |
---|
27 | * |
---|
28 | * @{ |
---|
29 | */ |
---|
30 | |
---|
31 | /** |
---|
32 | * @brief Is timespec valid |
---|
33 | * |
---|
34 | * This method determines the validity of a timespec. |
---|
35 | * |
---|
36 | * @param[in] time is the timespec instance to validate. |
---|
37 | * |
---|
38 | * @retval true The timespec is valid. |
---|
39 | * @retval false The timespec is not valid. |
---|
40 | */ |
---|
41 | RTEMS_INLINE_ROUTINE bool rtems_timespec_is_valid( |
---|
42 | const struct timespec *time |
---|
43 | ) |
---|
44 | { |
---|
45 | return _Timespec_Is_valid(time); |
---|
46 | } |
---|
47 | |
---|
48 | /** |
---|
49 | * @brief Timespec less than operator. |
---|
50 | * |
---|
51 | * This method is the less than operator for timespecs. |
---|
52 | * |
---|
53 | * @param[in] lhs is the left hand side timespec |
---|
54 | * @param[in] rhs is the right hand side timespec |
---|
55 | * |
---|
56 | * @retval true @a lhs is less than @a rhr. |
---|
57 | * @retval false @a lhs is not less than @a rhr. |
---|
58 | * |
---|
59 | */ |
---|
60 | RTEMS_INLINE_ROUTINE bool rtems_timespec_less_than( |
---|
61 | const struct timespec *lhs, |
---|
62 | const struct timespec *rhs |
---|
63 | ) |
---|
64 | { |
---|
65 | return _Timespec_Less_than(lhs,rhs); |
---|
66 | } |
---|
67 | |
---|
68 | /** |
---|
69 | * @brief Add to a timespec. |
---|
70 | * |
---|
71 | * This routine adds two timespecs. The second argument is added |
---|
72 | * to the first. |
---|
73 | * |
---|
74 | * @param[in] time is the base time to be added to |
---|
75 | * @param[in] add is the timespec to add to the first argument |
---|
76 | * |
---|
77 | * @return This method returns the number of seconds @a time increased by. |
---|
78 | */ |
---|
79 | RTEMS_INLINE_ROUTINE uint32_t rtems_timespec_add_to( |
---|
80 | struct timespec *time, |
---|
81 | const struct timespec *add |
---|
82 | ) |
---|
83 | { |
---|
84 | return _Timespec_Add_to(time,add); |
---|
85 | } |
---|
86 | |
---|
87 | /** |
---|
88 | * @brief Convert timespec to number of ticks. |
---|
89 | * |
---|
90 | * This routine convert the @a time timespec to the corresponding number |
---|
91 | * of clock ticks. |
---|
92 | * |
---|
93 | * @param[in] time is the time to be converted |
---|
94 | * |
---|
95 | * @return This method returns the number of ticks computed. |
---|
96 | */ |
---|
97 | RTEMS_INLINE_ROUTINE uint32_t rtems_timespec_to_ticks( |
---|
98 | const struct timespec *time |
---|
99 | ) |
---|
100 | { |
---|
101 | return _Timespec_To_ticks(time); |
---|
102 | } |
---|
103 | |
---|
104 | /** |
---|
105 | * @brief Convert ticks to timespec. |
---|
106 | * |
---|
107 | * This routine converts the @a ticks value to the corresponding |
---|
108 | * timespec format @a time. |
---|
109 | * |
---|
110 | * @param[in] time is the timespec format time result |
---|
111 | * @param[in] ticks is the number of ticks to convert |
---|
112 | */ |
---|
113 | |
---|
114 | RTEMS_INLINE_ROUTINE void rtems_timespec_from_ticks( |
---|
115 | uint32_t ticks, |
---|
116 | struct timespec *time |
---|
117 | ) |
---|
118 | { |
---|
119 | _Timespec_From_ticks(ticks,time); |
---|
120 | } |
---|
121 | |
---|
122 | /** |
---|
123 | * @brief Subtract two timespec. |
---|
124 | * |
---|
125 | * This routine subtracts two timespecs. @a result is set to |
---|
126 | * @a end - @a start. |
---|
127 | * |
---|
128 | * @param[in] start is the starting time |
---|
129 | * @param[in] end is the ending time |
---|
130 | * @param[in] result is the difference between starting and ending time. |
---|
131 | * |
---|
132 | * @return This method fills in @a result. |
---|
133 | */ |
---|
134 | RTEMS_INLINE_ROUTINE void rtems_timespec_subtract( |
---|
135 | const struct timespec *start, |
---|
136 | const struct timespec *end, |
---|
137 | struct timespec *result |
---|
138 | ) |
---|
139 | { |
---|
140 | _Timespec_Subtract(start,end,result); |
---|
141 | } |
---|
142 | |
---|
143 | /** |
---|
144 | * @brief Divide timespec by integer. |
---|
145 | * |
---|
146 | * This routine divides a timespec by an integer value. The expected |
---|
147 | * use is to assist in benchmark calculations where you typically |
---|
148 | * divide a duration by a number of iterations. |
---|
149 | * |
---|
150 | * @param[in] time is the total |
---|
151 | * @param[in] iterations is the number of iterations |
---|
152 | * @param[in] result is the average time. |
---|
153 | * |
---|
154 | * @return This method fills in @a result. |
---|
155 | */ |
---|
156 | RTEMS_INLINE_ROUTINE void rtems_timespec_divide_by_integer( |
---|
157 | const struct timespec *time, |
---|
158 | uint32_t iterations, |
---|
159 | struct timespec *result |
---|
160 | ) |
---|
161 | { |
---|
162 | _Timespec_Divide_by_integer(time,iterations,result); |
---|
163 | } |
---|
164 | |
---|
165 | /** |
---|
166 | * @brief Divide timespec. |
---|
167 | * |
---|
168 | * This routine divides a timespec by another timespec. The |
---|
169 | * intended use is for calculating percentages to three decimal points. |
---|
170 | * |
---|
171 | * @param[in] lhs is the left hand number |
---|
172 | * @param[in] rhs is the right hand number |
---|
173 | * @param[in] ival_percentage is the integer portion of the average |
---|
174 | * @param[in] fval_percentage is the thousandths of percentage |
---|
175 | * |
---|
176 | * @return This method fills in @a result. |
---|
177 | */ |
---|
178 | RTEMS_INLINE_ROUTINE void rtems_timespec_divide( |
---|
179 | const struct timespec *lhs, |
---|
180 | const struct timespec *rhs, |
---|
181 | uint32_t *ival_percentage, |
---|
182 | uint32_t *fval_percentage |
---|
183 | ) |
---|
184 | { |
---|
185 | _Timespec_Divide(lhs,rhs,ival_percentage,fval_percentage); |
---|
186 | } |
---|
187 | |
---|
188 | /** |
---|
189 | * @brief Set timespec to seconds nanosecond. |
---|
190 | * |
---|
191 | * This method sets the timespec to the specified seconds and nanoseconds |
---|
192 | * value. |
---|
193 | * |
---|
194 | * @param[in] _time points to the timespec instance to validate. |
---|
195 | * @param[in] _seconds is the seconds portion of the timespec |
---|
196 | * @param[in] _nanoseconds is the nanoseconds portion of the timespec |
---|
197 | */ |
---|
198 | RTEMS_INLINE_ROUTINE void rtems_timespec_set( |
---|
199 | struct timespec *_time, |
---|
200 | time_t _seconds, |
---|
201 | uint32_t _nanoseconds |
---|
202 | ) |
---|
203 | { |
---|
204 | _Timespec_Set( _time, _seconds, _nanoseconds ); |
---|
205 | } |
---|
206 | |
---|
207 | /** |
---|
208 | * @brief Zero timespec. |
---|
209 | * |
---|
210 | * This method sets the timespec to zero. |
---|
211 | * value. |
---|
212 | * |
---|
213 | * @param[in] _time points to the timespec instance to zero. |
---|
214 | */ |
---|
215 | RTEMS_INLINE_ROUTINE void rtems_timespec_zero( |
---|
216 | struct timespec *_time |
---|
217 | ) |
---|
218 | { |
---|
219 | _Timespec_Set_to_zero( _time ); |
---|
220 | } |
---|
221 | |
---|
222 | /** |
---|
223 | * @brief Get seconds portion of timespec. |
---|
224 | * |
---|
225 | * This method returns the seconds portion of the specified timespec |
---|
226 | * |
---|
227 | * @param[in] _time points to the timespec |
---|
228 | * |
---|
229 | * @return The seconds portion of @a _time. |
---|
230 | */ |
---|
231 | RTEMS_INLINE_ROUTINE time_t rtems_timespec_get_seconds( |
---|
232 | struct timespec *_time |
---|
233 | ) |
---|
234 | { |
---|
235 | return _Timespec_Get_seconds( _time ); |
---|
236 | } |
---|
237 | |
---|
238 | /** |
---|
239 | * @brief Get nanoseconds portion of timespec. |
---|
240 | * |
---|
241 | * This method returns the nanoseconds portion of the specified timespec |
---|
242 | * |
---|
243 | * @param[in] _time points to the timespec |
---|
244 | * |
---|
245 | * @return The nanoseconds portion of @a _time. |
---|
246 | */ |
---|
247 | RTEMS_INLINE_ROUTINE uint32_t rtems_timespec_get_nanoseconds( |
---|
248 | struct timespec *_time |
---|
249 | ) |
---|
250 | { |
---|
251 | return _Timespec_Get_nanoseconds( _time ); |
---|
252 | } |
---|
253 | |
---|
254 | |
---|
255 | /** |
---|
256 | * @brief Timespec greater than operator. |
---|
257 | * |
---|
258 | * This method is the greater than operator for timespecs. |
---|
259 | * |
---|
260 | * @param[in] lhs is the left hand side timespec |
---|
261 | * @param[in] rhs is the right hand side timespec |
---|
262 | * |
---|
263 | * @retval true @a lhs is greater than @a rhr. |
---|
264 | * @retval false @a lhs is not greater than @a rhr. |
---|
265 | */ |
---|
266 | RTEMS_INLINE_ROUTINE bool rtems_timespec_greater_than( |
---|
267 | const struct timespec *_lhs, |
---|
268 | const struct timespec *_rhs |
---|
269 | ) |
---|
270 | { |
---|
271 | return _Timespec_Greater_than( _lhs, _rhs ); |
---|
272 | } |
---|
273 | /** |
---|
274 | * @brief Timespec equal to Operator |
---|
275 | * |
---|
276 | * This method is the is equal to than operator for timespecs. |
---|
277 | * |
---|
278 | * @param[in] lhs is the left hand side timespec |
---|
279 | * @param[in] rhs is the right hand side timespec |
---|
280 | * |
---|
281 | * @retval true @a lhs is equal to @a rhr. |
---|
282 | * @retval false @a lhs is not equal to @a rhr. |
---|
283 | */ |
---|
284 | RTEMS_INLINE_ROUTINE bool rtems_timespec_equal_to( |
---|
285 | const struct timespec *lhs, |
---|
286 | const struct timespec *rhs |
---|
287 | ) |
---|
288 | { |
---|
289 | return _Timespec_Equal_to( lhs, rhs); |
---|
290 | } |
---|
291 | |
---|
292 | /** @} */ |
---|
293 | |
---|
294 | #endif |
---|
295 | /* end of include file */ |
---|