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

4.104.114.84.95
Last change on this file since d6154c7 was d6154c7, checked in by Ralf Corsepius <ralf.corsepius@…>, on Mar 29, 2004 at 4:41:13 PM

2004-03-29 Ralf Corsepius <ralf_corsepius@…>

  • score/include/rtems/debug.h, score/include/rtems/score/bitfield.h, score/include/rtems/score/chain.h, score/include/rtems/score/coremsg.h, score/include/rtems/score/coremutex.h, score/include/rtems/score/coresem.h, score/include/rtems/score/heap.h, score/include/rtems/score/interr.h, score/include/rtems/score/isr.h, score/include/rtems/score/mpci.h, score/include/rtems/score/mppkt.h, score/include/rtems/score/object.h, score/include/rtems/score/objectmp.h, score/include/rtems/score/priority.h, score/include/rtems/score/stack.h, score/include/rtems/score/states.h, score/include/rtems/score/thread.h, score/include/rtems/score/threadmp.h, score/include/rtems/score/threadq.h, score/include/rtems/score/tod.h, score/include/rtems/score/tqdata.h, score/include/rtems/score/userext.h, score/include/rtems/score/watchdog.h, score/include/rtems/score/wkspace.h, score/inline/rtems/score/address.inl, score/inline/rtems/score/coremsg.inl, score/inline/rtems/score/coresem.inl, score/inline/rtems/score/heap.inl, score/inline/rtems/score/isr.inl, score/inline/rtems/score/object.inl, score/inline/rtems/score/priority.inl, score/inline/rtems/score/stack.inl, score/inline/rtems/score/thread.inl, score/inline/rtems/score/tqdata.inl, score/inline/rtems/score/userext.inl, score/inline/rtems/score/wkspace.inl, score/macros/rtems/score/address.inl, score/macros/rtems/score/heap.inl, score/macros/rtems/score/object.inl, score/macros/rtems/score/priority.inl, score/macros/rtems/score/userext.inl: Convert to using c99 fixed size types.
  • Property mode set to 100644
File size: 6.6 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-1999.
7 *  On-Line Applications Research Corporation (OAR).
8 *
9 *  The license and distribution terms for this file may be
10 *  found in the file LICENSE in this distribution or at
11 *  http://www.rtems.com/license/LICENSE.
12 *
13 *  $Id$
14 */
15
16#ifndef __TIME_OF_DAY_h
17#define __TIME_OF_DAY_h
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23#include <rtems/score/object.h>
24#include <rtems/score/watchdog.h>
25
26/*
27 *  The following constants are related to the time of day.
28 */
29
30#define TOD_SECONDS_PER_MINUTE (uint32_t  )60
31#define TOD_MINUTES_PER_HOUR   (uint32_t  )60
32#define TOD_MONTHS_PER_YEAR    (uint32_t  )12
33#define TOD_DAYS_PER_YEAR      (uint32_t  )365
34#define TOD_HOURS_PER_DAY      (uint32_t  )24
35#define TOD_SECONDS_PER_DAY    (uint32_t  ) (TOD_SECONDS_PER_MINUTE * \
36                                TOD_MINUTES_PER_HOUR   * \
37                                TOD_HOURS_PER_DAY)
38
39#define TOD_SECONDS_PER_NON_LEAP_YEAR (365 * TOD_SECONDS_PER_DAY)
40
41#define TOD_MILLISECONDS_PER_SECOND     (uint32_t  )1000
42#define TOD_MICROSECONDS_PER_SECOND     (uint32_t  )1000000
43#define TOD_NANOSECONDS_PER_SECOND      (uint32_t  )1000000000
44#define TOD_NANOSECONDS_PER_MICROSECOND (uint32_t  )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  uint32_t   year;                 /* year, A.D. */
61  uint32_t   month;                /* month, 1 -> 12 */
62  uint32_t   day;                  /* day, 1 -> 31 */
63  uint32_t   hour;                 /* hour, 0 -> 23 */
64  uint32_t   minute;               /* minute, 0 -> 59 */
65  uint32_t   second;               /* second, 0 -> 59 */
66  uint32_t   ticks;                /* elapsed ticks between secs */
67}   TOD_Control;
68
69/*
70 *  The following is TRUE if the application has set the current
71 *  time of day, and FALSE otherwise.
72 */
73
74SCORE_EXTERN boolean _TOD_Is_set;
75
76/*
77 *  The following contains the current time of day.
78 */
79
80SCORE_EXTERN TOD_Control _TOD_Current;
81
82/*
83 *  The following contains the number of seconds from 00:00:00
84 *  January 1, TOD_BASE_YEAR until the current time of day.
85 */
86
87SCORE_EXTERN Watchdog_Interval _TOD_Seconds_since_epoch;
88
89/*
90 *  The following contains the number of microseconds per tick.
91 */
92
93SCORE_EXTERN uint32_t   _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 uint32_t   _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 uint32_t   _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 uint16_t   _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 uint16_t   _TOD_Days_since_last_leap_year[4] = { 0, 366, 731, 1096 };
148
149#else
150
151extern const uint16_t   _TOD_Days_to_date[2][13]; /* Julian days */
152extern const uint16_t   _TOD_Days_since_last_leap_year[4];
153extern const uint32_t   _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  uint32_t   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_MICROSECONDS_TO_TICKS
239 *
240 *  DESCRIPTION:
241 *
242 *  This routine converts an interval expressed in microseconds 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_MICROSECONDS_TO_TICKS(_us) \
250    ((_us) / _TOD_Microseconds_per_tick)
251
252/*
253 *  TOD_MILLISECONDS_TO_TICKS
254 *
255 *  DESCRIPTION:
256 *
257 *  This routine converts an interval expressed in milliseconds to ticks.
258 *
259 *  NOTE:
260 *
261 *  This must be a macro so it can be used in "static" tables.
262 */
263
264#define TOD_MILLISECONDS_TO_TICKS(_ms) \
265    (TOD_MILLISECONDS_TO_MICROSECONDS(_ms) / _TOD_Microseconds_per_tick)
266
267#ifndef __RTEMS_APPLICATION__
268#include <rtems/score/tod.inl>
269#endif
270
271#ifdef __cplusplus
272}
273#endif
274
275#endif
276/* end of include file */
Note: See TracBrowser for help on using the repository browser.