1 | /** |
---|
2 | * @file rtems/score/tod.inl |
---|
3 | * |
---|
4 | * This file contains the static inline implementation of the inlined routines |
---|
5 | * from the Time of Day Handler. |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2007. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.com/license/LICENSE. |
---|
15 | * |
---|
16 | * $Id$ |
---|
17 | */ |
---|
18 | |
---|
19 | #ifndef _RTEMS_SCORE_TOD_INL |
---|
20 | #define _RTEMS_SCORE_TOD_INL |
---|
21 | |
---|
22 | #include <rtems/score/isr.h> |
---|
23 | |
---|
24 | /** |
---|
25 | * @addtogroup ScoreTOD |
---|
26 | * @{ |
---|
27 | */ |
---|
28 | |
---|
29 | /** |
---|
30 | * |
---|
31 | * This routines adds two timespecs. The second argument is added |
---|
32 | * to the first. |
---|
33 | */ |
---|
34 | |
---|
35 | RTEMS_INLINE_ROUTINE uint32_t _TOD_Add_timespec( |
---|
36 | struct timespec *time, |
---|
37 | struct timespec *add |
---|
38 | ) |
---|
39 | { |
---|
40 | uint32_t seconds = 0; |
---|
41 | |
---|
42 | |
---|
43 | /* Add the basics */ |
---|
44 | time->tv_sec += add->tv_sec; |
---|
45 | time->tv_nsec += add->tv_nsec; |
---|
46 | |
---|
47 | /* Now adjust it so nanoseconds is in range */ |
---|
48 | while ( time->tv_nsec >= TOD_NANOSECONDS_PER_SECOND ) { |
---|
49 | time->tv_nsec -= TOD_NANOSECONDS_PER_SECOND; |
---|
50 | time->tv_sec++; |
---|
51 | seconds++; |
---|
52 | } |
---|
53 | |
---|
54 | return seconds; |
---|
55 | } |
---|
56 | |
---|
57 | /** |
---|
58 | * This routine increments the ticks field of the current time of |
---|
59 | * day at each clock tick. |
---|
60 | */ |
---|
61 | |
---|
62 | RTEMS_INLINE_ROUTINE void _TOD_Tickle_ticks( void ) |
---|
63 | { |
---|
64 | struct timespec tick; |
---|
65 | uint32_t seconds; |
---|
66 | |
---|
67 | /* Convert the tick quantum to a timespec */ |
---|
68 | tick.tv_nsec = _TOD_Microseconds_per_tick * 1000; |
---|
69 | tick.tv_sec = 0; |
---|
70 | |
---|
71 | /* Update the counter of ticks since boot */ |
---|
72 | _Watchdog_Ticks_since_boot += 1; |
---|
73 | |
---|
74 | /* Update the timespec format uptime */ |
---|
75 | (void) _TOD_Add_timespec( &_TOD_Uptime, &tick ); |
---|
76 | /* we do not care how much the uptime changed */ |
---|
77 | |
---|
78 | /* Update the timespec format TOD */ |
---|
79 | seconds = _TOD_Add_timespec( &_TOD_Now, &tick ); |
---|
80 | while ( seconds ) { |
---|
81 | _Watchdog_Tickle_seconds(); |
---|
82 | seconds--; |
---|
83 | } |
---|
84 | } |
---|
85 | |
---|
86 | /** |
---|
87 | * This routine deactivates updating of the current time of day. |
---|
88 | */ |
---|
89 | |
---|
90 | RTEMS_INLINE_ROUTINE void _TOD_Deactivate( void ) |
---|
91 | { |
---|
92 | /* XXX do we need something now that we are using timespec for TOD */ |
---|
93 | } |
---|
94 | |
---|
95 | /** |
---|
96 | * This routine activates updating of the current time of day. |
---|
97 | */ |
---|
98 | |
---|
99 | RTEMS_INLINE_ROUTINE void _TOD_Activate( |
---|
100 | Watchdog_Interval ticks |
---|
101 | ) |
---|
102 | { |
---|
103 | /* XXX do we need something now that we are using timespec for TOD */ |
---|
104 | } |
---|
105 | |
---|
106 | /** |
---|
107 | * This routine returns a timeval based upon the internal timespec format TOD. |
---|
108 | */ |
---|
109 | |
---|
110 | RTEMS_INLINE_ROUTINE void _TOD_Get_timeval( |
---|
111 | struct timeval *time |
---|
112 | ) |
---|
113 | { |
---|
114 | ISR_Level level; |
---|
115 | struct timespec now; |
---|
116 | |
---|
117 | _ISR_Disable(level); |
---|
118 | _TOD_Get( &now ); |
---|
119 | _ISR_Enable(level); |
---|
120 | |
---|
121 | time->tv_sec = now.tv_sec; |
---|
122 | time->tv_usec = now.tv_nsec / TOD_NANOSECONDS_PER_MICROSECOND; |
---|
123 | } |
---|
124 | |
---|
125 | /**@}*/ |
---|
126 | |
---|
127 | #endif |
---|
128 | /* end of include file */ |
---|