RTEMS  5.0.0
todimpl.h
Go to the documentation of this file.
1 
9 /*
10  * COPYRIGHT (c) 1989-2009.
11  * On-Line Applications Research Corporation (OAR).
12  *
13  * The license and distribution terms for this file may be
14  * found in the file LICENSE in this distribution or at
15  * http://www.rtems.org/license/LICENSE.
16  */
17 
18 #ifndef _RTEMS_SCORE_TODIMPL_H
19 #define _RTEMS_SCORE_TODIMPL_H
20 
21 #include <rtems/score/timestamp.h>
23 #include <rtems/score/watchdog.h>
24 
25 #include <sys/time.h>
26 #include <time.h>
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
45 #define TOD_SECONDS_PER_MINUTE (uint32_t)60
46 
50 #define TOD_MINUTES_PER_HOUR (uint32_t)60
51 
55 #define TOD_MONTHS_PER_YEAR (uint32_t)12
56 
60 #define TOD_DAYS_PER_YEAR (uint32_t)365
61 
65 #define TOD_HOURS_PER_DAY (uint32_t)24
66 
71 #define TOD_SECONDS_PER_DAY (uint32_t) (TOD_SECONDS_PER_MINUTE * \
72  TOD_MINUTES_PER_HOUR * \
73  TOD_HOURS_PER_DAY)
74 
78 #define TOD_SECONDS_PER_NON_LEAP_YEAR (365 * TOD_SECONDS_PER_DAY)
79 
83 #define TOD_MILLISECONDS_PER_SECOND (uint32_t)1000
84 
88 #define TOD_MICROSECONDS_PER_SECOND (uint32_t)1000000
89 
93 #define TOD_NANOSECONDS_PER_SECOND (uint32_t)1000000000
94 
98 #define TOD_NANOSECONDS_PER_MICROSECOND (uint32_t)1000
99 
107 #define TOD_SECONDS_1970_THROUGH_1988 \
108  (((1987 - 1970 + 1) * TOD_SECONDS_PER_NON_LEAP_YEAR) + \
109  (4 * TOD_SECONDS_PER_DAY))
110 
118 #define TOD_BASE_YEAR 1988
119 
130 typedef struct {
137  bool is_set;
138 } TOD_Control;
139 
140 extern TOD_Control _TOD;
141 
142 void _TOD_Lock( void );
143 
144 void _TOD_Unlock( void );
145 
146 #if defined(RTEMS_DEBUG)
147 bool _TOD_Is_owner( void );
148 #endif
149 
150 static inline void _TOD_Acquire( ISR_lock_Context *lock_context )
151 {
152  _Timecounter_Acquire( lock_context );
153 }
154 
166 void _TOD_Set(
167  const struct timespec *tod,
168  ISR_lock_Context *lock_context
169 );
170 
176 static inline void _TOD_Get(
177  struct timespec *tod
178 )
179 {
180  _Timecounter_Nanotime( tod );
181 }
182 
193 static inline void _TOD_Get_uptime(
194  Timestamp_Control *time
195 )
196 {
197  *time = _Timecounter_Sbinuptime();
198 }
199 
208 static inline void _TOD_Get_zero_based_uptime(
209  Timestamp_Control *time
210 )
211 {
212  *time = _Timecounter_Sbinuptime() - SBT_1S;
213 }
214 
222 static inline void _TOD_Get_zero_based_uptime_as_timespec(
223  struct timespec *time
224 )
225 {
226  _Timecounter_Nanouptime( time );
227  --time->tv_sec;
228 }
229 
236 static inline uint32_t _TOD_Seconds_since_epoch( void )
237 {
238  return (uint32_t) _Timecounter_Time_second;
239 }
240 
249 uint32_t TOD_TICKS_PER_SECOND_method(void);
250 
259 #define TOD_TICKS_PER_SECOND TOD_TICKS_PER_SECOND_method()
260 
266  struct timeval *time
267 )
268 {
269  _Timecounter_Microtime( time );
270 }
271 
280 void _TOD_Adjust(
281  const struct timespec *delta
282 );
283 
290 {
291  return _TOD.is_set;
292 }
293 
296 #ifdef __cplusplus
297 }
298 #endif
299 
300 #endif
301 /* end of include file */
TOD control.
Definition: todimpl.h:130
RTEMS_INLINE_ROUTINE void _TOD_Get_timeval(struct timeval *time)
Definition: todimpl.h:265
int64_t Timestamp_Control
Definition: timestamp.h:52
#define RTEMS_INLINE_ROUTINE
Definition: basedefs.h:65
#define _Timecounter_Acquire(lock_context)
Lock to protect the timecounter mechanic.
Definition: timecounter.h:199
Helpers for Manipulating Timestamps.
int64_t _Timecounter_Sbinuptime(void)
Returns the uptime in the sbintime_t format.
bool is_set
Indicates if the time of day is set.
Definition: todimpl.h:137
RTEMS_INLINE_ROUTINE bool _TOD_Is_set(void)
Check if the TOD is Set.
Definition: todimpl.h:289
volatile time_t _Timecounter_Time_second
The wall clock time in seconds.
void _Timecounter_Nanouptime(struct timespec *ts)
Returns the uptime in the timespec format.
Timecounter Implementation.
void _Timecounter_Nanotime(struct timespec *ts)
Returns the wall clock time in the timespec format.
void _TOD_Adjust(const struct timespec *delta)
Adjust the Time of Time.
Definition: coretodadjust.c:23
Constants and Structures Associated with Watchdog Timers.
uint32_t TOD_TICKS_PER_SECOND_method(void)
Gets number of ticks in a second.
Definition: coretodtickspersec.c:24
void _Timecounter_Microtime(struct timeval *tv)
Returns the wall clock time in the timeval format.
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:65
void _TOD_Set(const struct timespec *tod, ISR_lock_Context *lock_context)
Sets the time of day.
Definition: coretodset.c:25