source: rtems/cpukit/include/rtems/timespec.h @ a660e9dc

Last change on this file since a660e9dc was a660e9dc, checked in by Sebastian Huber <sebastian.huber@…>, on 09/08/22 at 08:37:05

Do not use RTEMS_INLINE_ROUTINE

Directly use "static inline" which is available in C99 and later. This brings
the RTEMS implementation closer to standard C.

Close #3935.

  • Property mode set to 100644
File size: 8.0 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @brief Timespec API
7 *
8 * This include file contains API for manipulating timespecs.
9 */
10
11/*
12 *  Copyright (c) 2012.
13 *  Krzysztof Miesowicz <krzysztof.miesowicz@gmail.com>
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 *    notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 *    notice, this list of conditions and the following disclaimer in the
22 *    documentation and/or other materials provided with the distribution.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 */
36
37#ifndef _RTEMS_TIMESPEC_H
38#define _RTEMS_TIMESPEC_H
39
40#include <rtems/score/timespec.h>
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
46/**
47 *  @defgroup TimespecAPI Timespec
48 *
49 *  @ingroup RTEMSAPIClassic
50 *
51 *  @brief Timespec API
52 *
53 * @{
54 *
55 */
56
57/**
58 * @brief Is timespec valid
59 *
60 * This method determines the validity of a timespec.
61 *
62 * @param[in] time is the timespec instance to validate.
63 *
64 * @retval true The timespec is valid.
65 * @retval false The timespec is not valid.
66 */
67static inline bool rtems_timespec_is_valid(
68  const struct timespec *time
69)
70{
71  return _Timespec_Is_valid(time);
72}
73
74/**
75 * @brief Timespec less than operator.
76 *
77 * This method is the less than operator for timespecs.
78 *
79 * @param[in] lhs is the left hand side timespec
80 * @param[in] rhs is the right hand side timespec
81 *
82 * @retval true @a lhs is less than @a rhs.
83 * @retval false @a lhs is not less than @a rhs.
84 *
85 */
86static inline bool rtems_timespec_less_than(
87  const struct timespec *lhs,
88  const struct timespec *rhs
89)
90{
91  return _Timespec_Less_than(lhs,rhs);
92}
93
94/**
95 * @brief Add to a timespec.
96 *
97 * This routine adds two timespecs.  The second argument is added
98 * to the first.
99 *
100 * @param[in] time is the base time to be added to
101 * @param[in] add is the timespec to add to the first argument
102 *
103 * @return This method returns the number of seconds @a time increased by.
104 */
105static inline uint32_t rtems_timespec_add_to(
106  struct timespec       *time,
107  const struct timespec *add
108)
109{
110  return _Timespec_Add_to(time,add);
111}
112
113/**
114 * @brief Convert timespec to number of ticks.
115 *
116 * This routine convert the @a time timespec to the corresponding number
117 * of clock ticks.
118 *
119 * @param[in] time is the time to be converted
120 *
121 * @return This method returns the number of ticks computed.
122 */
123static inline uint32_t rtems_timespec_to_ticks(
124  const struct timespec *time
125)
126{
127  return _Timespec_To_ticks(time);
128}
129
130/**
131 * @brief Convert ticks to timespec.
132 *
133 * This routine converts the @a ticks value to the corresponding
134 * timespec format @a time.
135 *
136 * @param[in] time is the timespec format time result
137 * @param[in] ticks is the number of ticks to convert
138 */
139
140static inline void rtems_timespec_from_ticks(
141  uint32_t         ticks,
142  struct timespec *time
143)
144{
145  _Timespec_From_ticks(ticks,time);
146}
147
148/**
149 * @brief Subtract two timespec.
150 *
151 * This routine subtracts two timespecs.  @a result is set to
152 * @a end - @a start.
153 *
154 * @param[in] start is the starting time
155 * @param[in] end is the ending time
156 * @param[in] result is the difference between starting and ending time.
157 *
158 * @return This method fills in @a result.
159 */
160static inline void rtems_timespec_subtract(
161  const struct timespec *start,
162  const struct timespec *end,
163  struct timespec       *result
164)
165{
166  _Timespec_Subtract(start,end,result);
167}
168
169/**
170 * @brief Divide timespec by integer.
171 *
172 * This routine divides a timespec by an integer value.  The expected
173 * use is to assist in benchmark calculations where you typically
174 * divide a duration by a number of iterations.
175 *
176 * @param[in] time is the total
177 * @param[in] iterations is the number of iterations
178 * @param[in] result is the average time.
179 *
180 * @return This method fills in @a result.
181 */
182static inline void rtems_timespec_divide_by_integer(
183  const struct timespec *time,
184  uint32_t               iterations,
185  struct timespec       *result
186)
187{
188  _Timespec_Divide_by_integer(time,iterations,result);
189}
190
191/**
192 * @brief Divide timespec.
193 *
194 * This routine divides a timespec by another timespec.  The
195 * intended use is for calculating percentages to three decimal points.
196 *
197 * @param[in] lhs is the left hand number
198 * @param[in] rhs is the right hand number
199 * @param[in] ival_percentage is the integer portion of the average
200 * @param[in] fval_percentage is the thousandths of percentage
201 *
202 * @return This method fills in @a result.
203 */
204static inline void rtems_timespec_divide(
205  const struct timespec *lhs,
206  const struct timespec *rhs,
207  uint32_t              *ival_percentage,
208  uint32_t              *fval_percentage
209)
210{
211  _Timespec_Divide(lhs,rhs,ival_percentage,fval_percentage);
212}
213
214/**
215 * @brief Set timespec to seconds nanosecond.
216 *
217 * This method sets the timespec to the specified seconds and nanoseconds
218 * value.
219 *
220 * @param[in] _time points to the timespec instance to validate.
221 * @param[in] _seconds is the seconds portion of the timespec
222 * @param[in] _nanoseconds is the nanoseconds portion of the timespec
223 */
224static inline void rtems_timespec_set(
225  struct timespec *_time,
226  time_t _seconds,
227  uint32_t _nanoseconds
228)
229{
230  _Timespec_Set( _time, _seconds, _nanoseconds );
231}
232
233/**
234 * @brief Zero timespec.
235 *
236 * This method sets the timespec to zero.
237 * value.
238 *
239 * @param[in] _time points to the timespec instance to zero.
240 */
241static inline void rtems_timespec_zero(
242  struct timespec *_time
243)
244{
245  _Timespec_Set_to_zero( _time );
246}
247
248/**
249 * @brief Get seconds portion of timespec.
250 *
251 * This method returns the seconds portion of the specified timespec
252 *
253 * @param[in] _time points to the timespec
254 *
255 * @return The seconds portion of @a _time.
256 */
257static inline time_t rtems_timespec_get_seconds(
258  struct timespec *_time
259)
260{
261  return _Timespec_Get_seconds( _time );
262}
263
264/**
265 * @brief Get nanoseconds portion of timespec.
266 *
267 * This method returns the nanoseconds portion of the specified timespec
268 *
269 * @param[in] _time points to the timespec
270 *
271 * @return The nanoseconds portion of @a _time.
272 */
273static inline uint32_t rtems_timespec_get_nanoseconds(
274  struct timespec *_time
275)
276{
277  return _Timespec_Get_nanoseconds( _time );
278}
279
280/**
281 * @brief Timespec greater than operator.
282 *
283 * This method is the greater than operator for timespecs.
284 *
285 * @param[in] _lhs is the left hand side timespec
286 * @param[in] _rhs is the right hand side timespec
287 *
288 * @retval true @a _lhs is greater than @a _rhs.
289 * @retval false @a _lhs is not greater than @a _rhs.
290 */
291static inline bool rtems_timespec_greater_than(
292  const struct timespec *_lhs,
293  const struct timespec *_rhs
294)
295{
296  return _Timespec_Greater_than( _lhs, _rhs );
297}
298/**
299 * @brief Timespec equal to Operator
300 *
301 * This method is the is equal to than operator for timespecs.
302 *
303 * @param[in] lhs is the left hand side timespec
304 * @param[in] rhs is the right hand side timespec
305 *
306 * @retval true @a lhs is equal to @a rhs.
307 * @retval false @a lhs is not equal to @a rhs.
308 */
309static inline bool rtems_timespec_equal_to(
310  const struct timespec *lhs,
311  const struct timespec *rhs
312)
313{
314  return _Timespec_Equal_to( lhs, rhs);
315}
316
317/** @} */
318
319#ifdef __cplusplus
320}
321#endif
322
323#endif
324/* end of include file */
Note: See TracBrowser for help on using the repository browser.