source: rtems/cpukit/rtems/include/rtems/rtems/clock.h @ 23e43f6

4.115
Last change on this file since 23e43f6 was 23e43f6, checked in by Gedare Bloom <gedare@…>, on 03/10/15 at 17:51:21

cpukit: deprecate rtems_clock_get(). closes #2294.

  • Property mode set to 100644
File size: 10.2 KB
Line 
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.org/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#include <rtems/config.h>
38
39#include <sys/time.h> /* struct timeval */
40
41/**
42 *  @defgroup ClassicClock Clocks
43 *
44 *  @ingroup ClassicRTEMS
45 *
46 *  This encapsulates functionality related to the Classic API Clock
47 *  Manager.
48 */
49/**@{*/
50
51#ifdef __cplusplus
52extern "C" {
53#endif
54
55/**
56 *  List of things which can be returned by the rtems_clock_get directive.
57 */
58typedef enum {
59  /** This value indicates obtain TOD in Classic API format. */
60  RTEMS_CLOCK_GET_TOD,
61  /** This value indicates obtain the number of seconds since the epoch. */
62  RTEMS_CLOCK_GET_SECONDS_SINCE_EPOCH,
63  /** This value indicates obtain the number of ticks since system boot. */
64  RTEMS_CLOCK_GET_TICKS_SINCE_BOOT,
65  /** This value indicates obtain the number of ticks per second. */
66  RTEMS_CLOCK_GET_TICKS_PER_SECOND,
67  /** This value indicates obtain the TOD in struct timeval format. */
68  RTEMS_CLOCK_GET_TIME_VALUE
69} rtems_clock_get_options;
70
71/**
72 *  Type for the nanoseconds since last tick BSP extension.
73 */
74typedef TOD_Nanoseconds_since_last_tick_routine
75  rtems_nanoseconds_extension_routine;
76
77/**
78 * @brief Obtain Current Time of Day
79 *
80 * @deprecated rtems_clock_get() is deprecated. Use the more explicit
81 * function calls rtems_clock_get_xxx().
82 *
83 * This routine implements the rtems_clock_get directive. It returns
84 * one of the following:
85 * + current time of day
86 * + seconds since epoch
87 * + ticks since boot
88 * + ticks per second
89 *
90 * @param[in] option is the format of time to return
91 * @param[in] time_buffer points to the output area
92 *
93 * @retval This method returns RTEMS_SUCCESSFUL if there was not an
94 *         error. Otherwise, a status code is returned indicating the
95 *         source of the error.
96 */
97rtems_status_code rtems_clock_get(
98  rtems_clock_get_options  option,
99  void                    *time_buffer
100) RTEMS_COMPILER_DEPRECATED_ATTRIBUTE;
101
102/**
103 * @brief Obtain Current Time of Day (Classic TOD)
104 *
105 * This routine implements the rtems_clock_get_tod directive. It returns
106 * the current time of day in the format defined by RTEID.
107 *
108 * Clock Manager - rtems_clock_get_tod
109 *
110 * @param[in] time_buffer points to the time of day structure
111 *
112 * @retval This method returns RTEMS_SUCCESSFUL if there was not an
113 *         error. Otherwise, a status code is returned indicating the
114 *         source of the error. If successful, the time_buffer will
115 *         be filled in with the current time of day.
116 */
117rtems_status_code rtems_clock_get_tod(
118  rtems_time_of_day *time_buffer
119);
120
121/**
122 * @brief Obtain TOD in struct timeval Format
123 *
124 * This routine implements the rtems_clock_get_tod_timeval
125 * directive.
126 *
127 * @param[in] time points to the struct timeval variable to fill in
128 *
129 * @retval This method returns RTEMS_SUCCESSFUL if there was not an
130 *         error. Otherwise, a status code is returned indicating the
131 *         source of the error. If successful, the time will
132 *         be filled in with the current time of day.
133 */
134rtems_status_code rtems_clock_get_tod_timeval(
135  struct timeval *time
136);
137
138/**
139 * @brief Obtain Seconds Since Epoch
140 *
141 * This routine implements the rtems_clock_get_seconds_since_epoch
142 * directive.
143 *
144 * @param[in] the_interval points to the interval variable to fill in
145 *
146 * @retval This method returns RTEMS_SUCCESSFUL if there was not an
147 *         error. Otherwise, a status code is returned indicating the
148 *         source of the error. If successful, the time_buffer will
149 *         be filled in with the current time of day.
150 */
151rtems_status_code rtems_clock_get_seconds_since_epoch(
152  rtems_interval *the_interval
153);
154
155/**
156 * @brief Gets the current ticks counter value.
157 *
158 * @return The current tick counter value.  With a 1ms clock tick, this counter
159 * overflows after 50 days since boot.
160 */
161RTEMS_INLINE_ROUTINE rtems_interval rtems_clock_get_ticks_since_boot(void)
162{
163  return _Watchdog_Ticks_since_boot;
164}
165
166/**
167 * @brief Returns the ticks counter value delta ticks in the future.
168 *
169 * @param[in] delta The ticks delta value.
170 *
171 * @return The tick counter value delta ticks in the future.
172 */
173RTEMS_INLINE_ROUTINE rtems_interval rtems_clock_tick_later(
174  rtems_interval delta
175)
176{
177  return _Watchdog_Ticks_since_boot + delta;
178}
179
180/**
181 * @brief Returns the ticks counter value at least delta microseconds in the
182 * future.
183 *
184 * @param[in] delta_in_usec The delta value in microseconds.
185 *
186 * @return The tick counter value at least delta microseconds in the future.
187 */
188RTEMS_INLINE_ROUTINE rtems_interval rtems_clock_tick_later_usec(
189  rtems_interval delta_in_usec
190)
191{
192  rtems_interval us_per_tick = rtems_configuration_get_microseconds_per_tick();
193
194  /*
195   * Add one additional tick, since we don't know the time to the clock next
196   * tick.
197   */
198  return _Watchdog_Ticks_since_boot
199    + (delta_in_usec + us_per_tick - 1) / us_per_tick + 1;
200}
201
202/**
203 * @brief Returns true if the current ticks counter value indicates a time
204 * before the time specified by the tick value and false otherwise.
205 *
206 * @param[in] tick The tick value.
207 *
208 * This can be used to write busy loops with a timeout.
209 *
210 * @code
211 * status busy( void )
212 * {
213 *   rtems_interval timeout = rtems_clock_tick_later_usec( 10000 );
214 *
215 *   do {
216 *     if ( ok() ) {
217 *       return success;
218 *     }
219 *   } while ( rtems_clock_tick_before( timeout ) );
220 *
221 *   return timeout;
222 * }
223 * @endcode
224 *
225 * @retval true The current ticks counter value indicates a time before the
226 * time specified by the tick value.
227 * @retval false Otherwise.
228 */
229RTEMS_INLINE_ROUTINE bool rtems_clock_tick_before(
230  rtems_interval tick
231)
232{
233  return (int32_t) ( tick - _Watchdog_Ticks_since_boot ) > 0;
234}
235
236/**
237 * @brief Obtain Ticks Per Seconds
238 *
239 * This routine implements the rtems_clock_get_ticks_per_second
240 * directive.
241 *
242 * @retval This method returns the number of ticks since boot. It cannot
243 *         fail since RTEMS is always configured to know the number of
244 *         ticks per second.
245 */
246rtems_interval rtems_clock_get_ticks_per_second(void);
247
248/**
249 * @brief Set the Current TOD
250 *
251 * This routine implements the rtems_clock_set directive. It sets
252 * the current time of day to that in the time_buffer record.
253 *
254 * @param[in] time_buffer points to the new TOD
255 *
256 * @retval This method returns RTEMS_SUCCESSFUL if there was not an
257 *         error. Otherwise, a status code is returned indicating the
258 *         source of the error.
259 *
260 * @note Activities scheduled based upon the current time of day
261 *       may be executed immediately if the time is moved forward.
262 */
263rtems_status_code rtems_clock_set(
264  const rtems_time_of_day *time_buffer
265);
266
267/**
268 * @brief Announce a Clock Tick
269 *
270 * This routine implements the rtems_clock_tick directive. It is invoked
271 * to inform RTEMS of the occurrence of a clock tick.
272 *
273 * @retval This directive always returns RTEMS_SUCCESSFUL.
274 *
275 * @note This method is typically called from an ISR and is the basis
276 *       for all timeouts and delays. This routine only works for leap-years
277 *       through 2099.
278 */
279rtems_status_code rtems_clock_tick( void );
280
281/**
282 * @brief Set the BSP specific Nanoseconds Extension
283 *
284 * Clock Manager
285 *
286 * This directive sets the BSP provided nanoseconds since last tick
287 * extension.
288 *
289 * @param[in] routine is a pointer to the extension routine
290 *
291 * @return This method returns RTEMS_SUCCESSFUL if there was not an
292 *         error. Otherwise, a status code is returned indicating the
293 *         source of the error.
294 */
295rtems_status_code rtems_clock_set_nanoseconds_extension(
296  rtems_nanoseconds_extension_routine routine
297);
298
299/**
300 * @brief Obtain the System Uptime
301 *
302 * This directive returns the system uptime.
303 *
304 * @param[in] uptime is a pointer to the time structure
305 *
306 * @retval This method returns RTEMS_SUCCESSFUL if there was not an
307 *         error. Otherwise, a status code is returned indicating the
308 *         source of the error. If successful, the @a uptime will be
309 *         filled in.
310 */
311rtems_status_code rtems_clock_get_uptime(
312  struct timespec *uptime
313);
314
315/**
316 * @brief Gets the System Uptime in the Struct Timeval Format
317 *
318 * @param[out] uptime is a pointer to a struct timeval structure.
319 *
320 * @retval This methods returns the system uptime.
321 *
322 * @note Pointer must not be NULL.
323 */
324void rtems_clock_get_uptime_timeval( struct timeval *uptime );
325
326/**
327 * @brief Returns the system uptime in seconds.
328 *
329 * @retval The system uptime in seconds.
330 */
331time_t rtems_clock_get_uptime_seconds( void );
332
333/**
334 * @brief Returns the system uptime in nanoseconds.
335 *
336 * @retval The system uptime in nanoseconds.
337 */
338uint64_t rtems_clock_get_uptime_nanoseconds( void );
339
340/**
341 * @brief TOD Validate
342 *
343 * This support function returns true if @a the_tod contains
344 * a valid time of day, and false otherwise.
345 *
346 * @param[in] the_tod is the TOD structure to validate
347 *
348 * @retval This method returns true if the TOD is valid and false otherwise.
349 *
350 * @note This routine only works for leap-years through 2099.
351 */
352bool _TOD_Validate(
353  const rtems_time_of_day *the_tod
354);
355
356/**
357 * @brief TOD to Seconds
358 *
359 * This function returns the number seconds between the epoch and @a the_tod.
360 *
361 * @param[in] the_tod is the TOD structure to convert to seconds
362 *
363 * @retval This method returns the number of seconds since epoch represented
364 *         by @a the_tod
365 */
366Watchdog_Interval _TOD_To_seconds(
367  const rtems_time_of_day *the_tod
368);
369
370#ifdef __cplusplus
371}
372#endif
373
374/**@}*/
375
376#endif
377/* end of include file */
Note: See TracBrowser for help on using the repository browser.