1 | /** |
---|
2 | * @file rtems/score/timespec.h |
---|
3 | * |
---|
4 | * This include file contains helpers for manipulating timespecs. |
---|
5 | */ |
---|
6 | |
---|
7 | /* |
---|
8 | * COPYRIGHT (c) 1989-2008. |
---|
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 | * This handler encapsulates functionality related to manipulating |
---|
25 | * POSIX struct timespecs. |
---|
26 | */ |
---|
27 | /**@{*/ |
---|
28 | |
---|
29 | #ifdef __cplusplus |
---|
30 | extern "C" { |
---|
31 | #endif |
---|
32 | |
---|
33 | #include <sys/types.h> |
---|
34 | #include <rtems/score/tod.h> |
---|
35 | #include <rtems/score/watchdog.h> |
---|
36 | |
---|
37 | /** @brief Is Timespec Valid |
---|
38 | * |
---|
39 | * This method determines the validatity of a timespec. |
---|
40 | * |
---|
41 | * @param[in] time is the timespec instance to validate. |
---|
42 | * |
---|
43 | * @return This method returns true if @a time is valid and |
---|
44 | * false otherwise. |
---|
45 | */ |
---|
46 | bool _Timespec_Is_valid( |
---|
47 | const struct timespec *time |
---|
48 | ); |
---|
49 | |
---|
50 | /** @brief Timespec Less Than Operator |
---|
51 | * |
---|
52 | * This method is the less than operator for timespecs. |
---|
53 | * |
---|
54 | * @param[in] lhs is the left hand side timespec |
---|
55 | * @param[in] rhs is the left hand side timespec |
---|
56 | * |
---|
57 | * @return This method returns true if @a lhs is less than the @a rhs and |
---|
58 | * false otherwise. |
---|
59 | */ |
---|
60 | bool _Timespec_Less_than( |
---|
61 | const struct timespec *lhs, |
---|
62 | const struct timespec *rhs |
---|
63 | ); |
---|
64 | |
---|
65 | /** @brief Timespec Greater Than Operator |
---|
66 | * |
---|
67 | * This method is the greater than operator for timespecs. |
---|
68 | * |
---|
69 | * @param[in] lhs is the left hand side timespec |
---|
70 | * @param[in] rhs is the left hand side timespec |
---|
71 | * |
---|
72 | * @return This method returns true if @a lhs is greater than the @a rhs and |
---|
73 | * false otherwise. |
---|
74 | */ |
---|
75 | bool _Timespec_Greater_than( |
---|
76 | const struct timespec *lhs, |
---|
77 | const struct timespec *rhs |
---|
78 | ); |
---|
79 | |
---|
80 | /** @brief Timespec equal to Operator |
---|
81 | * |
---|
82 | * This method is the is equal to than operator for timespecs. |
---|
83 | * |
---|
84 | * @param[in] lhs is the left hand side timespec |
---|
85 | * @param[in] rhs is the left hand side timespec |
---|
86 | * |
---|
87 | * @return This method returns true if @a lhs is equal to @a rhs and |
---|
88 | * false otherwise. |
---|
89 | */ |
---|
90 | #define _Timespec_Equal_to( lhs, rhs ) \ |
---|
91 | ( ((lhs)->tv_sec == (rhs)->tv_sec) && \ |
---|
92 | ((lhs)->tv_nsec == (rhs)->tv_nsec) \ |
---|
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 | */ |
---|
105 | uint32_t _Timespec_Add_to( |
---|
106 | struct timespec *time, |
---|
107 | const struct timespec *add |
---|
108 | ); |
---|
109 | |
---|
110 | /** @brief Convert Timespec to Number of Ticks |
---|
111 | * |
---|
112 | * This routine convert the @a time timespec to the corresponding number |
---|
113 | * of clock ticks. |
---|
114 | * |
---|
115 | * @param[in] time is the time to be converted |
---|
116 | * |
---|
117 | * @return This method returns the number of ticks computed. |
---|
118 | */ |
---|
119 | uint32_t _Timespec_To_ticks( |
---|
120 | const struct timespec *time |
---|
121 | ); |
---|
122 | |
---|
123 | /** @brief Convert Ticks to Timespec |
---|
124 | * |
---|
125 | * This routine converts the @a ticks value to the corresponding |
---|
126 | * timespec format @a time. |
---|
127 | * |
---|
128 | * @param[in] time is the timespec format time result |
---|
129 | * @param[in] ticks is the number of ticks to convert |
---|
130 | */ |
---|
131 | void _Timespec_From_ticks( |
---|
132 | uint32_t ticks, |
---|
133 | struct timespec *time |
---|
134 | ); |
---|
135 | |
---|
136 | /** @brief Subtract Two Timespec |
---|
137 | * |
---|
138 | * This routine subtracts two timespecs. @a result is set to |
---|
139 | * @a end - @a start. |
---|
140 | * |
---|
141 | * @param[in] start is the starting time |
---|
142 | * @param[in] end is the ending time |
---|
143 | * @param[in] result is the difference between starting and ending time. |
---|
144 | * |
---|
145 | * @return This method fills in @a result. |
---|
146 | */ |
---|
147 | void _Timespec_Subtract( |
---|
148 | const struct timespec *start, |
---|
149 | const struct timespec *end, |
---|
150 | struct timespec *result |
---|
151 | ); |
---|
152 | |
---|
153 | /** @brief Divide Timespec By Integet |
---|
154 | * |
---|
155 | * This routine divides a timespec by an integer value. The expected |
---|
156 | * use is to assist in benchmark calculations where you typically |
---|
157 | * divide a duration by a number of iterations. |
---|
158 | * |
---|
159 | * @param[in] time is the total |
---|
160 | * @param[in] iterations is the number of iterations |
---|
161 | * @param[in] result is the average time. |
---|
162 | * |
---|
163 | * @return This method fills in @a result. |
---|
164 | */ |
---|
165 | void _Timespec_Divide_by_integer( |
---|
166 | const struct timespec *time, |
---|
167 | uint32_t iterations, |
---|
168 | struct timespec *result |
---|
169 | ); |
---|
170 | |
---|
171 | /** @brief Divide Timespec |
---|
172 | * |
---|
173 | * This routine divides a timespec by another timespec. The |
---|
174 | * intended use is for calculating percentages to three decimal points. |
---|
175 | * |
---|
176 | * @param[in] lhs is the left hand number |
---|
177 | * @param[in] rhs is the righ hand number |
---|
178 | * @param[in] ival_percentage is the integer portion of the average |
---|
179 | * @param[in] fval_percentage is the thousandths of percentage |
---|
180 | * |
---|
181 | * @return This method fills in @a result. |
---|
182 | */ |
---|
183 | void _Timespec_Divide( |
---|
184 | const struct timespec *lhs, |
---|
185 | const struct timespec *rhs, |
---|
186 | uint32_t *ival_percentage, |
---|
187 | uint32_t *fval_percentage |
---|
188 | ); |
---|
189 | |
---|
190 | #ifdef __cplusplus |
---|
191 | } |
---|
192 | #endif |
---|
193 | |
---|
194 | /**@}*/ |
---|
195 | |
---|
196 | #endif |
---|
197 | /* end of include file */ |
---|