RTEMS: cpukit/include/rtems/score/todimpl.h Source File

| RTEMS 5.4-rc2

Loading...
Searching...
No Matches
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>
23#include <rtems/score/timecounterimpl.h>
24#include <rtems/score/watchdog.h>
25
26#include <sys/time.h>
27#include <time.h>
28
29#ifdef __cplusplus
30extern "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
148extern TOD_Control _TOD;
149
153void _TOD_Lock( void );
154
158void _TOD_Unlock( void );
159
166#if defined(RTEMS_DEBUG)
167bool _TOD_Is_owner( void );
168#endif
169
175static inline void _TOD_Acquire( ISR_lock_Context *lock_context )
176{
177 _Timecounter_Acquire( lock_context );
178}
179
185static inline void _TOD_Release( ISR_lock_Context *lock_context )
186{
187 _Timecounter_Release( lock_context );
188}
189
204Status_Control _TOD_Set(
205 const struct timespec *tod,
206 ISR_lock_Context *lock_context
207);
208
214static inline void _TOD_Get(
215 struct timespec *tod
216)
217{
218 _Timecounter_Nanotime( tod );
219}
220
231static inline void _TOD_Get_uptime(
232 Timestamp_Control *time
233)
234{
235 *time = _Timecounter_Sbinuptime();
236}
237
245static inline void _TOD_Get_zero_based_uptime(
246 Timestamp_Control *time
247)
248{
249 *time = _Timecounter_Sbinuptime() - SBT_1S;
250}
251
259static inline void _TOD_Get_zero_based_uptime_as_timespec(
260 struct timespec *time
261)
262{
263 _Timecounter_Nanouptime( time );
264 --time->tv_sec;
265}
266
275static inline uint32_t _TOD_Seconds_since_epoch( void )
276{
277 return (uint32_t) _Timecounter_Time_second;
278}
279
290uint32_t TOD_TICKS_PER_SECOND_method(void);
291
300#define TOD_TICKS_PER_SECOND TOD_TICKS_PER_SECOND_method()
301
308 RTEMS_INLINE_ROUTINE void _TOD_Get_timeval(
309 struct timeval *time
310)
311{
312 _Timecounter_Microtime( time );
313}
314
323void _TOD_Adjust(
324 const struct timespec *delta
325);
326
333 RTEMS_INLINE_ROUTINE bool _TOD_Is_set( void )
334{
335 return _TOD.is_set;
336}
337
359 typedef enum {
363 TOD_ACTION_SET_CLOCK
364} TOD_Action;
365
369 typedef struct TOD_Hook {
371 Chain_Node Node;
372
374 Status_Control ( *handler )( TOD_Action, const struct timespec * );
375} TOD_Hook;
376
380extern Chain_Control _TOD_Hooks;
381
389void _TOD_Hook_Register(
390 TOD_Hook *hook
391);
392
400void _TOD_Hook_Unregister(
401 TOD_Hook *hook
402);
403
415Status_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 */
watchdog.h
Constants and Structures Associated with Watchdog Timers.
RTEMS_INLINE_ROUTINE
#define RTEMS_INLINE_ROUTINE
Definition: basedefs.h:66
_TOD_Hook_Run
Status_Control _TOD_Hook_Run(TOD_Action action, const struct timespec *tod)
Run the TOD Action Hooks.
Definition: coretodhookrun.c:45
_TOD_Hooks
Chain_Control _TOD_Hooks
Set of registered methods for TOD Actions.
Definition: coretodhookdata.c:44
_TOD_Hook_Unregister
void _TOD_Hook_Unregister(TOD_Hook *hook)
Remove a TOD Action Hook.
Definition: coretodhookunregister.c:44
_TOD_Hook_Register
void _TOD_Hook_Register(TOD_Hook *hook)
Add a TOD Action Hook.
Definition: coretodhookregister.c:44
TOD_Action
TOD_Action
Possible actions where a registered hook could be invoked.
Definition: todimpl.h:359
TOD_ACTION_SET_CLOCK
@ TOD_ACTION_SET_CLOCK
Constant to indicate the TOD is being set.
Definition: todimpl.h:363
_TOD_Set
Status_Control _TOD_Set(const struct timespec *tod, ISR_lock_Context *lock_context)
Sets the time of day.
Definition: coretodset.c:44
_TOD
TOD_Control _TOD
TOD Management information.
Definition: coretod.c:24
_TOD_Unlock
void _TOD_Unlock(void)
Unlocks the time of day mutex.
Definition: coretod.c:33
_TOD_Get_timeval
RTEMS_INLINE_ROUTINE void _TOD_Get_timeval(struct timeval *time)
This routine returns a timeval based upon the internal timespec format TOD.
Definition: todimpl.h:308
_TOD_Adjust
void _TOD_Adjust(const struct timespec *delta)
Adjusts the Time of Time.
Definition: coretodadjust.c:24
TOD_TICKS_PER_SECOND_method
uint32_t TOD_TICKS_PER_SECOND_method(void)
Gets number of ticks in a second.
Definition: coretodtickspersec.c:25
_TOD_Lock
void _TOD_Lock(void)
Locks the time of day mutex.
Definition: coretod.c:28
_TOD_Is_set
RTEMS_INLINE_ROUTINE bool _TOD_Is_set(void)
Check if the TOD is Set.
Definition: todimpl.h:333
_Timecounter_Sbinuptime
int64_t _Timecounter_Sbinuptime(void)
Returns the uptime in the sbintime_t format.
_Timecounter_Release
#define _Timecounter_Release(lock_context)
Releases the timecounter lock.
Definition: timecounter.h:211
_Timecounter_Acquire
#define _Timecounter_Acquire(lock_context)
Lock to protect the timecounter mechanic.
Definition: timecounter.h:201
Timestamp_Control
int64_t Timestamp_Control
Definition: timestamp.h:57
Chain_Node_struct
Definition: chain.h:68
ISR_lock_Context
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:65
TOD_Control
TOD control.
Definition: todimpl.h:135
TOD_Control::is_set
bool is_set
Indicates if the time of day is set.
Definition: todimpl.h:142
TOD_Hook
Structure to manage each TOD action hook.
Definition: todimpl.h:369
TOD_Hook::handler
Status_Control(* handler)(TOD_Action, const struct timespec *)
Definition: todimpl.h:374
TOD_Hook::Node
Chain_Node Node
Definition: todimpl.h:371
timecounterimpl.h
Timecounter Implementation.
timestamp.h
Helpers for Manipulating Timestamps.
Chain_Control
Definition: chain.h:86