1 | /** |
---|
2 | * @file rtems/rtems/clock.h |
---|
3 | * |
---|
4 | * @defgroup ClassicClock Clocks |
---|
5 | * |
---|
6 | * @ingroup ClassicRTEMS |
---|
7 | * @brief Clock Manager API |
---|
8 | * |
---|
9 | * This include file contains all the constants and structures associated |
---|
10 | * with the Clock Manager. This manager provides facilities to set, obtain, |
---|
11 | * and continually update the current date and time. |
---|
12 | * |
---|
13 | * This manager provides directives to: |
---|
14 | * |
---|
15 | * - set the current date and time |
---|
16 | * - obtain the current date and time |
---|
17 | * - set the nanoseconds since last clock tick handler |
---|
18 | * - announce a clock tick |
---|
19 | * - obtain the system uptime |
---|
20 | */ |
---|
21 | |
---|
22 | /* COPYRIGHT (c) 1989-2013. |
---|
23 | * On-Line Applications Research Corporation (OAR). |
---|
24 | * |
---|
25 | * The license and distribution terms for this file may be |
---|
26 | * found in the file LICENSE in this distribution or at |
---|
27 | * http://www.rtems.com/license/LICENSE. |
---|
28 | */ |
---|
29 | |
---|
30 | #ifndef _RTEMS_RTEMS_CLOCK_H |
---|
31 | #define _RTEMS_RTEMS_CLOCK_H |
---|
32 | |
---|
33 | #include <rtems/score/watchdog.h> |
---|
34 | #include <rtems/score/tod.h> |
---|
35 | #include <rtems/rtems/status.h> |
---|
36 | #include <rtems/rtems/types.h> |
---|
37 | |
---|
38 | #include <sys/time.h> /* struct timeval */ |
---|
39 | |
---|
40 | /** |
---|
41 | * @defgroup ClassicClock Clocks |
---|
42 | * |
---|
43 | * @ingroup ClassicRTEMS |
---|
44 | * |
---|
45 | * This encapsulates functionality related to the Classic API Clock |
---|
46 | * Manager. |
---|
47 | */ |
---|
48 | /**@{*/ |
---|
49 | |
---|
50 | #ifdef __cplusplus |
---|
51 | extern "C" { |
---|
52 | #endif |
---|
53 | |
---|
54 | /** |
---|
55 | * List of things which can be returned by the rtems_clock_get directive. |
---|
56 | */ |
---|
57 | typedef enum { |
---|
58 | /** This value indicates obtain TOD in Classic API format. */ |
---|
59 | RTEMS_CLOCK_GET_TOD, |
---|
60 | /** This value indicates obtain the number of seconds since the epoch. */ |
---|
61 | RTEMS_CLOCK_GET_SECONDS_SINCE_EPOCH, |
---|
62 | /** This value indicates obtain the number of ticks since system boot. */ |
---|
63 | RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, |
---|
64 | /** This value indicates obtain the number of ticks per second. */ |
---|
65 | RTEMS_CLOCK_GET_TICKS_PER_SECOND, |
---|
66 | /** This value indicates obtain the TOD in struct timeval format. */ |
---|
67 | RTEMS_CLOCK_GET_TIME_VALUE |
---|
68 | } rtems_clock_get_options; |
---|
69 | |
---|
70 | /** |
---|
71 | * Type for the nanoseconds since last tick BSP extension. |
---|
72 | */ |
---|
73 | typedef TOD_Nanoseconds_since_last_tick_routine |
---|
74 | rtems_nanoseconds_extension_routine; |
---|
75 | |
---|
76 | /** |
---|
77 | * @brief Obtain Current Time of Day |
---|
78 | * |
---|
79 | * This routine implements the rtems_clock_get directive. It returns |
---|
80 | * one of the following: |
---|
81 | * + current time of day |
---|
82 | * + seconds since epoch |
---|
83 | * + ticks since boot |
---|
84 | * + ticks per second |
---|
85 | * |
---|
86 | * @param[in] option is the format of time to return |
---|
87 | * @param[in] time_buffer points to the output area |
---|
88 | * |
---|
89 | * @retval This method returns RTEMS_SUCCESSFUL if there was not an |
---|
90 | * error. Otherwise, a status code is returned indicating the |
---|
91 | * source of the error. |
---|
92 | */ |
---|
93 | rtems_status_code rtems_clock_get( |
---|
94 | rtems_clock_get_options option, |
---|
95 | void *time_buffer |
---|
96 | ); |
---|
97 | |
---|
98 | /** |
---|
99 | * @brief Obtain Current Time of Day (Classic TOD) |
---|
100 | * |
---|
101 | * This routine implements the rtems_clock_get_tod directive. It returns |
---|
102 | * the current time of day in the format defined by RTEID. |
---|
103 | * |
---|
104 | * Clock Manager - rtems_clock_get_tod |
---|
105 | * |
---|
106 | * @param[in] time_buffer points to the time of day structure |
---|
107 | * |
---|
108 | * @retval This method returns RTEMS_SUCCESSFUL if there was not an |
---|
109 | * error. Otherwise, a status code is returned indicating the |
---|
110 | * source of the error. If successful, the time_buffer will |
---|
111 | * be filled in with the current time of day. |
---|
112 | */ |
---|
113 | rtems_status_code rtems_clock_get_tod( |
---|
114 | rtems_time_of_day *time_buffer |
---|
115 | ); |
---|
116 | |
---|
117 | /** |
---|
118 | * @brief Obtain TOD in struct timeval Format |
---|
119 | * |
---|
120 | * This routine implements the rtems_clock_get_tod_timeval |
---|
121 | * directive. |
---|
122 | * |
---|
123 | * @param[in] time points to the struct timeval variable to fill in |
---|
124 | * |
---|
125 | * @retval This method returns RTEMS_SUCCESSFUL if there was not an |
---|
126 | * error. Otherwise, a status code is returned indicating the |
---|
127 | * source of the error. If successful, the time will |
---|
128 | * be filled in with the current time of day. |
---|
129 | */ |
---|
130 | rtems_status_code rtems_clock_get_tod_timeval( |
---|
131 | struct timeval *time |
---|
132 | ); |
---|
133 | |
---|
134 | /** |
---|
135 | * @brief Obtain Seconds Since Epoch |
---|
136 | * |
---|
137 | * This routine implements the rtems_clock_get_seconds_since_epoch |
---|
138 | * directive. |
---|
139 | * |
---|
140 | * @param[in] the_interval points to the interval variable to fill in |
---|
141 | * |
---|
142 | * @retval This method returns RTEMS_SUCCESSFUL if there was not an |
---|
143 | * error. Otherwise, a status code is returned indicating the |
---|
144 | * source of the error. If successful, the time_buffer will |
---|
145 | * be filled in with the current time of day. |
---|
146 | */ |
---|
147 | rtems_status_code rtems_clock_get_seconds_since_epoch( |
---|
148 | rtems_interval *the_interval |
---|
149 | ); |
---|
150 | |
---|
151 | /** |
---|
152 | * @brief Obtain Ticks Since Boot |
---|
153 | * |
---|
154 | * This routine implements the rtems_clock_get_ticks_since_boot |
---|
155 | * directive. |
---|
156 | * |
---|
157 | * @retval This method returns the number of ticks since boot. It cannot |
---|
158 | * fail since RTEMS always keeps a running count of ticks since boot. |
---|
159 | */ |
---|
160 | rtems_interval rtems_clock_get_ticks_since_boot(void); |
---|
161 | |
---|
162 | /** |
---|
163 | * @brief Obtain Ticks Per Seconds |
---|
164 | * |
---|
165 | * This routine implements the rtems_clock_get_ticks_per_second |
---|
166 | * directive. |
---|
167 | * |
---|
168 | * @retval This method returns the number of ticks since boot. It cannot |
---|
169 | * fail since RTEMS is always configured to know the number of |
---|
170 | * ticks per second. |
---|
171 | */ |
---|
172 | rtems_interval rtems_clock_get_ticks_per_second(void); |
---|
173 | |
---|
174 | /** |
---|
175 | * @brief Set the Current TOD |
---|
176 | * |
---|
177 | * This routine implements the rtems_clock_set directive. It sets |
---|
178 | * the current time of day to that in the time_buffer record. |
---|
179 | * |
---|
180 | * @param[in] time_buffer points to the new TOD |
---|
181 | * |
---|
182 | * @retval This method returns RTEMS_SUCCESSFUL if there was not an |
---|
183 | * error. Otherwise, a status code is returned indicating the |
---|
184 | * source of the error. |
---|
185 | * |
---|
186 | * @note Activities scheduled based upon the current time of day |
---|
187 | * may be executed immediately if the time is moved forward. |
---|
188 | */ |
---|
189 | rtems_status_code rtems_clock_set( |
---|
190 | const rtems_time_of_day *time_buffer |
---|
191 | ); |
---|
192 | |
---|
193 | /** |
---|
194 | * @brief Announce a Clock Tick |
---|
195 | * |
---|
196 | * This routine implements the rtems_clock_tick directive. It is invoked |
---|
197 | * to inform RTEMS of the occurrence of a clock tick. |
---|
198 | * |
---|
199 | * @retval This directive always returns RTEMS_SUCCESSFUL. |
---|
200 | * |
---|
201 | * @note This method is typically called from an ISR and is the basis |
---|
202 | * for all timeouts and delays. This routine only works for leap-years |
---|
203 | * through 2099. |
---|
204 | */ |
---|
205 | rtems_status_code rtems_clock_tick( void ); |
---|
206 | |
---|
207 | /** |
---|
208 | * @brief Set the BSP specific Nanoseconds Extension |
---|
209 | * |
---|
210 | * Clock Manager |
---|
211 | * |
---|
212 | * This directive sets the BSP provided nanoseconds since last tick |
---|
213 | * extension. |
---|
214 | * |
---|
215 | * @param[in] routine is a pointer to the extension routine |
---|
216 | * |
---|
217 | * @return This method returns RTEMS_SUCCESSFUL if there was not an |
---|
218 | * error. Otherwise, a status code is returned indicating the |
---|
219 | * source of the error. |
---|
220 | */ |
---|
221 | rtems_status_code rtems_clock_set_nanoseconds_extension( |
---|
222 | rtems_nanoseconds_extension_routine routine |
---|
223 | ); |
---|
224 | |
---|
225 | /** |
---|
226 | * @brief Obtain the System Uptime |
---|
227 | * |
---|
228 | * This directive returns the system uptime. |
---|
229 | * |
---|
230 | * @param[in] uptime is a pointer to the time structure |
---|
231 | * |
---|
232 | * @retval This method returns RTEMS_SUCCESSFUL if there was not an |
---|
233 | * error. Otherwise, a status code is returned indicating the |
---|
234 | * source of the error. If successful, the @a uptime will be |
---|
235 | * filled in. |
---|
236 | */ |
---|
237 | rtems_status_code rtems_clock_get_uptime( |
---|
238 | struct timespec *uptime |
---|
239 | ); |
---|
240 | |
---|
241 | /** |
---|
242 | * @brief Gets the System Uptime in the Struct Timeval Format |
---|
243 | * |
---|
244 | * @param[out] uptime is a pointer to a struct timeval structure. |
---|
245 | * |
---|
246 | * @retval This methods returns the system uptime. |
---|
247 | * |
---|
248 | * @note Pointer must not be NULL. |
---|
249 | */ |
---|
250 | void rtems_clock_get_uptime_timeval( struct timeval *uptime ); |
---|
251 | |
---|
252 | /** |
---|
253 | * @brief Returns the system uptime in seconds. |
---|
254 | * |
---|
255 | * @retval The system uptime in seconds. |
---|
256 | */ |
---|
257 | time_t rtems_clock_get_uptime_seconds( void ); |
---|
258 | |
---|
259 | /** |
---|
260 | * @brief TOD Validate |
---|
261 | * |
---|
262 | * This support function returns true if @a the_tod contains |
---|
263 | * a valid time of day, and false otherwise. |
---|
264 | * |
---|
265 | * @param[in] the_tod is the TOD structure to validate |
---|
266 | * |
---|
267 | * @retval This method returns true if the TOD is valid and false otherwise. |
---|
268 | * |
---|
269 | * @note This routine only works for leap-years through 2099. |
---|
270 | */ |
---|
271 | bool _TOD_Validate( |
---|
272 | const rtems_time_of_day *the_tod |
---|
273 | ); |
---|
274 | |
---|
275 | /** |
---|
276 | * @brief TOD to Seconds |
---|
277 | * |
---|
278 | * This function returns the number seconds between the epoch and @a the_tod. |
---|
279 | * |
---|
280 | * @param[in] the_tod is the TOD structure to convert to seconds |
---|
281 | * |
---|
282 | * @retval This method returns the number of seconds since epoch represented |
---|
283 | * by @a the_tod |
---|
284 | */ |
---|
285 | Watchdog_Interval _TOD_To_seconds( |
---|
286 | const rtems_time_of_day *the_tod |
---|
287 | ); |
---|
288 | |
---|
289 | #ifdef __cplusplus |
---|
290 | } |
---|
291 | #endif |
---|
292 | |
---|
293 | /**@}*/ |
---|
294 | |
---|
295 | #endif |
---|
296 | /* end of include file */ |
---|