1 | /** |
---|
2 | * @file rtems/score/tod.h |
---|
3 | * |
---|
4 | * This include file contains all the constants and structures associated |
---|
5 | * with the Time of Day Handler. |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2007. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.com/license/LICENSE. |
---|
15 | * |
---|
16 | * $Id$ |
---|
17 | */ |
---|
18 | |
---|
19 | #ifndef _RTEMS_SCORE_TOD_H |
---|
20 | #define _RTEMS_SCORE_TOD_H |
---|
21 | |
---|
22 | /** |
---|
23 | * @defgroup ScoreTOD Time Of Day (TOD) Handler |
---|
24 | * |
---|
25 | * This handler encapsulates functionality used to manage time of day. |
---|
26 | */ |
---|
27 | /**@{*/ |
---|
28 | |
---|
29 | #ifdef __cplusplus |
---|
30 | extern "C" { |
---|
31 | #endif |
---|
32 | |
---|
33 | #include <rtems/score/object.h> |
---|
34 | #include <time.h> |
---|
35 | |
---|
36 | /** @defgroup ScoreTODConstants TOD Constants |
---|
37 | * The following constants are related to the time of day. |
---|
38 | */ |
---|
39 | /**@{*/ |
---|
40 | |
---|
41 | /** |
---|
42 | * This constant represents the number of seconds in a minute. |
---|
43 | */ |
---|
44 | #define TOD_SECONDS_PER_MINUTE (uint32_t)60 |
---|
45 | |
---|
46 | /** |
---|
47 | * This constant represents the number of minutes per hour. |
---|
48 | */ |
---|
49 | #define TOD_MINUTES_PER_HOUR (uint32_t)60 |
---|
50 | |
---|
51 | /** |
---|
52 | * This constant represents the number of months in a year. |
---|
53 | */ |
---|
54 | #define TOD_MONTHS_PER_YEAR (uint32_t)12 |
---|
55 | |
---|
56 | /** |
---|
57 | * This constant represents the number of days in a non-leap year. |
---|
58 | */ |
---|
59 | #define TOD_DAYS_PER_YEAR (uint32_t)365 |
---|
60 | |
---|
61 | /** |
---|
62 | * This constant represents the number of hours per day. |
---|
63 | */ |
---|
64 | #define TOD_HOURS_PER_DAY (uint32_t)24 |
---|
65 | |
---|
66 | /** |
---|
67 | * This constant represents the number of seconds in a day which does |
---|
68 | * not include a leap second. |
---|
69 | */ |
---|
70 | #define TOD_SECONDS_PER_DAY (uint32_t) (TOD_SECONDS_PER_MINUTE * \ |
---|
71 | TOD_MINUTES_PER_HOUR * \ |
---|
72 | TOD_HOURS_PER_DAY) |
---|
73 | |
---|
74 | /** |
---|
75 | * This constant represents the number of seconds in a non-leap year. |
---|
76 | */ |
---|
77 | #define TOD_SECONDS_PER_NON_LEAP_YEAR (365 * TOD_SECONDS_PER_DAY) |
---|
78 | |
---|
79 | /** |
---|
80 | * This constant represents the number of seconds in a millisecond. |
---|
81 | */ |
---|
82 | #define TOD_MILLISECONDS_PER_SECOND (uint32_t)1000 |
---|
83 | |
---|
84 | /** |
---|
85 | * This constant represents the number of microseconds in a second. |
---|
86 | */ |
---|
87 | #define TOD_MICROSECONDS_PER_SECOND (uint32_t)1000000 |
---|
88 | |
---|
89 | /** |
---|
90 | * This constant represents the number of nanoseconds in a second. |
---|
91 | */ |
---|
92 | #define TOD_NANOSECONDS_PER_SECOND (uint32_t)1000000000 |
---|
93 | |
---|
94 | /** |
---|
95 | * This constant represents the number of nanoseconds in a second. |
---|
96 | */ |
---|
97 | #define TOD_NANOSECONDS_PER_MICROSECOND (uint32_t)1000 |
---|
98 | |
---|
99 | /* |
---|
100 | * Seconds from January 1, 1970 to January 1, 1988. Used to account for |
---|
101 | * differences between POSIX API and RTEMS core. The timespec format time |
---|
102 | * is kept in POSIX compliant form. |
---|
103 | */ |
---|
104 | #define TOD_SECONDS_1970_THROUGH_1988 \ |
---|
105 | (((1987 - 1970 + 1) * TOD_SECONDS_PER_NON_LEAP_YEAR) + \ |
---|
106 | (4 * TOD_SECONDS_PER_DAY)) |
---|
107 | |
---|
108 | /**@}*/ |
---|
109 | |
---|
110 | /** @brief Ticks per Second |
---|
111 | * |
---|
112 | * This macro calculates the number of ticks per second. |
---|
113 | */ |
---|
114 | |
---|
115 | #define TOD_TICKS_PER_SECOND \ |
---|
116 | (TOD_MICROSECONDS_PER_SECOND / _TOD_Microseconds_per_tick) |
---|
117 | |
---|
118 | /** @brief RTEMS Epoch Year |
---|
119 | * |
---|
120 | * The following constant define the earliest year to which an |
---|
121 | * time of day can be initialized. This is considered the |
---|
122 | * epoch. |
---|
123 | */ |
---|
124 | #define TOD_BASE_YEAR 1988 |
---|
125 | |
---|
126 | /** @brief Is the Time Of Day Set |
---|
127 | * |
---|
128 | * This is TRUE if the application has set the current |
---|
129 | * time of day, and FALSE otherwise. |
---|
130 | */ |
---|
131 | SCORE_EXTERN boolean _TOD_Is_set; |
---|
132 | |
---|
133 | /** @brief Current Time of Day (Timespec) |
---|
134 | * The following contains the current time of day. |
---|
135 | */ |
---|
136 | SCORE_EXTERN struct timespec _TOD_Now; |
---|
137 | |
---|
138 | /** @brief Current Time of Day (Timespec) |
---|
139 | * The following contains the running uptime. |
---|
140 | */ |
---|
141 | SCORE_EXTERN struct timespec _TOD_Uptime; |
---|
142 | |
---|
143 | /** @brief Seconds Since RTEMS Epoch |
---|
144 | * The following contains the number of seconds from 00:00:00 |
---|
145 | * January 1, TOD_BASE_YEAR until the current time of day. |
---|
146 | */ |
---|
147 | #define _TOD_Seconds_since_epoch (_TOD_Now.tv_sec) |
---|
148 | |
---|
149 | /** @brief Microseconds per Clock Tick |
---|
150 | * |
---|
151 | * The following contains the number of microseconds per tick. |
---|
152 | */ |
---|
153 | SCORE_EXTERN uint32_t _TOD_Microseconds_per_tick; |
---|
154 | |
---|
155 | /** @brief _TOD_Handler_initialization |
---|
156 | * |
---|
157 | * This routine performs the initialization necessary for this handler. |
---|
158 | */ |
---|
159 | void _TOD_Handler_initialization( |
---|
160 | uint32_t microseconds_per_tick |
---|
161 | ); |
---|
162 | |
---|
163 | /** @brief _TOD_Set |
---|
164 | * |
---|
165 | * This routine sets the current time of day to @a time and |
---|
166 | * the equivalent SECONDS_SINCE_EPOCH. |
---|
167 | */ |
---|
168 | void _TOD_Set( |
---|
169 | const struct timespec *time |
---|
170 | ); |
---|
171 | |
---|
172 | /** @brief _TOD_Get |
---|
173 | * |
---|
174 | * This routine returns the current time of day with potential accuracy |
---|
175 | * to the nanosecond. |
---|
176 | * |
---|
177 | * @param[in] time is a pointer to the time to be returned |
---|
178 | */ |
---|
179 | void _TOD_Get( |
---|
180 | struct timespec *time |
---|
181 | ); |
---|
182 | |
---|
183 | /** @brief _TOD_Get_uptime |
---|
184 | * |
---|
185 | * This routine returns the system uptime with potential accuracy |
---|
186 | * to the nanosecond. |
---|
187 | * |
---|
188 | * @param[in] time is a pointer to the uptime to be returned |
---|
189 | */ |
---|
190 | void _TOD_Get_uptime( |
---|
191 | struct timespec *time |
---|
192 | ); |
---|
193 | |
---|
194 | /** |
---|
195 | * This routine increments the ticks field of the current time of |
---|
196 | * day at each clock tick. |
---|
197 | */ |
---|
198 | void _TOD_Tickle_ticks( void ); |
---|
199 | |
---|
200 | /** @brief TOD_MILLISECONDS_TO_MICROSECONDS |
---|
201 | * |
---|
202 | * This routine converts an interval expressed in milliseconds to microseconds. |
---|
203 | * |
---|
204 | * @note This must be a macro so it can be used in "static" tables. |
---|
205 | */ |
---|
206 | #define TOD_MILLISECONDS_TO_MICROSECONDS(_ms) ((uint32_t)(_ms) * 1000L) |
---|
207 | |
---|
208 | /** @brief TOD_MICROSECONDS_TO_TICKS |
---|
209 | * |
---|
210 | * This routine converts an interval expressed in microseconds to ticks. |
---|
211 | * |
---|
212 | * @note This must be a macro so it can be used in "static" tables. |
---|
213 | */ |
---|
214 | #define TOD_MICROSECONDS_TO_TICKS(_us) \ |
---|
215 | ((_us) / _TOD_Microseconds_per_tick) |
---|
216 | |
---|
217 | /** @brief TOD_MILLISECONDS_TO_TICKS |
---|
218 | * |
---|
219 | * This routine converts an interval expressed in milliseconds to ticks. |
---|
220 | * |
---|
221 | * @note This must be a macro so it can be used in "static" tables. |
---|
222 | */ |
---|
223 | |
---|
224 | #define TOD_MILLISECONDS_TO_TICKS(_ms) \ |
---|
225 | (TOD_MILLISECONDS_TO_MICROSECONDS(_ms) / _TOD_Microseconds_per_tick) |
---|
226 | |
---|
227 | |
---|
228 | /** @brief How many ticks in a second? |
---|
229 | * |
---|
230 | * This macro returns the number of ticks in a second. |
---|
231 | * |
---|
232 | * @note If the clock tick value does not multiply evenly into a second |
---|
233 | * then this number of ticks will be slightly shorter than a second. |
---|
234 | */ |
---|
235 | #define TOD_TICKS_PER_SECOND \ |
---|
236 | (TOD_MICROSECONDS_PER_SECOND / _TOD_Microseconds_per_tick) |
---|
237 | |
---|
238 | #ifndef __RTEMS_APPLICATION__ |
---|
239 | #include <rtems/score/tod.inl> |
---|
240 | #endif |
---|
241 | |
---|
242 | #ifdef __cplusplus |
---|
243 | } |
---|
244 | #endif |
---|
245 | |
---|
246 | /**@}*/ |
---|
247 | |
---|
248 | #endif |
---|
249 | /* end of include file */ |
---|