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

4.11
Last change on this file since b249d7f was b249d7f, checked in by Joel Sherrill <joel.sherrill@…>, on Oct 2, 2012 at 6:23:23 PM

score/tod.h: Fix formatting

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