source: rtems/cpukit/score/include/rtems/score/tod.h @ 412dbff6

4.104.114.84.95
Last change on this file since 412dbff6 was 412dbff6, checked in by Joel Sherrill <joel.sherrill@…>, on 04/05/07 at 21:17:27

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

  • posix/Makefile.am, posix/include/rtems/posix/time.h, posix/src/adjtime.c, posix/src/alarm.c, posix/src/clockgetres.c, posix/src/condtimedwait.c, posix/src/mqueuetimedreceive.c, posix/src/mqueuetimedsend.c, posix/src/mutextimedlock.c, posix/src/nanosleep.c, posix/src/posixtimespecabsolutetimeout.c, posix/src/pthread.c, posix/src/pthreadcreate.c, posix/src/pthreadsetschedparam.c, posix/src/ptimer1.c, posix/src/sched.c, posix/src/semtimedwait.c, posix/src/sigtimedwait.c, posix/src/ualarm.c, rtems/src/clocktodtoseconds.c, score/Makefile.am, score/preinstall.am, score/include/rtems/score/tod.h, score/inline/rtems/score/tod.inl, score/src/coretod.c, score/src/coretodget.c, score/src/coretodgetuptime.c, score/src/coretodset.c, score/src/coretodtickle.c: Provide timespec manipulation routines in the SuperCore?. Use them everywhere possible. This lead to significant cleanup in the API routines and eliminated some of the same code from the POSIX API. At this point, the SuperCore? keeps time in POSIX timespec format properly from 1970. You just cannot set it before 1988 in keeping with RTEMS traditional behavior.
  • score/include/rtems/score/timespec.h, score/src/timespecaddto.c, score/src/timespecfromticks.c, score/src/timespecisvalid.c, score/src/timespeclessthan.c, score/src/timespecsubtract.c, score/src/timespectoticks.c: New files.
  • posix/src/posixintervaltotimespec.c, posix/src/posixtimespecsubtract.c, posix/src/posixtimespectointerval.c: Removed.
  • Property mode set to 100644
File size: 5.9 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 */
140#define _TOD_Seconds_since_epoch (_TOD_Now.tv_sec)
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/**
188 *  This routine increments the ticks field of the current time of
189 *  day at each clock tick.
190 */
191void _TOD_Tickle_ticks( void );
192
193/** @brief TOD_MILLISECONDS_TO_MICROSECONDS
194 *
195 *  This routine converts an interval expressed in milliseconds to microseconds.
196 *
197 *  @note This must be a macro so it can be used in "static" tables.
198 */
199#define TOD_MILLISECONDS_TO_MICROSECONDS(_ms) ((uint32_t)(_ms) * 1000L)
200
201/** @brief TOD_MICROSECONDS_TO_TICKS
202 *
203 *  This routine converts an interval expressed in microseconds to ticks.
204 *
205 *  @note This must be a macro so it can be used in "static" tables.
206 */
207#define TOD_MICROSECONDS_TO_TICKS(_us) \
208    ((_us) / _TOD_Microseconds_per_tick)
209
210/** @brief TOD_MILLISECONDS_TO_TICKS
211 *
212 *  This routine converts an interval expressed in milliseconds to ticks.
213 *
214 *  @note This must be a macro so it can be used in "static" tables.
215 */
216
217#define TOD_MILLISECONDS_TO_TICKS(_ms) \
218    (TOD_MILLISECONDS_TO_MICROSECONDS(_ms) / _TOD_Microseconds_per_tick)
219
220
221/** @brief How many ticks in a second?
222 *
223 *  This macro returns the number of ticks in a second.
224 *
225 *  @note If the clock tick value does not multiply evenly into a second
226 *        then this number of ticks will be slightly shorter than a second.
227 */
228#define TOD_TICKS_PER_SECOND \
229  (TOD_MICROSECONDS_PER_SECOND / _TOD_Microseconds_per_tick)
230
231#ifndef __RTEMS_APPLICATION__
232#include <rtems/score/tod.inl>
233#endif
234
235#ifdef __cplusplus
236}
237#endif
238
239/**@}*/
240
241#endif
242/* end of include file */
Note: See TracBrowser for help on using the repository browser.