RTEMS
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/status.h>
22 #include <rtems/score/timestamp.h>
24 #include <rtems/score/watchdog.h>
25 
26 #include <sys/time.h>
27 #include <time.h>
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
49 #define TOD_SECONDS_PER_MINUTE (uint32_t)60
50 
54 #define TOD_MINUTES_PER_HOUR (uint32_t)60
55 
59 #define TOD_MONTHS_PER_YEAR (uint32_t)12
60 
64 #define TOD_DAYS_PER_YEAR (uint32_t)365
65 
69 #define TOD_HOURS_PER_DAY (uint32_t)24
70 
75 #define TOD_SECONDS_PER_DAY (uint32_t) (TOD_SECONDS_PER_MINUTE * \
76  TOD_MINUTES_PER_HOUR * \
77  TOD_HOURS_PER_DAY)
78 
82 #define TOD_SECONDS_PER_NON_LEAP_YEAR (365 * TOD_SECONDS_PER_DAY)
83 
87 #define TOD_MILLISECONDS_PER_SECOND (uint32_t)1000
88 
92 #define TOD_MICROSECONDS_PER_SECOND (uint32_t)1000000
93 
97 #define TOD_NANOSECONDS_PER_SECOND (uint32_t)1000000000
98 
102 #define TOD_NANOSECONDS_PER_MICROSECOND (uint32_t)1000
103 
111 #define TOD_SECONDS_1970_THROUGH_1988 \
112  (((1987 - 1970 + 1) * TOD_SECONDS_PER_NON_LEAP_YEAR) + \
113  (4 * TOD_SECONDS_PER_DAY))
114 
122 #define TOD_BASE_YEAR 1988
123 
135 typedef struct {
142  bool is_set;
143 } TOD_Control;
144 
148 extern TOD_Control _TOD;
149 
153 void _TOD_Lock( void );
154 
158 void _TOD_Unlock( void );
159 
166 #if defined(RTEMS_DEBUG)
167 bool _TOD_Is_owner( void );
168 #endif
169 
175 static inline void _TOD_Acquire( ISR_lock_Context *lock_context )
176 {
177  _Timecounter_Acquire( lock_context );
178 }
179 
185 static inline void _TOD_Release( ISR_lock_Context *lock_context )
186 {
187  _Timecounter_Release( lock_context );
188 }
189 
204 Status_Control _TOD_Set(
205  const struct timespec *tod,
206  ISR_lock_Context *lock_context
207 );
208 
214 static inline void _TOD_Get(
215  struct timespec *tod
216 )
217 {
218  _Timecounter_Nanotime( tod );
219 }
220 
231 static inline void _TOD_Get_uptime(
232  Timestamp_Control *time
233 )
234 {
235  *time = _Timecounter_Sbinuptime();
236 }
237 
245 static inline void _TOD_Get_zero_based_uptime(
246  Timestamp_Control *time
247 )
248 {
249  *time = _Timecounter_Sbinuptime() - SBT_1S;
250 }
251 
260  struct timespec *time
261 )
262 {
263  _Timecounter_Nanouptime( time );
264  --time->tv_sec;
265 }
266 
275 static inline uint32_t _TOD_Seconds_since_epoch( void )
276 {
277  return (uint32_t) _Timecounter_Time_second;
278 }
279 
290 uint32_t TOD_TICKS_PER_SECOND_method(void);
291 
300 #define TOD_TICKS_PER_SECOND TOD_TICKS_PER_SECOND_method()
301 
309  struct timeval *time
310 )
311 {
312  _Timecounter_Microtime( time );
313 }
314 
323 void _TOD_Adjust(
324  const struct timespec *delta
325 );
326 
334 {
335  return _TOD.is_set;
336 }
337 
359 typedef enum {
364 } TOD_Action;
365 
369 typedef struct TOD_Hook {
372 
374  Status_Control ( *handler )( TOD_Action, const struct timespec * );
375 } TOD_Hook;
376 
381 
389 void _TOD_Hook_Register(
390  TOD_Hook *hook
391 );
392 
401  TOD_Hook *hook
402 );
403 
415 Status_Control _TOD_Hook_Run(
416  TOD_Action action,
417  const struct timespec *tod
418 );
419 
420 
423 #ifdef __cplusplus
424 }
425 #endif
426 
427 #endif
428 /* end of include file */
TOD control.
Definition: todimpl.h:135
static __inline__ bool _TOD_Is_set(void)
Check if the TOD is Set.
Definition: todimpl.h:333
Status_Control _TOD_Set(const struct timespec *tod, ISR_lock_Context *lock_context)
Sets the time of day.
static void _TOD_Get_uptime(Timestamp_Control *time)
Gets the system uptime with potential accuracy to the nanosecond.
Definition: todimpl.h:231
int64_t Timestamp_Control
Definition: timestamp.h:57
#define _Timecounter_Release(lock_context)
Releases the timecounter lock.
Definition: timecounter.h:211
Helpers for Manipulating Timestamps.
void _Timecounter_Nanouptime(struct timespec *ts)
Returns the uptime in the timespec format.
static void _TOD_Get_zero_based_uptime(Timestamp_Control *time)
Gets the system uptime with potential accuracy to the nanosecond.
Definition: todimpl.h:245
struct TOD_Hook TOD_Hook
Structure to manage each TOD action hook.
Constant to indicate the TOD is being set.
Definition: todimpl.h:363
Constants and Structures Associated with Watchdog Timers.
bool is_set
Indicates if the time of day is set.
Definition: todimpl.h:142
TOD_Action
Possible actions where a registered hook could be invoked.
Definition: todimpl.h:359
#define _Timecounter_Acquire(lock_context)
Lock to protect the timecounter mechanic.
Definition: timecounter.h:201
static void _TOD_Release(ISR_lock_Context *lock_context)
Releases the lock context for the timecounter.
Definition: todimpl.h:185
volatile time_t _Timecounter_Time_second
The wall clock time in seconds.
Chain_Node Node
Definition: todimpl.h:371
void _TOD_Adjust(const struct timespec *delta)
Adjusts the Time of Time.
Chain_Control _TOD_Hooks
Set of registered methods for TOD Actions.
void _TOD_Hook_Unregister(TOD_Hook *hook)
Remove a TOD Action Hook.
static void _TOD_Acquire(ISR_lock_Context *lock_context)
Checks if api mutex is owner of the time of day mutex.
Definition: todimpl.h:175
Status_Control _TOD_Hook_Run(TOD_Action action, const struct timespec *tod)
Run the TOD Action Hooks.
TOD_Control _TOD
TOD Management information.
Definition: coretod.c:24
Status_Control(* handler)(TOD_Action, const struct timespec *)
Definition: todimpl.h:374
void _TOD_Hook_Register(TOD_Hook *hook)
Add a TOD Action Hook.
Structure to manage each TOD action hook.
Definition: todimpl.h:369
Timecounter Implementation.
static void _TOD_Get(struct timespec *tod)
Gets the current time in the timespec format.
Definition: todimpl.h:214
void _TOD_Unlock(void)
Unlocks the time of day mutex.
Definition: coretod.c:33
static __inline__ void _TOD_Get_timeval(struct timeval *time)
This routine returns a timeval based upon the internal timespec format TOD.
Definition: todimpl.h:308
static uint32_t _TOD_Seconds_since_epoch(void)
Returns Number of seconds Since RTEMS epoch.
Definition: todimpl.h:275
void _Timecounter_Nanotime(struct timespec *ts)
Returns the wall clock time in the timespec format.
static void _TOD_Get_zero_based_uptime_as_timespec(struct timespec *time)
Gets the system uptime with potential accuracy to the nanosecond.
Definition: todimpl.h:259
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:65
#define RTEMS_INLINE_ROUTINE
Gives a hint to the compiler in a function declaration to inline this function.
Definition: basedefs.h:683
int64_t _Timecounter_Sbinuptime(void)
Returns the uptime in the sbintime_t format.
Definition: kern_tc.c:487
void _Timecounter_Microtime(struct timeval *tv)
Returns the wall clock time in the timeval format.
uint32_t TOD_TICKS_PER_SECOND_method(void)
Gets number of ticks in a second.
void _TOD_Lock(void)
Locks the time of day mutex.
Definition: coretod.c:28