source: rtems/cpukit/score/include/rtems/score/timespec.h @ d8cd045c

4.115
Last change on this file since d8cd045c was d8cd045c, checked in by Joel Sherrill <joel.sherrill@…>, on 06/17/11 at 15:40:09

2011-06-17 Joel Sherrill <joel.sherrill@…>

  • rtems/include/rtems/rtems/types.h, score/include/rtems/score/address.h, score/include/rtems/score/apiext.h, score/include/rtems/score/bitfield.h, score/include/rtems/score/context.h, score/include/rtems/score/corebarrier.h, score/include/rtems/score/coremsg.h, score/include/rtems/score/coremutex.h, score/include/rtems/score/corerwlock.h, score/include/rtems/score/coresem.h, score/include/rtems/score/corespinlock.h, score/include/rtems/score/interr.h, score/include/rtems/score/isr.h, score/include/rtems/score/mpci.h, score/include/rtems/score/mppkt.h, score/include/rtems/score/objectmp.h, score/include/rtems/score/percpu.h, score/include/rtems/score/priority.h, score/include/rtems/score/rbtree.h, score/include/rtems/score/scheduler.h, score/include/rtems/score/smp.h, score/include/rtems/score/smplock.h, score/include/rtems/score/stack.h, score/include/rtems/score/states.h, score/include/rtems/score/thread.h, score/include/rtems/score/threadq.h, score/include/rtems/score/threadsync.h, score/include/rtems/score/timespec.h, score/include/rtems/score/timestamp.h, score/include/rtems/score/timestamp64.h, score/include/rtems/score/tod.h, score/include/rtems/score/tqdata.h, score/include/rtems/score/watchdog.h, score/include/rtems/score/wkspace.h: Mark Score files as in Score Group to improve Doxygen output.
  • Property mode set to 100644
File size: 6.3 KB
Line 
1/**
2 *  @file  rtems/score/timespec.h
3 *
4 *  This include file contains helpers for manipulating timespecs.
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 *  $Id$
16 */
17
18#ifndef _RTEMS_SCORE_TIMESPEC_H
19#define _RTEMS_SCORE_TIMESPEC_H
20
21/**
22 *  @defgroup Timespec Helpers
23 *
24 *  @ingroup Score
25 *
26 *  This handler encapsulates functionality related to manipulating
27 *  POSIX struct timespecs.
28 */
29/**@{*/
30
31#include <stdbool.h> /* bool */
32#include <stdint.h> /* uint32_t */
33#include <time.h> /* struct timespec */
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39/**
40 * @brief Set Timespec to Seconds Nanosecond
41 *
42 *  This method sets the timespec to the specified seconds and nanoseconds
43 *  value.
44 *
45 *  @param[in] _time points to the timespec instance to validate.
46 *  @param[in] _seconds is the seconds portion of the timespec
47 *  @param[in] _nanoseconds is the nanoseconds portion of the timespec
48 */
49#define _Timespec_Set( _time, _seconds, _nanoseconds ) \
50        do { \
51           (_time)->tv_sec = (_seconds); \
52           (_time)->tv_nsec = (_nanoseconds); \
53        } while (0)
54
55/**
56 * @brief Zero Timespec
57 *
58 *  This method sets the timespec to zero.
59 *  value.
60 *
61 *  @param[in] _time points to the timespec instance to zero.
62 */
63#define _Timespec_Set_to_zero( _time ) \
64        do { \
65           (_time)->tv_sec = 0; \
66           (_time)->tv_nsec = 0; \
67        } while (0)
68
69/**
70 * @brief Get Seconds Portion of Timespec
71 *
72 *  This method returns the seconds portion of the specified timespec
73 *
74 *  @param[in] _time points to the timespec
75 *
76 *  @return The seconds portion of @a _time.
77 */
78#define _Timespec_Get_seconds( _time ) \
79        ((_time)->tv_sec)
80
81/**
82 * @brief Get Nanoseconds Portion of Timespec
83 *
84 *  This method returns the nanoseconds portion of the specified timespec
85 *
86 *  @param[in] _time points to the timespec
87 *
88 *  @return The nanoseconds portion of @a _time.
89 */
90#define _Timespec_Get_nanoseconds( _time ) \
91        ((_time)->tv_nsec)
92
93/**
94 * @brief Is Timespec Valid
95 *
96 *  This method determines the validity of a timespec.
97 *
98 *  @param[in] time is the timespec instance to validate.
99 *
100 *  @return This method returns true if @a time is valid and
101 *          false otherwise.
102 */
103bool _Timespec_Is_valid(
104  const struct timespec *time
105);
106
107/**
108 * @brief Timespec Less Than Operator
109 *
110 *  This method is the less than operator for timespecs.
111 *
112 *  @param[in] lhs is the left hand side timespec
113 *  @param[in] rhs is the right hand side timespec
114 *
115 *  @return This method returns true if @a lhs is less than the @a rhs and
116 *          false otherwise.
117 */
118bool _Timespec_Less_than(
119  const struct timespec *lhs,
120  const struct timespec *rhs
121);
122
123/**
124 * @brief Timespec Greater Than Operator
125 *
126 *  This method is the greater than operator for timespecs.
127 *
128 *  @param[in] lhs is the left hand side timespec
129 *  @param[in] rhs is the right hand side timespec
130 *
131 *  @return This method returns true if @a lhs is greater than the @a rhs and
132 *          false otherwise.
133 */
134bool _Timespec_Greater_than(
135  const struct timespec *lhs,
136  const struct timespec *rhs
137);
138
139/**
140 * @brief Timespec equal to Operator
141 *
142 *  This method is the is equal to than operator for timespecs.
143 *
144 *  @param[in] lhs is the left hand side timespec
145 *  @param[in] rhs is the right hand side timespec
146 *
147 *  @return This method returns true if @a lhs is equal to  @a rhs and
148 *          false otherwise.
149 */
150#define _Timespec_Equal_to( lhs, rhs ) \
151  ( ((lhs)->tv_sec  == (rhs)->tv_sec) &&   \
152    ((lhs)->tv_nsec == (rhs)->tv_nsec)     \
153  )
154
155/**
156 * @brief Add to a Timespec
157 *
158 *  This routine adds two timespecs.  The second argument is added
159 *  to the first.
160 *
161 *  @param[in] time is the base time to be added to
162 *  @param[in] add is the timespec to add to the first argument
163 *
164 *  @return This method returns the number of seconds @a time increased by.
165 */
166uint32_t _Timespec_Add_to(
167  struct timespec       *time,
168  const struct timespec *add
169);
170
171/**
172 * @brief Convert Timespec to Number of Ticks
173 *
174 *  This routine convert the @a time timespec to the corresponding number
175 *  of clock ticks.
176 *
177 *  @param[in] time is the time to be converted
178 *
179 *  @return This method returns the number of ticks computed.
180 */
181uint32_t _Timespec_To_ticks(
182  const struct timespec *time
183);
184
185/**
186 * @brief Convert Ticks to Timespec
187 *
188 *  This routine converts the @a ticks value to the corresponding
189 *  timespec format @a time.
190 *
191 *  @param[in] time is the timespec format time result
192 *  @param[in] ticks is the number of ticks to convert
193 */
194void _Timespec_From_ticks(
195  uint32_t         ticks,
196  struct timespec *time
197);
198
199/**
200 * @brief Subtract Two Timespec
201 *
202 *  This routine subtracts two timespecs.  @a result is set to
203 *  @a end - @a start.
204 *
205 *  @param[in] start is the starting time
206 *  @param[in] end is the ending time
207 *  @param[in] result is the difference between starting and ending time.
208 *
209 *  @return This method fills in @a result.
210 */
211void _Timespec_Subtract(
212  const struct timespec *start,
213  const struct timespec *end,
214  struct timespec       *result
215);
216
217/**
218 * @brief Divide Timespec By Integer
219 *
220 *  This routine divides a timespec by an integer value.  The expected
221 *  use is to assist in benchmark calculations where you typically
222 *  divide a duration by a number of iterations.
223 *
224 *  @param[in] time is the total
225 *  @param[in] iterations is the number of iterations
226 *  @param[in] result is the average time.
227 *
228 *  @return This method fills in @a result.
229 */
230void _Timespec_Divide_by_integer(
231  const struct timespec *time,
232  uint32_t               iterations,
233  struct timespec       *result
234);
235
236/**
237 * @brief Divide Timespec
238 *
239 *  This routine divides a timespec by another timespec.  The
240 *  intended use is for calculating percentages to three decimal points.
241 *
242 *  @param[in] lhs is the left hand number
243 *  @param[in] rhs is the right hand number
244 *  @param[in] ival_percentage is the integer portion of the average
245 *  @param[in] fval_percentage is the thousandths of percentage
246 *
247 *  @return This method fills in @a result.
248 */
249void _Timespec_Divide(
250  const struct timespec *lhs,
251  const struct timespec *rhs,
252  uint32_t              *ival_percentage,
253  uint32_t              *fval_percentage
254);
255
256#ifdef __cplusplus
257}
258#endif
259
260/**@}*/
261
262#endif
263/* end of include file */
Note: See TracBrowser for help on using the repository browser.