1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup ClassicTimerImpl |
---|
5 | * |
---|
6 | * @brief Classic Timer Implementation |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * COPYRIGHT (c) 1989-2011. |
---|
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_RTEMS_TIMER_INL |
---|
19 | #define _RTEMS_RTEMS_TIMER_INL |
---|
20 | |
---|
21 | #include <rtems/rtems/timer.h> |
---|
22 | #include <rtems/score/objectimpl.h> |
---|
23 | #include <rtems/score/thread.h> |
---|
24 | #include <rtems/score/watchdogimpl.h> |
---|
25 | |
---|
26 | #ifdef __cplusplus |
---|
27 | extern "C" { |
---|
28 | #endif |
---|
29 | |
---|
30 | /** |
---|
31 | * @defgroup ClassicTimerImpl Classic Timer Implementation |
---|
32 | * |
---|
33 | * @ingroup ClassicTimer |
---|
34 | * |
---|
35 | * @{ |
---|
36 | */ |
---|
37 | |
---|
38 | /** |
---|
39 | * @brief Instantiate RTEMS Timer Data |
---|
40 | * |
---|
41 | * This constant is defined to extern most of the time when using |
---|
42 | * this header file. However by defining it to nothing, the data |
---|
43 | * declared in this header file can be instantiated. This is done |
---|
44 | * in a single per manager file. |
---|
45 | */ |
---|
46 | #ifndef RTEMS_TIMER_EXTERN |
---|
47 | #define RTEMS_TIMER_EXTERN extern |
---|
48 | #endif |
---|
49 | |
---|
50 | typedef struct Timer_server_Control Timer_server_Control; |
---|
51 | |
---|
52 | /** |
---|
53 | * @brief Method used for task based timers. |
---|
54 | */ |
---|
55 | typedef void (*Timer_server_Method)( |
---|
56 | Timer_server_Control *timer_server, |
---|
57 | Timer_Control *timer |
---|
58 | ); |
---|
59 | |
---|
60 | typedef struct { |
---|
61 | /** |
---|
62 | * @brief This watchdog that will be registered in the system tick mechanic |
---|
63 | * for timer server wake-up. |
---|
64 | */ |
---|
65 | Watchdog_Control System_watchdog; |
---|
66 | |
---|
67 | /** |
---|
68 | * @brief Remaining delta of the system watchdog. |
---|
69 | */ |
---|
70 | Watchdog_Interval system_watchdog_delta; |
---|
71 | |
---|
72 | /** |
---|
73 | * @brief Unique identifier of the context which deals currently with the |
---|
74 | * system watchdog. |
---|
75 | */ |
---|
76 | Thread_Control *system_watchdog_helper; |
---|
77 | |
---|
78 | /** |
---|
79 | * @brief Each insert and tickle operation increases the generation count so |
---|
80 | * that the system watchdog dealer notices updates of the watchdog chain. |
---|
81 | */ |
---|
82 | uint32_t generation; |
---|
83 | |
---|
84 | /** |
---|
85 | * @brief Watchdog header managed by the timer server. |
---|
86 | */ |
---|
87 | Watchdog_Header Header; |
---|
88 | |
---|
89 | /** |
---|
90 | * @brief Last time snapshot of the timer server. |
---|
91 | * |
---|
92 | * The units may be ticks or seconds. |
---|
93 | */ |
---|
94 | Watchdog_Interval last_snapshot; |
---|
95 | |
---|
96 | /** |
---|
97 | * @brief Current time snapshot of the timer server. |
---|
98 | * |
---|
99 | * The units may be ticks or seconds. |
---|
100 | */ |
---|
101 | Watchdog_Interval current_snapshot; |
---|
102 | } Timer_server_Watchdogs; |
---|
103 | |
---|
104 | struct Timer_server_Control { |
---|
105 | /** |
---|
106 | * @brief The cancel method of the timer server. |
---|
107 | */ |
---|
108 | Timer_server_Method cancel; |
---|
109 | |
---|
110 | /** |
---|
111 | * @brief The schedule operation method of the timer server. |
---|
112 | */ |
---|
113 | Timer_server_Method schedule_operation; |
---|
114 | |
---|
115 | /** |
---|
116 | * @brief Interval watchdogs triggered by the timer server. |
---|
117 | */ |
---|
118 | Timer_server_Watchdogs Interval_watchdogs; |
---|
119 | |
---|
120 | /** |
---|
121 | * @brief TOD watchdogs triggered by the timer server. |
---|
122 | */ |
---|
123 | Timer_server_Watchdogs TOD_watchdogs; |
---|
124 | }; |
---|
125 | |
---|
126 | /** |
---|
127 | * @brief Pointer to default timer server control block. |
---|
128 | * |
---|
129 | * This value is @c NULL when the default timer server is not initialized. |
---|
130 | */ |
---|
131 | RTEMS_TIMER_EXTERN Timer_server_Control *volatile _Timer_server; |
---|
132 | |
---|
133 | /** |
---|
134 | * The following defines the information control block used to manage |
---|
135 | * this class of objects. |
---|
136 | */ |
---|
137 | RTEMS_TIMER_EXTERN Objects_Information _Timer_Information; |
---|
138 | |
---|
139 | /** |
---|
140 | * @brief Timer Manager Initialization |
---|
141 | * |
---|
142 | * This routine performs the initialization necessary for this manager. |
---|
143 | */ |
---|
144 | void _Timer_Manager_initialization(void); |
---|
145 | |
---|
146 | /** |
---|
147 | * @brief Timer_Allocate |
---|
148 | * |
---|
149 | * This function allocates a timer control block from |
---|
150 | * the inactive chain of free timer control blocks. |
---|
151 | */ |
---|
152 | RTEMS_INLINE_ROUTINE Timer_Control *_Timer_Allocate( void ) |
---|
153 | { |
---|
154 | return (Timer_Control *) _Objects_Allocate( &_Timer_Information ); |
---|
155 | } |
---|
156 | |
---|
157 | /** |
---|
158 | * @brief Timer_Free |
---|
159 | * |
---|
160 | * This routine frees a timer control block to the |
---|
161 | * inactive chain of free timer control blocks. |
---|
162 | */ |
---|
163 | RTEMS_INLINE_ROUTINE void _Timer_Free ( |
---|
164 | Timer_Control *the_timer |
---|
165 | ) |
---|
166 | { |
---|
167 | _Objects_Free( &_Timer_Information, &the_timer->Object ); |
---|
168 | } |
---|
169 | |
---|
170 | /** |
---|
171 | * @brief Timer_Get |
---|
172 | * |
---|
173 | * This function maps timer IDs to timer control blocks. |
---|
174 | * If ID corresponds to a local timer, then it returns |
---|
175 | * the timer control pointer which maps to ID and location |
---|
176 | * is set to OBJECTS_LOCAL. Otherwise, location is set |
---|
177 | * to OBJECTS_ERROR and the returned value is undefined. |
---|
178 | */ |
---|
179 | RTEMS_INLINE_ROUTINE Timer_Control *_Timer_Get ( |
---|
180 | Objects_Id id, |
---|
181 | Objects_Locations *location |
---|
182 | ) |
---|
183 | { |
---|
184 | return (Timer_Control *) |
---|
185 | _Objects_Get( &_Timer_Information, id, location ); |
---|
186 | } |
---|
187 | |
---|
188 | /** |
---|
189 | * @brief Timer_Is_interval_class |
---|
190 | * |
---|
191 | * This function returns TRUE if the class is that of an INTERVAL |
---|
192 | * timer, and FALSE otherwise. |
---|
193 | */ |
---|
194 | RTEMS_INLINE_ROUTINE bool _Timer_Is_interval_class ( |
---|
195 | Timer_Classes the_class |
---|
196 | ) |
---|
197 | { |
---|
198 | return (the_class == TIMER_INTERVAL) || (the_class == TIMER_INTERVAL_ON_TASK); |
---|
199 | } |
---|
200 | |
---|
201 | /** |
---|
202 | * @brief Timer_Is_time_of_day_class |
---|
203 | * |
---|
204 | * This function returns TRUE if the class is that of an INTERVAL |
---|
205 | * timer, and FALSE otherwise. |
---|
206 | */ |
---|
207 | RTEMS_INLINE_ROUTINE bool _Timer_Is_timer_of_day_class ( |
---|
208 | Timer_Classes the_class |
---|
209 | ) |
---|
210 | { |
---|
211 | return ( the_class == TIMER_TIME_OF_DAY ); |
---|
212 | } |
---|
213 | |
---|
214 | /** |
---|
215 | * @brief Timer_Is_dormant_class |
---|
216 | * |
---|
217 | * This function returns TRUE if the class is that of a DORMANT |
---|
218 | * timer, and FALSE otherwise. |
---|
219 | */ |
---|
220 | RTEMS_INLINE_ROUTINE bool _Timer_Is_dormant_class ( |
---|
221 | Timer_Classes the_class |
---|
222 | ) |
---|
223 | { |
---|
224 | return ( the_class == TIMER_DORMANT ); |
---|
225 | } |
---|
226 | |
---|
227 | void _Timer_Cancel( Timer_Control *the_timer ); |
---|
228 | |
---|
229 | /**@}*/ |
---|
230 | |
---|
231 | #ifdef __cplusplus |
---|
232 | } |
---|
233 | #endif |
---|
234 | |
---|
235 | #endif |
---|
236 | /* end of include file */ |
---|