RTEMS CPU Kit with SuperCore  4.11.2
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/tod.h>
22 #include <rtems/score/timestamp.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 
132 typedef struct {
140  uint32_t seconds_trigger;
141 
148  bool is_set;
149 } TOD_Control;
150 
152 
158 void _TOD_Handler_initialization(void);
159 
169  const Timestamp_Control *tod_as_timestamp
170 );
171 
184 static inline void _TOD_Set(
185  const struct timespec *tod_as_timespec
186 )
187 {
188  Timestamp_Control tod_as_timestamp;
189 
191  &tod_as_timestamp,
192  tod_as_timespec->tv_sec,
193  tod_as_timespec->tv_nsec
194  );
195  _TOD_Set_with_timestamp( &tod_as_timestamp );
196 }
197 
203 static inline void _TOD_Get(
204  Timestamp_Control *time
205 )
206 {
207  _Timecounter_Bintime(time);
208 }
209 
215 static inline void _TOD_Get_as_timespec(
216  struct timespec *time
217 )
218 {
219  _Timecounter_Nanotime(time);
220 }
221 
232 static inline void _TOD_Get_uptime(
233  Timestamp_Control *time
234 )
235 {
236  _Timecounter_Binuptime( time );
237 }
238 
247 static inline void _TOD_Get_zero_based_uptime(
248  Timestamp_Control *time
249 )
250 {
251  _Timecounter_Binuptime( time );
252  --time->sec;
253 }
254 
262 static inline void _TOD_Get_zero_based_uptime_as_timespec(
263  struct timespec *time
264 )
265 {
266  _Timecounter_Nanouptime( time );
267  --time->tv_sec;
268 }
269 
276 static inline uint32_t _TOD_Seconds_since_epoch( void )
277 {
278  return (uint32_t) _Timecounter_Time_second;
279 }
280 
287 void _TOD_Tickle_ticks( void );
288 
297 uint32_t TOD_TICKS_PER_SECOND_method(void);
298 
307 #define TOD_TICKS_PER_SECOND TOD_TICKS_PER_SECOND_method()
308 
314  struct timeval *time
315 )
316 {
317  _Timecounter_Microtime( time );
318 }
319 
328 void _TOD_Adjust(
330 );
331 
338 {
339  return _TOD.is_set;
340 }
341 
344 #ifdef __cplusplus
345 }
346 #endif
347 
348 #endif
349 /* end of include file */
TOD control.
Definition: todimpl.h:132
void _Timecounter_Bintime(struct bintime *bt)
Returns the wall clock time in the bintime format.
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:313
void _TOD_Tickle_ticks(void)
Increments time of day at each clock tick.
Definition: coretodtickle.c:25
uint32_t seconds_trigger
Time of day seconds trigger.
Definition: todimpl.h:140
POSIX Time Types.
void _Timecounter_Binuptime(struct bintime *bt)
Returns the uptime in the bintime format.
#define RTEMS_INLINE_ROUTINE
The following (in conjunction with compiler arguments) are used to choose between the use of static i...
Definition: basedefs.h:135
Helpers for Manipulating Timestamps.
void _TOD_Handler_initialization(void)
Initializes the time of day handler.
Definition: coretod.c:23
bool is_set
Indicates if the time of day is set.
Definition: todimpl.h:148
RTEMS_INLINE_ROUTINE bool _TOD_Is_set(void)
Check if the TOD is Set.
Definition: todimpl.h:337
volatile time_t _Timecounter_Time_second
The wall clock time in seconds.
void _TOD_Set_with_timestamp(const Timestamp_Control *tod_as_timestamp)
Sets the time of day from timestamp.
Definition: coretodset.c:25
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.
uint32_t TOD_TICKS_PER_SECOND_method(void)
Gets number of ticks in a second.
Definition: coretodtickspersec.c:24
struct bintime Timestamp_Control
Define the Timestamp control type.
Definition: timestamp.h:55
Definition: rtems_bsdnet.h:233
void _Timecounter_Microtime(struct timeval *tv)
Returns the wall clock time in the timeval format.
Time of Day Handler API.
RTEMS_INLINE_ROUTINE void _Timestamp_Set(Timestamp_Control *_time, time_t _seconds, long _nanoseconds)
Set timestamp to specified seconds and nanoseconds.
Definition: timestamp.h:67
#define SCORE_EXTERN
The following ensures that all data is declared in the space of the initialization routine for either...
Definition: basedefs.h:81
void _TOD_Adjust(const Timestamp_Control timestamp)
Adjust the Time of Time.
Definition: coretodadjust.c:24