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

4.104.114.84.95
Last change on this file since f6e0934 was f6e0934, checked in by Joel Sherrill <joel.sherrill@…>, on 04/02/07 at 21:51:52

2007-04-02 Joel Sherrill <joel@…>

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