source: rtems/cpukit/rtems/include/rtems/rtems/clock.h @ e65c45c

5
Last change on this file since e65c45c was e65c45c, checked in by Joel Sherrill <joel@…>, on 03/22/16 at 22:13:30

Obsolete rtems_clock_get() directive.

This service was marked as deprecated long prior to the 4.11 release
series and is now being removed.

closes #2676.

  • Property mode set to 100644
File size: 8.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 * - announce a clock tick
18 * - obtain the system uptime
19 */
20
21/* COPYRIGHT (c) 1989-2013.
22 * On-Line Applications Research Corporation (OAR).
23 *
24 * The license and distribution terms for this file may be
25 * found in the file LICENSE in this distribution or at
26 * http://www.rtems.org/license/LICENSE.
27 */
28
29#ifndef _RTEMS_RTEMS_CLOCK_H
30#define _RTEMS_RTEMS_CLOCK_H
31
32#include <rtems/score/watchdog.h>
33#include <rtems/score/tod.h>
34#include <rtems/rtems/status.h>
35#include <rtems/rtems/types.h>
36#include <rtems/config.h>
37#include <rtems/score/timecounterimpl.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 * @brief Obtain Current Time of Day (Classic TOD)
57 *
58 * This routine implements the rtems_clock_get_tod directive. It returns
59 * the current time of day in the format defined by RTEID.
60 *
61 * Clock Manager - rtems_clock_get_tod
62 *
63 * @param[in] time_buffer points to the time of day structure
64 *
65 * @retval This method returns RTEMS_SUCCESSFUL if there was not an
66 *         error. Otherwise, a status code is returned indicating the
67 *         source of the error. If successful, the time_buffer will
68 *         be filled in with the current time of day.
69 */
70rtems_status_code rtems_clock_get_tod(
71  rtems_time_of_day *time_buffer
72);
73
74/**
75 * @brief Obtain TOD in struct timeval Format
76 *
77 * This routine implements the rtems_clock_get_tod_timeval
78 * directive.
79 *
80 * @param[in] time points to the struct timeval variable to fill in
81 *
82 * @retval This method returns RTEMS_SUCCESSFUL if there was not an
83 *         error. Otherwise, a status code is returned indicating the
84 *         source of the error. If successful, the time will
85 *         be filled in with the current time of day.
86 */
87rtems_status_code rtems_clock_get_tod_timeval(
88  struct timeval *time
89);
90
91/**
92 * @brief Obtain Seconds Since Epoch
93 *
94 * This routine implements the rtems_clock_get_seconds_since_epoch
95 * directive.
96 *
97 * @param[in] the_interval points to the interval variable to fill in
98 *
99 * @retval This method returns RTEMS_SUCCESSFUL if there was not an
100 *         error. Otherwise, a status code is returned indicating the
101 *         source of the error. If successful, the time_buffer will
102 *         be filled in with the current time of day.
103 */
104rtems_status_code rtems_clock_get_seconds_since_epoch(
105  rtems_interval *the_interval
106);
107
108/**
109 * @brief Gets the current ticks counter value.
110 *
111 * @return The current tick counter value.  With a 1ms clock tick, this counter
112 * overflows after 50 days since boot.
113 */
114RTEMS_INLINE_ROUTINE rtems_interval rtems_clock_get_ticks_since_boot(void)
115{
116  return _Watchdog_Ticks_since_boot;
117}
118
119/**
120 * @brief Returns the ticks counter value delta ticks in the future.
121 *
122 * @param[in] delta The ticks delta value.
123 *
124 * @return The tick counter value delta ticks in the future.
125 */
126RTEMS_INLINE_ROUTINE rtems_interval rtems_clock_tick_later(
127  rtems_interval delta
128)
129{
130  return _Watchdog_Ticks_since_boot + delta;
131}
132
133/**
134 * @brief Returns the ticks counter value at least delta microseconds in the
135 * future.
136 *
137 * @param[in] delta_in_usec The delta value in microseconds.
138 *
139 * @return The tick counter value at least delta microseconds in the future.
140 */
141RTEMS_INLINE_ROUTINE rtems_interval rtems_clock_tick_later_usec(
142  rtems_interval delta_in_usec
143)
144{
145  rtems_interval us_per_tick = rtems_configuration_get_microseconds_per_tick();
146
147  /*
148   * Add one additional tick, since we don't know the time to the clock next
149   * tick.
150   */
151  return _Watchdog_Ticks_since_boot
152    + (delta_in_usec + us_per_tick - 1) / us_per_tick + 1;
153}
154
155/**
156 * @brief Returns true if the current ticks counter value indicates a time
157 * before the time specified by the tick value and false otherwise.
158 *
159 * @param[in] tick The tick value.
160 *
161 * This can be used to write busy loops with a timeout.
162 *
163 * @code
164 * status busy( void )
165 * {
166 *   rtems_interval timeout = rtems_clock_tick_later_usec( 10000 );
167 *
168 *   do {
169 *     if ( ok() ) {
170 *       return success;
171 *     }
172 *   } while ( rtems_clock_tick_before( timeout ) );
173 *
174 *   return timeout;
175 * }
176 * @endcode
177 *
178 * @retval true The current ticks counter value indicates a time before the
179 * time specified by the tick value.
180 * @retval false Otherwise.
181 */
182RTEMS_INLINE_ROUTINE bool rtems_clock_tick_before(
183  rtems_interval tick
184)
185{
186  return (int32_t) ( tick - _Watchdog_Ticks_since_boot ) > 0;
187}
188
189/**
190 * @brief Obtain Ticks Per Seconds
191 *
192 * This routine implements the rtems_clock_get_ticks_per_second
193 * directive.
194 *
195 * @retval This method returns the number of ticks per second. It cannot
196 *         fail since RTEMS is always configured to know the number of
197 *         ticks per second.
198 */
199rtems_interval rtems_clock_get_ticks_per_second(void);
200
201/**
202 * @brief Set the Current TOD
203 *
204 * This routine implements the rtems_clock_set directive. It sets
205 * the current time of day to that in the time_buffer record.
206 *
207 * @param[in] time_buffer points to the new TOD
208 *
209 * @retval This method returns RTEMS_SUCCESSFUL if there was not an
210 *         error. Otherwise, a status code is returned indicating the
211 *         source of the error.
212 *
213 * @note Activities scheduled based upon the current time of day
214 *       may be executed immediately if the time is moved forward.
215 */
216rtems_status_code rtems_clock_set(
217  const rtems_time_of_day *time_buffer
218);
219
220/**
221 * @brief Announce a Clock Tick
222 *
223 * This routine implements the rtems_clock_tick directive. It is invoked
224 * to inform RTEMS of the occurrence of a clock tick.
225 *
226 * @retval This directive always returns RTEMS_SUCCESSFUL.
227 *
228 * @note This method is typically called from an ISR and is the basis
229 *       for all timeouts and delays. This routine only works for leap-years
230 *       through 2099.
231 */
232rtems_status_code rtems_clock_tick( void );
233
234/**
235 * @brief Obtain the System Uptime
236 *
237 * This directive returns the system uptime.
238 *
239 * @param[in] uptime is a pointer to the time structure
240 *
241 * @retval This method returns RTEMS_SUCCESSFUL if there was not an
242 *         error. Otherwise, a status code is returned indicating the
243 *         source of the error. If successful, the @a uptime will be
244 *         filled in.
245 */
246rtems_status_code rtems_clock_get_uptime(
247  struct timespec *uptime
248);
249
250/**
251 * @brief Gets the System Uptime in the Struct Timeval Format
252 *
253 * @param[out] uptime is a pointer to a struct timeval structure.
254 *
255 * @retval This methods returns the system uptime.
256 *
257 * @note Pointer must not be NULL.
258 */
259void rtems_clock_get_uptime_timeval( struct timeval *uptime );
260
261/**
262 * @brief Returns the system uptime in seconds.
263 *
264 * @retval The system uptime in seconds.
265 */
266RTEMS_INLINE_ROUTINE time_t rtems_clock_get_uptime_seconds( void )
267{
268  return _Timecounter_Time_uptime - 1;
269}
270
271/**
272 * @brief Returns the system uptime in nanoseconds.
273 *
274 * @retval The system uptime in nanoseconds.
275 */
276uint64_t rtems_clock_get_uptime_nanoseconds( void );
277
278/**
279 * @brief TOD Validate
280 *
281 * This support function returns true if @a the_tod contains
282 * a valid time of day, and false otherwise.
283 *
284 * @param[in] the_tod is the TOD structure to validate
285 *
286 * @retval This method returns true if the TOD is valid and false otherwise.
287 *
288 * @note This routine only works for leap-years through 2099.
289 */
290bool _TOD_Validate(
291  const rtems_time_of_day *the_tod
292);
293
294/**
295 * @brief TOD to Seconds
296 *
297 * This function returns the number seconds between the epoch and @a the_tod.
298 *
299 * @param[in] the_tod is the TOD structure to convert to seconds
300 *
301 * @retval This method returns the number of seconds since epoch represented
302 *         by @a the_tod
303 */
304Watchdog_Interval _TOD_To_seconds(
305  const rtems_time_of_day *the_tod
306);
307
308#ifdef __cplusplus
309}
310#endif
311
312/**@}*/
313
314#endif
315/* end of include file */
Note: See TracBrowser for help on using the repository browser.