1 | /** |
---|
2 | * @file rtems/score/timespec.h |
---|
3 | * |
---|
4 | * This include file contains helpers for manipulating timespecs. |
---|
5 | */ |
---|
6 | |
---|
7 | /* |
---|
8 | * COPYRIGHT (c) 1989-2007. |
---|
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 | boolean _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 | boolean _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 | boolean _Timespec_Greater_than( |
---|
76 | const struct timespec *lhs, |
---|
77 | const struct timespec *rhs |
---|
78 | ); |
---|
79 | |
---|
80 | /** @brief Add to a Timespec |
---|
81 | * |
---|
82 | * This routine adds two timespecs. The second argument is added |
---|
83 | * to the first. |
---|
84 | * |
---|
85 | * @param[in] time is the base time to be added to |
---|
86 | * @param[in] add is the timespec to add to the first argument |
---|
87 | * |
---|
88 | * @return This method returns the number of seconds @a time increased by. |
---|
89 | */ |
---|
90 | uint32_t _Timespec_Add_to( |
---|
91 | struct timespec *time, |
---|
92 | const struct timespec *add |
---|
93 | ); |
---|
94 | |
---|
95 | /** @brief Convert Timespec to Number of Ticks |
---|
96 | * |
---|
97 | * This routine convert the @a time timespec to the corresponding number |
---|
98 | * of clock ticks. |
---|
99 | * |
---|
100 | * @param[in] time is the time to be converted |
---|
101 | * |
---|
102 | * @return This method returns the number of ticks computed. |
---|
103 | */ |
---|
104 | uint32_t _Timespec_To_ticks( |
---|
105 | const struct timespec *time |
---|
106 | ); |
---|
107 | |
---|
108 | /** @brief Convert Ticks to Timespec |
---|
109 | * |
---|
110 | * This routine converts the @a ticks value to the corresponding |
---|
111 | * timespec format @a time. |
---|
112 | * |
---|
113 | * @param[in] time is the timespec format time result |
---|
114 | * @param[in] ticks is the number of ticks to convert |
---|
115 | */ |
---|
116 | void _Timespec_From_ticks( |
---|
117 | uint32_t ticks, |
---|
118 | struct timespec *time |
---|
119 | ); |
---|
120 | |
---|
121 | /** @brief Subtract Two Timespec |
---|
122 | * |
---|
123 | * This routine subtracts two timespecs. @a result is set to |
---|
124 | * @a end - @a start. |
---|
125 | * |
---|
126 | * @param[in] start is the starting time |
---|
127 | * @param[in] end is the ending time |
---|
128 | * @param[in] result is the difference between starting and ending time. |
---|
129 | * |
---|
130 | * @return This method fills in @a result. |
---|
131 | */ |
---|
132 | void _Timespec_Subtract( |
---|
133 | const struct timespec *start, |
---|
134 | const struct timespec *end, |
---|
135 | struct timespec *result |
---|
136 | ); |
---|
137 | |
---|
138 | /** @brief Divide Timespec By Integet |
---|
139 | * |
---|
140 | * This routine divides a timespec by an integer value. The expected |
---|
141 | * use is to assist in benchmark calculations where you typically |
---|
142 | * divide a duration by a number of iterations. |
---|
143 | * |
---|
144 | * @param[in] time is the total |
---|
145 | * @param[in] iterations is the number of iterations |
---|
146 | * @param[in] result is the average time. |
---|
147 | * |
---|
148 | * @return This method fills in @a result. |
---|
149 | */ |
---|
150 | void _Timespec_Divide_by_integer( |
---|
151 | const struct timespec *time, |
---|
152 | uint32_t iterations, |
---|
153 | struct timespec *result |
---|
154 | ); |
---|
155 | |
---|
156 | /** @brief Divide Timespec |
---|
157 | * |
---|
158 | * This routine divides a timespec by another timespec. The |
---|
159 | * intended use is for calculating percentages to three decimal points. |
---|
160 | * |
---|
161 | * @param[in] lhs is the left hand number |
---|
162 | * @param[in] rhs is the righ hand number |
---|
163 | * @param[in] ival_percentage is the integer portion of the average |
---|
164 | * @param[in] fval_percentage is the thousandths of percentage |
---|
165 | * |
---|
166 | * @return This method fills in @a result. |
---|
167 | */ |
---|
168 | void _Timespec_Divide( |
---|
169 | const struct timespec *lhs, |
---|
170 | const struct timespec *rhs, |
---|
171 | uint32_t *ival_percentage, |
---|
172 | uint32_t *fval_percentage |
---|
173 | ); |
---|
174 | |
---|
175 | #ifdef __cplusplus |
---|
176 | } |
---|
177 | #endif |
---|
178 | |
---|
179 | /**@}*/ |
---|
180 | |
---|
181 | #endif |
---|
182 | /* end of include file */ |
---|