OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [exec/] [score/] [include/] [rtems/] [score/] [tod.h] - Blame information for rev 735

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*  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.OARcorp.com/rtems/license.html.
12
 *
13
 *  $Id: tod.h,v 1.2 2001-09-27 11:59:32 chris Exp $
14
 */
15
 
16
#ifndef __TIME_OF_DAY_h
17
#define __TIME_OF_DAY_h
18
 
19
#ifdef __cplusplus
20
extern "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 60
31
#define TOD_MINUTES_PER_HOUR   60
32
#define TOD_MONTHS_PER_YEAR    12
33
#define TOD_DAYS_PER_YEAR      365
34
#define TOD_HOURS_PER_DAY      24
35
#define TOD_SECONDS_PER_DAY    (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     1000
42
#define TOD_MICROSECONDS_PER_SECOND     1000000
43
#define TOD_NANOSECONDS_PER_SECOND      1000000000
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
 
59
typedef 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 is TRUE if the application has set the current
71
 *  time of day, and FALSE otherwise.
72
 */
73
 
74
SCORE_EXTERN boolean _TOD_Is_set;
75
 
76
/*
77
 *  The following contains the current time of day.
78
 */
79
 
80
SCORE_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
 
87
SCORE_EXTERN Watchdog_Interval _TOD_Seconds_since_epoch;
88
 
89
/*
90
 *  The following contains the number of microseconds per tick.
91
 */
92
 
93
SCORE_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
 
106
SCORE_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
 
113
SCORE_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
 
124
const 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
 
135
const 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
 
147
const unsigned16 _TOD_Days_since_last_leap_year[4] = { 0, 366, 731, 1096 };
148
 
149
#else
150
 
151
extern const unsigned16 _TOD_Days_to_date[2][13]; /* Julian days */
152
extern const unsigned16 _TOD_Days_since_last_leap_year[4];
153
extern 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
 
165
void _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
 
178
void _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
 
192
boolean _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
 
204
Watchdog_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
 
218
void _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 */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.