source: rtems/cpukit/score/include/rtems/score/tod.h @ 377cf106

4.104.114.95
Last change on this file since 377cf106 was 377cf106, checked in by Joel Sherrill <joel.sherrill@…>, on 04/09/08 at 18:27:02

2008-04-09 Madhusudan.C.S <madhusudancs@…>

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