source: rtems/cpukit/sapi/inline/rtems/timespec.inl @ fd71610

4.115
Last change on this file since fd71610 was fd71610, checked in by Ralf Corsépius <ralf.corsepius@…>, on 10/11/12 at 16:25:03

Cleanup Krzysztof's copyright notices.

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