source: rtems/c/src/exec/score/include/rtems/score/tod.h @ 7c55e06

4.104.114.84.95
Last change on this file since 7c55e06 was 7c55e06, checked in by Joel Sherrill <joel.sherrill@…>, on 05/30/96 at 20:48:33

Added nanoseconds constant

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