source: rtems/cpukit/score/include/rtems/score/tod.h @ a2e3f33

4.115
Last change on this file since a2e3f33 was e858f70, checked in by Joel Sherrill <joel.sherrill@…>, on 01/10/13 at 23:06:06

cpukit: Fix many Doxygen warnings

  • Property mode set to 100644
File size: 8.0 KB
Line 
1/**
2 *  @file  rtems/score/tod.h
3 *
4 *  @brief Constants and Structures Associated with the Time of Day Handler.
5 *
6 *  This include file contains all the constants and structures associated
7 *  with the Time of Day Handler.
8 */
9
10/*
11 *  COPYRIGHT (c) 1989-2009.
12 *  On-Line Applications Research Corporation (OAR).
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.rtems.com/license/LICENSE.
17 */
18
19#ifndef _RTEMS_SCORE_TOD_H
20#define _RTEMS_SCORE_TOD_H
21
22#include <time.h>
23#include <rtems/score/timestamp.h>
24#include <rtems/score/basedefs.h> /* SCORE_EXTERN */
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30/**
31 *  @defgroup ScoreTODConstants TOD Constants
32 *
33 *  @ingroup Score
34 *
35 *  The following constants are related to the time of day and are
36 *  independent of RTEMS.
37 */
38/**@{*/
39
40/**
41 *  This constant represents the number of seconds in a minute.
42 */
43#define TOD_SECONDS_PER_MINUTE (uint32_t)60
44
45/**
46 *  This constant represents the number of minutes per hour.
47 */
48#define TOD_MINUTES_PER_HOUR   (uint32_t)60
49
50/**
51 *  This constant represents the number of months in a year.
52 */
53#define TOD_MONTHS_PER_YEAR    (uint32_t)12
54
55/**
56 *  This constant represents the number of days in a non-leap year.
57 */
58#define TOD_DAYS_PER_YEAR      (uint32_t)365
59
60/**
61 *  This constant represents the number of hours per day.
62 */
63#define TOD_HOURS_PER_DAY      (uint32_t)24
64
65/**
66 *  This constant represents the number of seconds in a day which does
67 *  not include a leap second.
68 */
69#define TOD_SECONDS_PER_DAY    (uint32_t) (TOD_SECONDS_PER_MINUTE * \
70                                TOD_MINUTES_PER_HOUR   * \
71                                TOD_HOURS_PER_DAY)
72
73/**
74 *  This constant represents the number of seconds in a non-leap year.
75 */
76#define TOD_SECONDS_PER_NON_LEAP_YEAR (365 * TOD_SECONDS_PER_DAY)
77
78/**
79 *  This constant represents the number of millisecond in a second.
80 */
81#define TOD_MILLISECONDS_PER_SECOND     (uint32_t)1000
82
83/**
84 *  This constant represents the number of microseconds in a second.
85 */
86#define TOD_MICROSECONDS_PER_SECOND     (uint32_t)1000000
87
88/**
89 *  This constant represents the number of nanoseconds in a second.
90 */
91#define TOD_NANOSECONDS_PER_SECOND      (uint32_t)1000000000
92
93/**
94 *  This constant represents the number of nanoseconds in a mircosecond.
95 */
96#define TOD_NANOSECONDS_PER_MICROSECOND (uint32_t)1000
97
98/**@}*/
99
100/**
101 *  Seconds from January 1, 1970 to January 1, 1988.  Used to account for
102 *  differences between POSIX API and RTEMS core. The timespec format time
103 *  is kept in POSIX compliant form.
104 */
105#define TOD_SECONDS_1970_THROUGH_1988 \
106  (((1987 - 1970 + 1)  * TOD_SECONDS_PER_NON_LEAP_YEAR) + \
107  (4 * TOD_SECONDS_PER_DAY))
108
109/**
110 *  @brief Earliest year to which an time of day can be initialized.
111 *
112 *  The following constant define the earliest year to which an
113 *  time of day can be initialized.  This is considered the
114 *  epoch.
115 */
116#define TOD_BASE_YEAR 1988
117
118/**
119 *  @defgroup ScoreTOD Time Of Day (TOD) Handler
120 *
121 *  @ingroup Score
122 *
123 *  This handler encapsulates functionality used to manage time of day.
124 */
125/**@{*/
126
127/**
128 *  @brief TOD control.
129 */
130typedef struct {
131  /**
132   *  @brief Current time of day value.
133   */
134  Timestamp_Control now;
135
136  /**
137   *  @brief System uptime.
138   */
139  Timestamp_Control uptime;
140
141  /**
142   * @brief Time of day seconds trigger.
143   *
144   * This value specifies the nanoseconds since the last time of day second.
145   * It is updated and evaluated in _TOD_Tickle_ticks().  It is set in
146   * _TOD_Set_with_timestamp().
147   */
148  uint32_t seconds_trigger;
149
150  /**
151   *  @brief Indicates if the time of day is set.
152   *
153   *  This is true if the application has set the current
154   *  time of day, and false otherwise.
155   */
156  bool is_set;
157} TOD_Control;
158
159SCORE_EXTERN TOD_Control _TOD;
160
161/**
162 *  @brief Number of seconds Since RTEMS epoch.
163 *
164 *  The following contains the number of seconds from 00:00:00
165 *  January 1, TOD_BASE_YEAR until the current time of day.
166 */
167#define _TOD_Seconds_since_epoch() \
168  _Timestamp_Get_seconds(&_TOD.now)
169
170/**
171 *  @brief Initializes the time of day handler.
172 *
173 *  Performs the initialization necessary for the Time Of Day handler.
174 */
175void _TOD_Handler_initialization(void);
176
177/**
178 *  @brief Sets the time of day from timestamp.
179 *
180 *  The @a tod_as_timestamp timestamp represents the time since UNIX epoch.
181 *  The watchdog seconds chain will be adjusted.
182 *
183 *  @param[in] tod_as_timestamp is the constant of the time of day as a timestamp
184 */
185void _TOD_Set_with_timestamp(
186  const Timestamp_Control *tod_as_timestamp
187);
188
189static inline void _TOD_Set(
190  const struct timespec *tod_as_timespec
191)
192{
193  Timestamp_Control tod_as_timestamp;
194
195  _Timestamp_Set(
196    &tod_as_timestamp,
197    tod_as_timespec->tv_sec,
198    tod_as_timespec->tv_nsec
199  );
200  _TOD_Set_with_timestamp( &tod_as_timestamp );
201}
202
203/**
204 *  @brief Returns a snapshot of a clock.
205 *
206 *  This function invokes the nanoseconds extension.
207 *
208 *  @param[out] snapshot points to an area that will contain the current
209 *              TOD plus the BSP nanoseconds since last tick adjustment
210 *  @param[in] clock contains the current TOD
211 *
212 *  @retval @a snapshot
213 */
214Timestamp_Control *_TOD_Get_with_nanoseconds(
215  Timestamp_Control *snapshot,
216  const Timestamp_Control *clock
217);
218
219static inline void _TOD_Get(
220  struct timespec *tod_as_timespec
221)
222{
223  Timestamp_Control  tod_as_timestamp;
224  Timestamp_Control *tod_as_timestamp_ptr;
225
226  tod_as_timestamp_ptr =
227    _TOD_Get_with_nanoseconds( &tod_as_timestamp, &_TOD.now );
228  _Timestamp_To_timespec( tod_as_timestamp_ptr, tod_as_timespec );
229}
230
231/**
232 *  @brief Gets the system uptime with potential accuracy to the nanosecond.
233 *
234 *  This routine returns the system uptime with potential accuracy
235 *  to the nanosecond.
236 *
237 *  @param[in] time is a pointer to the uptime to be returned
238 */
239static inline void _TOD_Get_uptime(
240  Timestamp_Control *time
241)
242{
243  _TOD_Get_with_nanoseconds( time, &_TOD.uptime );
244}
245
246/**
247 *  @brief Gets the system uptime with potential accuracy to the nanosecond.
248 *
249 *  This routine returns the system uptime with potential accuracy
250 *  to the nanosecond.
251 *
252 *  @param[in] time is a pointer to the uptime to be returned
253 */
254void _TOD_Get_uptime_as_timespec(
255  struct timespec *time
256);
257
258/**
259 *  @brief Increments time of day at each clock tick.
260 *
261 *  This routine increments the ticks field of the current time of
262 *  day at each clock tick.
263 */
264void _TOD_Tickle_ticks( void );
265
266/**
267 *  @brief Converts an interval expressed in milliseconds to microseconds.
268 *
269 *  This routine converts an interval expressed in milliseconds to microseconds.
270 *
271 *  @note This must be a macro so it can be used in "static" tables.
272 */
273#define TOD_MILLISECONDS_TO_MICROSECONDS(_ms) ((uint32_t)(_ms) * 1000L)
274
275/**
276 *  @brief Converts an interval expressed in microseconds to ticks.
277 *
278 *  This routine converts an interval expressed in microseconds to ticks.
279 *
280 *  @note This must be a macro so it can be used in "static" tables.
281 */
282uint32_t TOD_MICROSECONDS_TO_TICKS(
283  uint32_t microseconds
284);
285
286/**
287 *  @brief Converts an interval expressed in milliseconds to ticks.
288 *
289 *  This routine converts an interval expressed in milliseconds to ticks.
290 *
291 *  @note This must be a macro so it can be used in "static" tables.
292 */
293uint32_t TOD_MILLISECONDS_TO_TICKS(
294  uint32_t milliseconds
295);
296
297/**
298 *  @brief Gets number of ticks in a second.
299 *
300 *  This method returns the number of ticks in a second.
301 *
302 *  @note If the clock tick value does not multiply evenly into a second
303 *        then this number of ticks will be slightly shorter than a second.
304 */
305uint32_t TOD_TICKS_PER_SECOND_method(void);
306
307/**
308 *  @brief Gets number of ticks in a second.
309 *
310 *  This method exists to hide the fact that TOD_TICKS_PER_SECOND can not
311 *  be implemented as a macro in a .h file due to visibility issues.
312 *  The Configuration Table is not available to SuperCore .h files but
313 *  is available to their .c files.
314 */
315#define TOD_TICKS_PER_SECOND TOD_TICKS_PER_SECOND_method()
316
317#ifndef __RTEMS_APPLICATION__
318#include <rtems/score/tod.inl>
319#endif
320
321#ifdef __cplusplus
322}
323#endif
324
325/**@}*/
326
327#endif
328/* end of include file */
Note: See TracBrowser for help on using the repository browser.