source: rtems/cpukit/rtems/include/rtems/rtems/clock.h @ 997bc7f4

4.104.115
Last change on this file since 997bc7f4 was 997bc7f4, checked in by Ralf Corsepius <ralf.corsepius@…>, on 12/23/08 at 05:06:37

Eliminate TRUE/FALSE.

  • 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 *  $Id$
25 */
26
27#ifndef _RTEMS_RTEMS_CLOCK_H
28#define _RTEMS_RTEMS_CLOCK_H
29
30#include <rtems/score/tod.h>
31#include <rtems/score/watchdog.h>
32#include <rtems/rtems/status.h>
33#include <rtems/rtems/types.h>
34
35#include <sys/time.h> /* struct timeval */
36
37/**
38 *  @defgroup ClassicClock Classic API Clock
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 *  Standard flavor style to return TOD in for a rtems_clock_get option.
66 */
67typedef struct {
68  /** This is the seconds portion of a time of day. */
69  uint32_t    seconds;
70  /** This is the microseconds portion of a time of day. */
71  uint32_t    microseconds;
72} rtems_clock_time_value;
73
74/**
75 *  Type for the nanoseconds since last tick BSP extension.
76 */
77typedef Watchdog_Nanoseconds_since_last_tick_routine
78  rtems_nanoseconds_extension_routine;
79
80/**
81 *  @brief Obtain Current Time of Day
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 *  @return 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);
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 *  @param[in] time_buffer points to the time of day structure
109 *
110 *  @return This method returns RTEMS_SUCCESSFUL if there was not an
111 *          error.  Otherwise, a status code is returned indicating the
112 *          source of the error.  If successful, the time_buffer will
113 *          be filled in with the current time of day.
114 */
115rtems_status_code rtems_clock_get_tod(
116  rtems_time_of_day *time_buffer
117);
118
119/**
120 *  @brief Obtain TOD in struct timeval Format
121 *
122 *  This routine implements the rtems_clock_get_tod_timeval
123 *  directive.
124 *
125 *  @param[in] time points to the struct timeval variable to fill in
126 *
127 *  @return This method returns RTEMS_SUCCESSFUL if there was not an
128 *          error.  Otherwise, a status code is returned indicating the
129 *          source of the error.  If successful, the time will
130 *          be filled in with the current time of day.
131 */
132rtems_status_code rtems_clock_get_tod_timeval(
133  struct timeval *time
134);
135
136/**
137 *  @brief Obtain Seconds Since Epoch
138 *
139 *  This routine implements the rtems_clock_get_seconds_since_epoch
140 *  directive.
141 *
142 *  @param[in] the_interval points to the interval variable to fill in
143 *
144 *  @return This method returns RTEMS_SUCCESSFUL if there was not an
145 *          error.  Otherwise, a status code is returned indicating the
146 *          source of the error.  If successful, the time_buffer will
147 *          be filled in with the current time of day.
148 */
149rtems_status_code rtems_clock_get_seconds_since_epoch(
150  rtems_interval *the_interval
151);
152
153/**
154 *  @brief Obtain Ticks Since Boot
155 *
156 *  This routine implements the rtems_clock_get_ticks_since_boot
157 *  directive.
158 *
159 *  @return This method returns the number of ticks since boot.  It cannot
160 *          fail since RTEMS always keeps a running count of ticks since boot.
161 */
162rtems_interval rtems_clock_get_ticks_since_boot(void);
163
164/**
165 *  @brief Obtain Ticks Per Seconds
166 *
167 *  This routine implements the rtems_clock_get_ticks_per_second
168 *  directive.
169 *
170 *  @return This method returns the number of ticks since boot.  It cannot
171 *          fail since RTEMS is always configured to know the number of
172 *          ticks per second.
173 */
174rtems_interval rtems_clock_get_ticks_per_second(void);
175
176/**
177 *  @brief Set the Current TOD
178 *
179 *  This routine implements the rtems_clock_set directive.  It sets
180 *  the current time of day to that in the time_buffer record.
181 *
182 *  @param[in] time_buffer points to the new TOD
183 *
184 *  @return This method returns RTEMS_SUCCESSFUL if there was not an
185 *          error.  Otherwise, a status code is returned indicating the
186 *          source of the error.
187 *
188 *  @note Activities scheduled based upon the current time of day
189 *        may be executed immediately if the time is moved forward.
190 */
191rtems_status_code rtems_clock_set(
192  rtems_time_of_day *time_buffer
193);
194
195/**
196 *  @brief Announce a Clock Tick
197 *
198 *  This routine implements the rtems_clock_tick directive.  It is invoked
199 *  to inform RTEMS of the occurrence of a clock tick.
200 *
201 *  @return This directive always returns RTEMS_SUCCESSFUL.
202 *
203 *  @note This method is typically called from an ISR and is the basis
204 *        for all timeouts and delays.
205 */
206rtems_status_code rtems_clock_tick( void );
207
208/**
209 *  @brief Set the BSP specific Nanoseconds Extension
210 *
211 *  This directive sets the BSP provided nanoseconds since last tick
212 *  extension.
213 *
214 *  @param[in] routine is a pointer to the extension routine
215 *
216 *  @return This method returns RTEMS_SUCCESSFUL if there was not an
217 *          error.  Otherwise, a status code is returned indicating the
218 *          source of the error.
219 */
220rtems_status_code rtems_clock_set_nanoseconds_extension(
221  rtems_nanoseconds_extension_routine routine
222);
223
224/**
225 *  @brief Obtain the System Uptime
226 *
227 *  This directive returns the system uptime.
228 *
229 *  @param[in] uptime is a pointer to the time structure
230 *
231 *  @return This method returns RTEMS_SUCCESSFUL if there was not an
232 *          error.  Otherwise, a status code is returned indicating the
233 *          source of the error.  If successful, the uptime will be
234 *          filled in.
235 */
236rtems_status_code rtems_clock_get_uptime(
237  struct timespec *uptime
238);
239
240/**
241 *  @brief _TOD_Validate
242 *
243 *  This support function returns true if @a the_tod contains
244 *  a valid time of day, and false otherwise.
245 *
246 *  @param[in] the_tod is the TOD structure to validate
247 *
248 *  @return This method returns true if the TOD is valid and false otherwise.
249 */
250bool _TOD_Validate(
251  rtems_time_of_day *the_tod
252);
253
254/**
255 *  @brief _TOD_To_seconds
256 *
257 *  This function returns the number seconds between the epoch and @a the_tod.
258 *
259 *  @param[in] the_tod is the TOD structure to convert to seconds
260 *
261 *  @return This method returns the number of seconds since epoch represented
262 *          by @a the_tod
263 */
264Watchdog_Interval _TOD_To_seconds(
265  rtems_time_of_day *the_tod
266);
267
268#ifdef __cplusplus
269}
270#endif
271
272/**@}*/
273
274#endif
275/* end of include file */
Note: See TracBrowser for help on using the repository browser.