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

4.104.114.84.95
Last change on this file since ac7d5ef0 was ac7d5ef0, checked in by Joel Sherrill <joel.sherrill@…>, on 05/11/95 at 17:39:37

Initial revision

  • Property mode set to 100644
File size: 6.8 KB
Line 
1/*  tod.h
2 *
3 *  This include file contains all the constants and structures associated
4 *  with the Time of Day Handler.
5 *
6 *  COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
7 *  On-Line Applications Research Corporation (OAR).
8 *  All rights assigned to U.S. Government, 1994.
9 *
10 *  This material may be reproduced by or for the U.S. Government pursuant
11 *  to the copyright license under the clause at DFARS 252.227-7013.  This
12 *  notice must appear in all copies of this file and its derivatives.
13 *
14 *  $Id$
15 */
16
17#ifndef __RTEMS_TIME_OF_DAY_h
18#define __RTEMS_TIME_OF_DAY_h
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24#include <rtems/object.h>
25#include <rtems/watchdog.h>
26
27/*
28 *  The following constants are related to the time of day.
29 */
30
31#define TOD_SECONDS_PER_MINUTE 60
32#define TOD_MINUTES_PER_HOUR   60
33#define TOD_MONTHS_PER_YEAR    12
34#define TOD_DAYS_PER_YEAR      365
35#define TOD_HOURS_PER_DAY      24
36#define TOD_SECONDS_PER_DAY    (TOD_SECONDS_PER_MINUTE * \
37                                TOD_MINUTES_PER_HOUR   * \
38                                TOD_HOURS_PER_DAY)
39
40#define TOD_MICROSECONDS_PER_SECOND 1000000
41#define TOD_MILLISECONDS_PER_SECOND 1000
42
43/*
44 *  The following constant define the earliest year to which an
45 *  RTEMS time of day can be initialized.  This is considered the
46 *  epoch.
47 */
48
49#define TOD_BASE_YEAR 1988
50
51/*
52 *  The following record defines the time of control block.  This
53 *  control block is used to maintain the current time of day.
54 */
55
56typedef struct {                   /* RTEID style time/date */
57  unsigned32 year;                 /* year, A.D. */
58  unsigned32 month;                /* month, 1 -> 12 */
59  unsigned32 day;                  /* day, 1 -> 31 */
60  unsigned32 hour;                 /* hour, 0 -> 23 */
61  unsigned32 minute;               /* minute, 0 -> 59 */
62  unsigned32 second;               /* second, 0 -> 59 */
63  unsigned32 ticks;                /* elapsed ticks between secs */
64}   rtems_time_of_day;
65
66/*
67 *  The following contains the current time of day.
68 */
69
70EXTERN rtems_time_of_day _TOD_Current;
71
72/*
73 *  The following contains the number of seconds from 00:00:00
74 *  January 1, TOD_BASE_YEAR until the current time of day.
75 */
76
77EXTERN rtems_interval _TOD_Seconds_since_epoch;
78
79/*
80 *  The following contains the number of ticks since the
81 *  system was booted.
82 */
83
84EXTERN rtems_interval _TOD_Ticks_since_boot;
85
86/*
87 *  The following contains the number of microseconds per tick.
88 */
89
90EXTERN unsigned32 _TOD_Microseconds_per_tick;
91
92/*
93 *  The following contains the number of clock ticks per second.
94 *
95 *  NOTE:
96 *
97 *  If one second is NOT evenly divisible by the number of microseconds
98 *  per clock tick, this value will contain only the integer portion
99 *  of the division.  This means that the interval between clock ticks
100 *  can be a source of error in the current time of day.
101 */
102
103EXTERN unsigned32 _TOD_Ticks_per_second;
104
105/*
106 *  This is the control structure for the watchdog timer which
107 *  fires to service the seconds chain.
108 */
109
110EXTERN Watchdog_Control _TOD_Seconds_watchdog;
111
112#ifdef INIT
113
114/*
115 *  The following array contains the number of days in all months.
116 *  The first dimension should be 1 for leap years, and 0 otherwise.
117 *  The second dimension should range from 1 to 12 for January to
118 *  February, respectively.
119 */
120
121const unsigned32 _TOD_Days_per_month[ 2 ][ 13 ] = {
122  { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
123  { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
124};
125
126/*
127 *  The following array contains the number of days in all months
128 *  up to the month indicated by the index of the second dimension.
129 *  The first dimension should be 1 for leap years, and 0 otherwise.
130 */
131
132const unsigned16 _TOD_Days_to_date[2][13] = {
133  { 0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 },
134  { 0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 }
135};
136
137/*
138 *  The following array contains the number of days in the years
139 *  since the last leap year.  The index should be 0 for leap
140 *  years, and the number of years since the beginning of a leap
141 *  year otherwise.
142 */
143
144const unsigned16 _TOD_Days_since_last_leap_year[4] = { 0, 366, 761, 1126 };
145
146#else
147
148extern const unsigned16 _TOD_Days_to_date[2][13]; /* Julian days */
149extern const unsigned16 _TOD_Days_since_last_leap_year[4];
150extern const unsigned32 _TOD_Days_per_month[2][13];
151
152#endif
153
154/*
155 *  _TOD_Handler_initialization
156 *
157 *  DESCRIPTION:
158 *
159 *  This routine performs the initialization necessary for this handler.
160 */
161
162void _TOD_Handler_initialization(
163  unsigned32 microseconds_per_tick
164);
165
166/*
167 *  _TOD_Set
168 *
169 *  DESCRIPTION:
170 *
171 *  This routine sets the current time of day to THE_TOD and
172 *  the equivalent SECONDS_SINCE_EPOCH.
173 */
174
175void _TOD_Set(
176  rtems_time_of_day       *the_tod,
177  rtems_interval  seconds_since_epoch
178);
179
180/*
181 *  _TOD_Validate
182 *
183 *  DESCRIPTION:
184 *
185 *  This function returns STATUS.RTEMS_SUCCESSFUL if THE_TOD contains
186 *  a valid time of day, and FALSE otherwise.
187 */
188
189rtems_status_code _TOD_Validate(
190  rtems_time_of_day *the_tod
191);
192
193/*
194 *  _TOD_To_seconds
195 *
196 *  DESCRIPTION:
197 *
198 *  This function returns the number seconds between the epoch and THE_TOD.
199 */
200
201rtems_interval _TOD_To_seconds(
202  rtems_time_of_day *the_tod
203);
204
205/*
206 *  _TOD_Is_set
207 *
208 *  DESCRIPTION:
209 *
210 *  This function returns TRUE if the application has set the current
211 *  time of day, and FALSE otherwise.
212 */
213
214STATIC INLINE boolean _TOD_Is_set( void );
215
216/*
217 *  _TOD_Tickle_ticks
218 *
219 *  DESCRIPTION:
220 *
221 *  This routine increments the ticks field of the current time of
222 *  day at each clock tick.
223 */
224
225STATIC INLINE void _TOD_Tickle_ticks( void );
226
227/*
228 *  _TOD_Deactivate
229 *
230 *  DESCRIPTION:
231 *
232 *  This routine deactivates updating of the current time of day.
233 */
234
235STATIC INLINE void _TOD_Deactivate( void );
236
237/*
238 *  _TOD_Activate
239 *
240 *  DESCRIPTION:
241 *
242 *  This routine deactivates updating of the current time of day.
243 */
244
245STATIC INLINE void _TOD_Activate(
246  rtems_interval ticks
247);
248
249/*
250 *  _TOD_Tickle
251 *
252 *  DESCRIPTION:
253 *
254 *  This routine is scheduled as a watchdog function and is invoked at
255 *  each second boundary.  It updates the current time of day to indicate
256 *  that a second has passed and processes the seconds watchdog chain.
257 */
258
259void _TOD_Tickle(
260  Objects_Id  id,
261  void       *ignored
262);
263
264/*
265 *  RTEMS_MILLISECONDS_TO_MICROSECONDS
266 *
267 *  DESCRIPTION:
268 *
269 *  This routine converts an interval expressed in milliseconds to microseconds.
270 *
271 *  NOTE:
272 *
273 *  This must be a macro so it can be used in "static" tables.
274 */
275
276#define RTEMS_MILLISECONDS_TO_MICROSECONDS(_ms) ((_ms) * 1000)
277
278/*
279 *  RTEMS_MILLISECONDS_TO_TICKS
280 *
281 *  DESCRIPTION:
282 *
283 *  This routine converts an interval expressed in milliseconds to ticks.
284 *
285 *  NOTE:
286 *
287 *  This must be a macro so it can be used in "static" tables.
288 */
289
290#define RTEMS_MILLISECONDS_TO_TICKS(_ms) \
291    (RTEMS_MILLISECONDS_TO_MICROSECONDS(_ms) / _TOD_Microseconds_per_tick)
292
293#include <rtems/tod.inl>
294
295#ifdef __cplusplus
296}
297#endif
298
299#endif
300/* end of include file */
Note: See TracBrowser for help on using the repository browser.