source: rtems/cpukit/rtems/include/rtems/rtems/clock.h @ 90733a86

4.115
Last change on this file since 90733a86 was 90733a86, checked in by Sebastian Huber <sebastian.huber@…>, on 11/16/12 at 13:14:03

rtems: Add rtems_clock_get_uptime_seconds()

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