RTEMS 6.1-rc2
Loading...
Searching...
No Matches
todimpl.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
13/*
14 * COPYRIGHT (c) 1989-2009.
15 * On-Line Applications Research Corporation (OAR).
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
19 * are met:
20 * 1. Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39#ifndef _RTEMS_SCORE_TODIMPL_H
40#define _RTEMS_SCORE_TODIMPL_H
41
42#include <rtems/score/status.h>
47
48#include <sys/time.h>
49#include <time.h>
50
51#ifdef __cplusplus
52extern "C" {
53#endif
54
71#define TOD_SECONDS_PER_MINUTE (uint32_t)60
72
76#define TOD_MINUTES_PER_HOUR (uint32_t)60
77
81#define TOD_MONTHS_PER_YEAR (uint32_t)12
82
86#define TOD_DAYS_PER_YEAR (uint32_t)365
87
91#define TOD_HOURS_PER_DAY (uint32_t)24
92
97#define TOD_SECONDS_PER_DAY (uint32_t) (TOD_SECONDS_PER_MINUTE * \
98 TOD_MINUTES_PER_HOUR * \
99 TOD_HOURS_PER_DAY)
100
104#define TOD_SECONDS_PER_NON_LEAP_YEAR (365 * TOD_SECONDS_PER_DAY)
105
109#define TOD_MILLISECONDS_PER_SECOND (uint32_t)1000
110
114#define TOD_MICROSECONDS_PER_SECOND (uint32_t)1000000
115
119#define TOD_NANOSECONDS_PER_SECOND (uint32_t)1000000000
120
124#define TOD_NANOSECONDS_PER_MICROSECOND (uint32_t)1000
125
133#define TOD_SECONDS_1970_THROUGH_1988 \
134 (((1987 - 1970 + 1) * TOD_SECONDS_PER_NON_LEAP_YEAR) + \
135 (4 * TOD_SECONDS_PER_DAY))
136
144#define TOD_SECONDS_1970_THROUGH_2400 13569465600
145
153#define TOD_BASE_YEAR 1988
154
173#define TOD_LATEST_YEAR 2099
174
186typedef struct {
193 bool is_set;
195
199extern TOD_Control _TOD;
200
207extern const uint16_t _TOD_Days_to_date[ 2 ][ 13 ];
208
212void _TOD_Lock( void );
213
217void _TOD_Unlock( void );
218
225#if defined(RTEMS_DEBUG)
226bool _TOD_Is_owner( void );
227#endif
228
234static inline void _TOD_Acquire( ISR_lock_Context *lock_context )
235{
236 _Timecounter_Acquire( lock_context );
237}
238
244static inline void _TOD_Release( ISR_lock_Context *lock_context )
245{
246 _Timecounter_Release( lock_context );
247}
248
258static inline size_t _TOD_Get_leap_year_index( uint32_t year )
259{
260 _Assert( year % 4 != 0 || year % 100 != 0 || year % 400 == 0 );
261 return ( ( year % 4 ) + 3 ) / 4;
262}
263
273Status_Control _TOD_Is_valid_new_time_of_day( const struct timespec *tod );
274
291 const struct timespec *tod,
292 ISR_lock_Context *lock_context
293);
294
300static inline void _TOD_Get(
301 struct timespec *tod
302)
303{
304 _Timecounter_Nanotime( tod );
305}
306
317static inline void _TOD_Get_uptime(
319)
320{
321 *time = _Timecounter_Sbinuptime();
322}
323
331static inline void _TOD_Get_zero_based_uptime(
333)
334{
335 *time = _Timecounter_Sbinuptime() - SBT_1S;
336}
337
345static inline void _TOD_Get_zero_based_uptime_as_timespec(
346 struct timespec *time
347)
348{
349 _Timecounter_Nanouptime( time );
350 --time->tv_sec;
351}
352
361static inline uint32_t _TOD_Seconds_since_epoch( void )
362{
363 return (uint32_t) _Timecounter_Time_second;
364}
365
369#define TOD_TICKS_PER_SECOND _Watchdog_Ticks_per_second
370
377static inline void _TOD_Get_timeval(
378 struct timeval *time
379)
380{
381 _Timecounter_Microtime( time );
382}
383
390static inline bool _TOD_Is_set( void )
391{
392 return _TOD.is_set;
393}
394
417typedef enum {
423
427typedef struct TOD_Hook {
430
432 Status_Control ( *handler )( TOD_Action, const struct timespec * );
434
439
448 TOD_Hook *hook
449);
450
459 TOD_Hook *hook
460);
461
474 TOD_Action action,
475 const struct timespec *tod
476);
477
478
481#ifdef __cplusplus
482}
483#endif
484
485#endif
486/* end of include file */
This header file provides interfaces of the Watchdog Handler which are used by the implementation and...
#define _Assert(_e)
Assertion similar to assert() controlled via RTEMS_DEBUG instead of NDEBUG and static analysis runs.
Definition: assert.h:96
Status_Control
Status codes.
Definition: status.h:111
Status_Control _TOD_Hook_Run(TOD_Action action, const struct timespec *tod)
Run the TOD Action Hooks.
Definition: coretodhookrun.c:46
Chain_Control _TOD_Hooks
Set of registered methods for TOD Actions.
Definition: coretodhookdata.c:45
void _TOD_Hook_Unregister(TOD_Hook *hook)
Remove a TOD Action Hook.
Definition: coretodhookunregister.c:45
void _TOD_Hook_Register(TOD_Hook *hook)
Add a TOD Action Hook.
Definition: coretodhookregister.c:45
TOD_Action
Possible actions where a registered hook could be invoked.
Definition: todimpl.h:417
@ TOD_ACTION_SET_CLOCK
Constant to indicate the TOD is being set.
Definition: todimpl.h:421
Status_Control _TOD_Is_valid_new_time_of_day(const struct timespec *tod)
Checks the time point is a valid new time of day for _TOD_Set().
Definition: coretodcheck.c:44
Status_Control _TOD_Set(const struct timespec *tod, ISR_lock_Context *lock_context)
Sets the time of day.
Definition: coretodset.c:45
TOD_Control _TOD
TOD Management information.
Definition: coretod.c:44
void _TOD_Unlock(void)
Unlocks the time of day mutex.
Definition: coretod.c:53
const uint16_t _TOD_Days_to_date[2][13]
This array contains the number of days in all months up to the month indicated by the index of the se...
Definition: clocktodtoseconds.c:45
void _TOD_Lock(void)
Locks the time of day mutex.
Definition: coretod.c:48
int64_t _Timecounter_Sbinuptime(void)
Returns the uptime in the sbintime_t format.
#define _Timecounter_Release(lock_context)
Releases the timecounter lock.
Definition: timecounter.h:225
#define _Timecounter_Acquire(lock_context)
Lock to protect the timecounter mechanic.
Definition: timecounter.h:215
int64_t Timestamp_Control
Definition: timestamp.h:76
This header file provides the interfaces of the Operation Status Support.
This structure represents a chain node.
Definition: chain.h:78
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:81
TOD control.
Definition: todimpl.h:186
bool is_set
Indicates if the time of day is set.
Definition: todimpl.h:193
Structure to manage each TOD action hook.
Definition: todimpl.h:427
Status_Control(* handler)(TOD_Action, const struct timespec *)
Definition: todimpl.h:432
Chain_Node Node
Definition: todimpl.h:429
This header file provides interfaces of the Timecounter Handler which are only used by the implementa...
This header file provides interfaces of the Timestamp Handler which are used by the implementation an...
This union represents a chain control block.
Definition: chain.h:96
This header file provides the interfaces of the Watchdog Handler related to watchdog ticks which are ...