source: rtems/cpukit/score/include/rtems/score/tod.h @ 7cb170b3

4.115
Last change on this file since 7cb170b3 was 8d7aea0d, checked in by Sebastian Huber <sebastian.huber@…>, on 09/29/11 at 09:55:54

2011-09-29 Sebastian Huber <sebastian.huber@…>

  • score/include/rtems/score/tod.h: Declare _TOD_Set_with_timestamp() and _TOD_Get_as_timestamp().
  • score/src/coretodset.c: Define _TOD_Set_with_timestamp().
  • score/src/coretodget.c: Define _TOD_Get_as_timestamp().
  • rtems/src/clockset.c: Use _TOD_Set_with_timestamp().
  • score/include/rtems/score/timestamp64.h, score/src/ts64set.c: Changed parameter types of _Timestamp64_Set().
  • rtems/src/clocktodtoseconds.c: Year 2100 is not a leap year.
  • Property mode set to 100644
File size: 7.0 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 *  $Id$
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 RTEMS Epoch Year
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 Is the Time Of Day Set
129 *
130 *  This is true if the application has set the current
131 *  time of day, and false otherwise.
132 */
133SCORE_EXTERN bool _TOD_Is_set;
134
135/**
136 *  @brief Current Time of Day (Timespec)
137 *
138 *  The following contains the current time of day.
139 */
140SCORE_EXTERN Timestamp_Control _TOD_Now;
141
142/**
143 *  @brief Current Time of Day (Timespec)
144 *
145 *  The following contains the running uptime.
146 */
147SCORE_EXTERN Timestamp_Control _TOD_Uptime;
148
149/**
150 *  @brief Seconds Since RTEMS Epoch
151 *
152 *  The following contains the number of seconds from 00:00:00
153 *  January 1, TOD_BASE_YEAR until the current time of day.
154 */
155#define _TOD_Seconds_since_epoch() \
156  _Timestamp_Get_seconds(&_TOD_Now)
157
158/**
159 *  @brief _TOD_Handler_initialization
160 *
161 *  This routine performs the initialization necessary for this handler.
162 */
163void _TOD_Handler_initialization(void);
164
165/**
166 *  @brief Sets the time of day according to @a tod_as_timestamp.
167 *
168 *  The @a tod_as_timestamp timestamp represents the time since UNIX epoch.  The watchdog
169 *  seconds chain will be adjusted.
170 */
171void _TOD_Set_with_timestamp(
172  const Timestamp_Control *tod_as_timestamp
173);
174
175static inline void _TOD_Set(
176  const struct timespec *tod_as_timespec
177)
178{
179  Timestamp_Control tod_as_timestamp;
180
181  _Timestamp_Set(
182    &tod_as_timestamp,
183    tod_as_timespec->tv_sec,
184    tod_as_timespec->tv_nsec
185  );
186  _TOD_Set_with_timestamp( &tod_as_timestamp );
187}
188
189/**
190 *  @brief Returns the time of day in @a tod_as_timestamp.
191 *
192 *  The @a tod_as_timestamp timestamp represents the time since UNIX epoch.
193 */
194void _TOD_Get_as_timestamp(
195  Timestamp_Control *tod_as_timestamp
196);
197
198static inline void _TOD_Get(
199  struct timespec *tod_as_timespec
200)
201{
202  Timestamp_Control tod_as_timestamp;
203
204  _TOD_Get_as_timestamp( &tod_as_timestamp );
205  _Timestamp_To_timespec( &tod_as_timestamp, tod_as_timespec );
206}
207
208/**
209 *  @brief _TOD_Get_uptime
210 *
211 *  This routine returns the system uptime with potential accuracy
212 *  to the nanosecond.
213 *
214 *  @param[in] time is a pointer to the uptime to be returned
215 */
216void _TOD_Get_uptime(
217  Timestamp_Control *time
218);
219
220/**
221 *  @brief _TOD_Get_uptime_as_timespec
222 *
223 *  This routine returns the system uptime with potential accuracy
224 *  to the nanosecond.
225 *
226 *  @param[in] time is a pointer to the uptime to be returned
227 */
228void _TOD_Get_uptime_as_timespec(
229  struct timespec *time
230);
231
232/**
233 *  This routine increments the ticks field of the current time of
234 *  day at each clock tick.
235 */
236void _TOD_Tickle_ticks( void );
237
238/**
239 *  @brief TOD_MILLISECONDS_TO_MICROSECONDS
240 *
241 *  This routine converts an interval expressed in milliseconds to microseconds.
242 *
243 *  @note This must be a macro so it can be used in "static" tables.
244 */
245#define TOD_MILLISECONDS_TO_MICROSECONDS(_ms) ((uint32_t)(_ms) * 1000L)
246
247/**
248 *  @brief TOD_MICROSECONDS_TO_TICKS
249 *
250 *  This routine converts an interval expressed in microseconds to ticks.
251 *
252 *  @note This must be a macro so it can be used in "static" tables.
253 */
254uint32_t TOD_MICROSECONDS_TO_TICKS(
255  uint32_t microseconds
256);
257
258/**
259 *  @brief TOD_MILLISECONDS_TO_TICKS
260 *
261 *  This routine converts an interval expressed in milliseconds to ticks.
262 *
263 *  @note This must be a macro so it can be used in "static" tables.
264 */
265uint32_t TOD_MILLISECONDS_TO_TICKS(
266  uint32_t milliseconds
267);
268
269/**
270 *  @brief How many ticks in a second?
271 *
272 *  This method returns the number of ticks in a second.
273 *
274 *  @note If the clock tick value does not multiply evenly into a second
275 *        then this number of ticks will be slightly shorter than a second.
276 */
277uint32_t TOD_TICKS_PER_SECOND_method(void);
278
279/**
280 *  @brief Method to return number of ticks in a second
281 *
282 *  This method exists to hide the fact that TOD_TICKS_PER_SECOND can not
283 *  be implemented as a macro in a .h file due to visibility issues.
284 *  The Configuration Table is not available to SuperCore .h files but
285 *  is available to their .c files.
286 */
287#define TOD_TICKS_PER_SECOND TOD_TICKS_PER_SECOND_method()
288
289#ifndef __RTEMS_APPLICATION__
290#include <rtems/score/tod.inl>
291#endif
292
293#ifdef __cplusplus
294}
295#endif
296
297/**@}*/
298
299#endif
300/* end of include file */
Note: See TracBrowser for help on using the repository browser.