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