[ac7d5ef0] | 1 | /* tod.h |
---|
| 2 | * |
---|
| 3 | * This include file contains all the constants and structures associated |
---|
| 4 | * with the Time of Day Handler. |
---|
| 5 | * |
---|
[08311cc3] | 6 | * COPYRIGHT (c) 1989-1999. |
---|
[ac7d5ef0] | 7 | * On-Line Applications Research Corporation (OAR). |
---|
| 8 | * |
---|
[98e4ebf5] | 9 | * The license and distribution terms for this file may be |
---|
| 10 | * found in the file LICENSE in this distribution or at |
---|
[03f2154e] | 11 | * http://www.OARcorp.com/rtems/license.html. |
---|
[ac7d5ef0] | 12 | * |
---|
| 13 | * $Id$ |
---|
| 14 | */ |
---|
| 15 | |
---|
[3a4ae6c] | 16 | #ifndef __TIME_OF_DAY_h |
---|
| 17 | #define __TIME_OF_DAY_h |
---|
[ac7d5ef0] | 18 | |
---|
| 19 | #ifdef __cplusplus |
---|
| 20 | extern "C" { |
---|
| 21 | #endif |
---|
| 22 | |
---|
[5e9b32b] | 23 | #include <rtems/score/object.h> |
---|
| 24 | #include <rtems/score/watchdog.h> |
---|
[ac7d5ef0] | 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 | |
---|
[5e9b32b] | 39 | #define TOD_SECONDS_PER_NON_LEAP_YEAR (365 * TOD_SECONDS_PER_DAY) |
---|
| 40 | |
---|
[7c55e06] | 41 | #define TOD_MILLISECONDS_PER_SECOND 1000 |
---|
[c832429] | 42 | #define TOD_MICROSECONDS_PER_SECOND 1000000 |
---|
| 43 | #define TOD_NANOSECONDS_PER_SECOND 1000000000 |
---|
[7c55e06] | 44 | #define TOD_NANOSECONDS_PER_MICROSECOND 1000 |
---|
[ac7d5ef0] | 45 | |
---|
| 46 | /* |
---|
| 47 | * The following constant define the earliest year to which an |
---|
[3a4ae6c] | 48 | * time of day can be initialized. This is considered the |
---|
[ac7d5ef0] | 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 */ |
---|
[3a4ae6c] | 67 | } TOD_Control; |
---|
[ac7d5ef0] | 68 | |
---|
[7fea679b] | 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 | |
---|
[ac7d5ef0] | 76 | /* |
---|
| 77 | * The following contains the current time of day. |
---|
| 78 | */ |
---|
| 79 | |
---|
[c627b2a3] | 80 | SCORE_EXTERN TOD_Control _TOD_Current; |
---|
[ac7d5ef0] | 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 | |
---|
[c627b2a3] | 87 | SCORE_EXTERN Watchdog_Interval _TOD_Seconds_since_epoch; |
---|
[ac7d5ef0] | 88 | |
---|
| 89 | /* |
---|
| 90 | * The following contains the number of microseconds per tick. |
---|
| 91 | */ |
---|
| 92 | |
---|
[c627b2a3] | 93 | SCORE_EXTERN unsigned32 _TOD_Microseconds_per_tick; |
---|
[ac7d5ef0] | 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 | |
---|
[c627b2a3] | 106 | SCORE_EXTERN unsigned32 _TOD_Ticks_per_second; |
---|
[ac7d5ef0] | 107 | |
---|
| 108 | /* |
---|
| 109 | * This is the control structure for the watchdog timer which |
---|
| 110 | * fires to service the seconds chain. |
---|
| 111 | */ |
---|
| 112 | |
---|
[c627b2a3] | 113 | SCORE_EXTERN Watchdog_Control _TOD_Seconds_watchdog; |
---|
[ac7d5ef0] | 114 | |
---|
[c627b2a3] | 115 | #ifdef SCORE_INIT |
---|
[ac7d5ef0] | 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 | |
---|
[87904ba] | 147 | const unsigned16 _TOD_Days_since_last_leap_year[4] = { 0, 366, 731, 1096 }; |
---|
[ac7d5ef0] | 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( |
---|
[3a4ae6c] | 179 | TOD_Control *the_tod, |
---|
| 180 | Watchdog_Interval seconds_since_epoch |
---|
[ac7d5ef0] | 181 | ); |
---|
| 182 | |
---|
| 183 | /* |
---|
| 184 | * _TOD_Validate |
---|
| 185 | * |
---|
| 186 | * DESCRIPTION: |
---|
| 187 | * |
---|
[3a4ae6c] | 188 | * This function returns TRUE if THE_TOD contains |
---|
[ac7d5ef0] | 189 | * a valid time of day, and FALSE otherwise. |
---|
| 190 | */ |
---|
| 191 | |
---|
[3a4ae6c] | 192 | boolean _TOD_Validate( |
---|
| 193 | TOD_Control *the_tod |
---|
[ac7d5ef0] | 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 | |
---|
[3a4ae6c] | 204 | Watchdog_Interval _TOD_To_seconds( |
---|
| 205 | TOD_Control *the_tod |
---|
[ac7d5ef0] | 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 | /* |
---|
[3a4ae6c] | 224 | * TOD_MILLISECONDS_TO_MICROSECONDS |
---|
[ac7d5ef0] | 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 | |
---|
[3a4ae6c] | 235 | #define TOD_MILLISECONDS_TO_MICROSECONDS(_ms) ((_ms) * 1000) |
---|
[ac7d5ef0] | 236 | |
---|
[0a6fb22] | 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 | |
---|
[ac7d5ef0] | 252 | /* |
---|
[3a4ae6c] | 253 | * TOD_MILLISECONDS_TO_TICKS |
---|
[ac7d5ef0] | 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 | |
---|
[3a4ae6c] | 264 | #define TOD_MILLISECONDS_TO_TICKS(_ms) \ |
---|
| 265 | (TOD_MILLISECONDS_TO_MICROSECONDS(_ms) / _TOD_Microseconds_per_tick) |
---|
[ac7d5ef0] | 266 | |
---|
[1a8fde6c] | 267 | #ifndef __RTEMS_APPLICATION__ |
---|
[5e9b32b] | 268 | #include <rtems/score/tod.inl> |
---|
[1a8fde6c] | 269 | #endif |
---|
[ac7d5ef0] | 270 | |
---|
| 271 | #ifdef __cplusplus |
---|
| 272 | } |
---|
| 273 | #endif |
---|
| 274 | |
---|
| 275 | #endif |
---|
| 276 | /* end of include file */ |
---|