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

4.104.114.84.95
Last change on this file since c627b2a3 was c627b2a3, checked in by Joel Sherrill <joel.sherrill@…>, on 05/28/96 at 21:40:52

split the inclusion of "EXTERN" data based on whether it was sapi,
score, rtems api, or posix api related.

  • Property mode set to 100644
File size: 6.2 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 __TIME_OF_DAY_h
18#define __TIME_OF_DAY_h
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24#include <rtems/score/object.h>
25#include <rtems/score/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_SECONDS_PER_NON_LEAP_YEAR (365 * TOD_SECONDS_PER_DAY)
41
42#define TOD_MICROSECONDS_PER_SECOND 1000000
43#define TOD_MILLISECONDS_PER_SECOND 1000
44
45/*
46 *  The following constant define the earliest year to which an
47 *  time of day can be initialized.  This is considered the
48 *  epoch.
49 */
50
51#define TOD_BASE_YEAR 1988
52
53/*
54 *  The following record defines the time of control block.  This
55 *  control block is used to maintain the current time of day.
56 */
57
58typedef struct {                   /* RTEID style time/date */
59  unsigned32 year;                 /* year, A.D. */
60  unsigned32 month;                /* month, 1 -> 12 */
61  unsigned32 day;                  /* day, 1 -> 31 */
62  unsigned32 hour;                 /* hour, 0 -> 23 */
63  unsigned32 minute;               /* minute, 0 -> 59 */
64  unsigned32 second;               /* second, 0 -> 59 */
65  unsigned32 ticks;                /* elapsed ticks between secs */
66}   TOD_Control;
67
68/*
69 *  The following contains the current time of day.
70 */
71
72SCORE_EXTERN TOD_Control _TOD_Current;
73
74/*
75 *  The following contains the number of seconds from 00:00:00
76 *  January 1, TOD_BASE_YEAR until the current time of day.
77 */
78
79SCORE_EXTERN Watchdog_Interval _TOD_Seconds_since_epoch;
80
81/*
82 *  The following contains the number of ticks since the
83 *  system was booted.
84 */
85
86SCORE_EXTERN Watchdog_Interval _TOD_Ticks_since_boot;
87
88/*
89 *  The following contains the number of microseconds per tick.
90 */
91
92SCORE_EXTERN unsigned32 _TOD_Microseconds_per_tick;
93
94/*
95 *  The following contains the number of clock ticks per second.
96 *
97 *  NOTE:
98 *
99 *  If one second is NOT evenly divisible by the number of microseconds
100 *  per clock tick, this value will contain only the integer portion
101 *  of the division.  This means that the interval between clock ticks
102 *  can be a source of error in the current time of day.
103 */
104
105SCORE_EXTERN unsigned32 _TOD_Ticks_per_second;
106
107/*
108 *  This is the control structure for the watchdog timer which
109 *  fires to service the seconds chain.
110 */
111
112SCORE_EXTERN Watchdog_Control _TOD_Seconds_watchdog;
113
114#ifdef SCORE_INIT
115
116/*
117 *  The following array contains the number of days in all months.
118 *  The first dimension should be 1 for leap years, and 0 otherwise.
119 *  The second dimension should range from 1 to 12 for January to
120 *  February, respectively.
121 */
122
123const unsigned32 _TOD_Days_per_month[ 2 ][ 13 ] = {
124  { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
125  { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
126};
127
128/*
129 *  The following array contains the number of days in all months
130 *  up to the month indicated by the index of the second dimension.
131 *  The first dimension should be 1 for leap years, and 0 otherwise.
132 */
133
134const unsigned16 _TOD_Days_to_date[2][13] = {
135  { 0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 },
136  { 0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 }
137};
138
139/*
140 *  The following array contains the number of days in the years
141 *  since the last leap year.  The index should be 0 for leap
142 *  years, and the number of years since the beginning of a leap
143 *  year otherwise.
144 */
145
146const unsigned16 _TOD_Days_since_last_leap_year[4] = { 0, 366, 761, 1126 };
147
148#else
149
150extern const unsigned16 _TOD_Days_to_date[2][13]; /* Julian days */
151extern const unsigned16 _TOD_Days_since_last_leap_year[4];
152extern const unsigned32 _TOD_Days_per_month[2][13];
153
154#endif
155
156/*
157 *  _TOD_Handler_initialization
158 *
159 *  DESCRIPTION:
160 *
161 *  This routine performs the initialization necessary for this handler.
162 */
163
164void _TOD_Handler_initialization(
165  unsigned32 microseconds_per_tick
166);
167
168/*
169 *  _TOD_Set
170 *
171 *  DESCRIPTION:
172 *
173 *  This routine sets the current time of day to THE_TOD and
174 *  the equivalent SECONDS_SINCE_EPOCH.
175 */
176
177void _TOD_Set(
178  TOD_Control       *the_tod,
179  Watchdog_Interval  seconds_since_epoch
180);
181
182/*
183 *  _TOD_Validate
184 *
185 *  DESCRIPTION:
186 *
187 *  This function returns TRUE if THE_TOD contains
188 *  a valid time of day, and FALSE otherwise.
189 */
190
191boolean _TOD_Validate(
192  TOD_Control *the_tod
193);
194
195/*
196 *  _TOD_To_seconds
197 *
198 *  DESCRIPTION:
199 *
200 *  This function returns the number seconds between the epoch and THE_TOD.
201 */
202
203Watchdog_Interval _TOD_To_seconds(
204  TOD_Control *the_tod
205);
206
207/*
208 *  _TOD_Tickle
209 *
210 *  DESCRIPTION:
211 *
212 *  This routine is scheduled as a watchdog function and is invoked at
213 *  each second boundary.  It updates the current time of day to indicate
214 *  that a second has passed and processes the seconds watchdog chain.
215 */
216
217void _TOD_Tickle(
218  Objects_Id  id,
219  void       *ignored
220);
221
222/*
223 *  TOD_MILLISECONDS_TO_MICROSECONDS
224 *
225 *  DESCRIPTION:
226 *
227 *  This routine converts an interval expressed in milliseconds to microseconds.
228 *
229 *  NOTE:
230 *
231 *  This must be a macro so it can be used in "static" tables.
232 */
233
234#define TOD_MILLISECONDS_TO_MICROSECONDS(_ms) ((_ms) * 1000)
235
236/*
237 *  TOD_MILLISECONDS_TO_TICKS
238 *
239 *  DESCRIPTION:
240 *
241 *  This routine converts an interval expressed in milliseconds to ticks.
242 *
243 *  NOTE:
244 *
245 *  This must be a macro so it can be used in "static" tables.
246 */
247
248#define TOD_MILLISECONDS_TO_TICKS(_ms) \
249    (TOD_MILLISECONDS_TO_MICROSECONDS(_ms) / _TOD_Microseconds_per_tick)
250
251#ifndef __RTEMS_APPLICATION__
252#include <rtems/score/tod.inl>
253#endif
254
255#ifdef __cplusplus
256}
257#endif
258
259#endif
260/* end of include file */
Note: See TracBrowser for help on using the repository browser.