source: rtems/cpukit/score/include/rtems/score/tod.h @ 5e7b6272

4.104.114.84.95
Last change on this file since 5e7b6272 was 5e7b6272, checked in by Joel Sherrill <joel.sherrill@…>, on 05/31/96 at 23:27:45

renamed _TOD_Ticks_since_boot as _Watchdog_Ticks_since_boot so the Watchdog
Handler could timestamp the starting and stopping of timers. Since
TOD is built on top of Watchdog, this avoided a circular dependency.

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