1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Inlined Routines in the Watchdog Handler |
---|
5 | * |
---|
6 | * This file contains the static inline implementation of all inlined |
---|
7 | * routines in the Watchdog Handler. |
---|
8 | */ |
---|
9 | |
---|
10 | /* |
---|
11 | * COPYRIGHT (c) 1989-2004. |
---|
12 | * On-Line Applications Research Corporation (OAR). |
---|
13 | * |
---|
14 | * The license and distribution terms for this file may be |
---|
15 | * found in the file LICENSE in this distribution or at |
---|
16 | * http://www.rtems.org/license/LICENSE. |
---|
17 | */ |
---|
18 | |
---|
19 | #ifndef _RTEMS_SCORE_WATCHDOGIMPL_H |
---|
20 | #define _RTEMS_SCORE_WATCHDOGIMPL_H |
---|
21 | |
---|
22 | #include <rtems/score/watchdog.h> |
---|
23 | #include <rtems/score/chainimpl.h> |
---|
24 | |
---|
25 | #ifdef __cplusplus |
---|
26 | extern "C" { |
---|
27 | #endif |
---|
28 | |
---|
29 | /** |
---|
30 | * @addtogroup ScoreWatchdog |
---|
31 | * @{ |
---|
32 | */ |
---|
33 | |
---|
34 | /** |
---|
35 | * @brief Control block used to manage intervals. |
---|
36 | * |
---|
37 | * The following type defines the control block used to manage |
---|
38 | * intervals. |
---|
39 | */ |
---|
40 | #define WATCHDOG_MAXIMUM_INTERVAL ((Watchdog_Interval) 0xffffffff) |
---|
41 | |
---|
42 | /** |
---|
43 | * @brief Watchdog initializer for static initialization. |
---|
44 | * |
---|
45 | * @see _Watchdog_Initialize(). |
---|
46 | */ |
---|
47 | #define WATCHDOG_INITIALIZER( routine, id, user_data ) \ |
---|
48 | { \ |
---|
49 | { NULL, NULL }, \ |
---|
50 | WATCHDOG_INACTIVE, \ |
---|
51 | 0, 0, 0, 0, \ |
---|
52 | ( routine ), ( id ), ( user_data ) \ |
---|
53 | } |
---|
54 | |
---|
55 | /** |
---|
56 | * @brief the manner in which a watchdog chain may |
---|
57 | * be adjusted by the @ref _Watchdog_Adjust routine. |
---|
58 | * |
---|
59 | * The following enumerated type details the manner in which |
---|
60 | * a watchdog chain may be adjusted by the @ref _Watchdog_Adjust |
---|
61 | * routine. The direction indicates a movement FORWARD |
---|
62 | * or BACKWARD in time. |
---|
63 | */ |
---|
64 | typedef enum { |
---|
65 | /** adjust delta value forward */ |
---|
66 | WATCHDOG_FORWARD, |
---|
67 | /** adjust delta value backward */ |
---|
68 | WATCHDOG_BACKWARD |
---|
69 | } Watchdog_Adjust_directions; |
---|
70 | |
---|
71 | /** |
---|
72 | * @brief Watchdog synchronization level. |
---|
73 | * |
---|
74 | * This used for synchronization purposes |
---|
75 | * during an insert on a watchdog delta chain. |
---|
76 | */ |
---|
77 | SCORE_EXTERN volatile uint32_t _Watchdog_Sync_level; |
---|
78 | |
---|
79 | /** |
---|
80 | * @brief Watchdog synchronization count. |
---|
81 | * |
---|
82 | * This used for synchronization purposes |
---|
83 | * during an insert on a watchdog delta chain. |
---|
84 | */ |
---|
85 | SCORE_EXTERN volatile uint32_t _Watchdog_Sync_count; |
---|
86 | |
---|
87 | /** |
---|
88 | * @brief Watchdog chain which is managed at ticks. |
---|
89 | * |
---|
90 | * This is the watchdog chain which is managed at ticks. |
---|
91 | */ |
---|
92 | SCORE_EXTERN Chain_Control _Watchdog_Ticks_chain; |
---|
93 | |
---|
94 | /** |
---|
95 | * @brief Watchdog chain which is managed at second boundaries. |
---|
96 | * |
---|
97 | * This is the watchdog chain which is managed at second boundaries. |
---|
98 | */ |
---|
99 | SCORE_EXTERN Chain_Control _Watchdog_Seconds_chain; |
---|
100 | |
---|
101 | /** |
---|
102 | * @brief Initialize the watchdog handler. |
---|
103 | * |
---|
104 | * This routine initializes the watchdog handler. The watchdog |
---|
105 | * synchronization flag is initialized and the watchdog chains are |
---|
106 | * initialized and emptied. |
---|
107 | */ |
---|
108 | void _Watchdog_Handler_initialization( void ); |
---|
109 | |
---|
110 | /** |
---|
111 | * @brief Removes @a the_watchdog from the watchdog chain. |
---|
112 | * |
---|
113 | * This routine removes @a the_watchdog from the watchdog chain on which |
---|
114 | * it resides and returns the state @a the_watchdog timer was in. |
---|
115 | * |
---|
116 | * @param[in] the_watchdog will be removed |
---|
117 | * @retval the state in which @a the_watchdog was in when removed |
---|
118 | */ |
---|
119 | Watchdog_States _Watchdog_Remove ( |
---|
120 | Watchdog_Control *the_watchdog |
---|
121 | ); |
---|
122 | |
---|
123 | /** |
---|
124 | * @brief Adjusts the @a header watchdog chain in the forward |
---|
125 | * or backward @a direction for @a units ticks. |
---|
126 | * |
---|
127 | * This routine adjusts the @a header watchdog chain in the forward |
---|
128 | * or backward @a direction for @a units ticks. |
---|
129 | * |
---|
130 | * @param[in] header is the watchdog chain to adjust |
---|
131 | * @param[in] direction is the direction to adjust @a header |
---|
132 | * @param[in] units is the number of units to adjust @a header |
---|
133 | */ |
---|
134 | void _Watchdog_Adjust ( |
---|
135 | Chain_Control *header, |
---|
136 | Watchdog_Adjust_directions direction, |
---|
137 | Watchdog_Interval units |
---|
138 | ); |
---|
139 | |
---|
140 | /** |
---|
141 | * @brief Adjusts the @a header watchdog chain in the forward |
---|
142 | * @a direction for @a units_arg ticks. |
---|
143 | * |
---|
144 | * This routine adjusts the @a header watchdog chain in the forward |
---|
145 | * @a direction for @a units_arg ticks. |
---|
146 | * |
---|
147 | * @param[in] header is the watchdog chain to adjust |
---|
148 | * @param[in] units_arg is the number of units to adjust @a header |
---|
149 | * @param[in] to_fire is a pointer to an initialized Chain_Control to which |
---|
150 | * all watchdog instances that are to be fired will be placed. |
---|
151 | * |
---|
152 | * @note This always adjusts forward. |
---|
153 | */ |
---|
154 | void _Watchdog_Adjust_to_chain( |
---|
155 | Chain_Control *header, |
---|
156 | Watchdog_Interval units_arg, |
---|
157 | Chain_Control *to_fire |
---|
158 | |
---|
159 | ); |
---|
160 | |
---|
161 | /** |
---|
162 | * @brief Inserts @a the_watchdog into the @a header watchdog chain |
---|
163 | * for a time of @a units. |
---|
164 | * |
---|
165 | * This routine inserts @a the_watchdog into the @a header watchdog chain |
---|
166 | * for a time of @a units. |
---|
167 | * Update the delta interval counters. |
---|
168 | * |
---|
169 | * @param[in] header is @a the_watchdog list to insert @a the_watchdog on |
---|
170 | * @param[in] the_watchdog is the watchdog to insert |
---|
171 | */ |
---|
172 | void _Watchdog_Insert ( |
---|
173 | Chain_Control *header, |
---|
174 | Watchdog_Control *the_watchdog |
---|
175 | ); |
---|
176 | |
---|
177 | /** |
---|
178 | * @brief This routine is invoked at appropriate intervals to update |
---|
179 | * the @a header watchdog chain. |
---|
180 | * |
---|
181 | * This routine is invoked at appropriate intervals to update |
---|
182 | * the @a header watchdog chain. |
---|
183 | * This routine decrements the delta counter in response to a tick. |
---|
184 | * |
---|
185 | * @param[in] header is the watchdog chain to tickle |
---|
186 | */ |
---|
187 | void _Watchdog_Tickle ( |
---|
188 | Chain_Control *header |
---|
189 | ); |
---|
190 | |
---|
191 | /** |
---|
192 | * This routine initializes the specified watchdog. The watchdog is |
---|
193 | * made inactive, the watchdog id and handler routine are set to the |
---|
194 | * specified values. |
---|
195 | */ |
---|
196 | |
---|
197 | RTEMS_INLINE_ROUTINE void _Watchdog_Initialize( |
---|
198 | Watchdog_Control *the_watchdog, |
---|
199 | Watchdog_Service_routine_entry routine, |
---|
200 | Objects_Id id, |
---|
201 | void *user_data |
---|
202 | ) |
---|
203 | { |
---|
204 | the_watchdog->state = WATCHDOG_INACTIVE; |
---|
205 | the_watchdog->routine = routine; |
---|
206 | the_watchdog->id = id; |
---|
207 | the_watchdog->user_data = user_data; |
---|
208 | } |
---|
209 | |
---|
210 | /** |
---|
211 | * This routine returns true if the watchdog timer is in the ACTIVE |
---|
212 | * state, and false otherwise. |
---|
213 | */ |
---|
214 | |
---|
215 | RTEMS_INLINE_ROUTINE bool _Watchdog_Is_active( |
---|
216 | Watchdog_Control *the_watchdog |
---|
217 | ) |
---|
218 | { |
---|
219 | |
---|
220 | return ( the_watchdog->state == WATCHDOG_ACTIVE ); |
---|
221 | |
---|
222 | } |
---|
223 | |
---|
224 | /** |
---|
225 | * This routine activates THE_WATCHDOG timer which is already |
---|
226 | * on a watchdog chain. |
---|
227 | */ |
---|
228 | |
---|
229 | RTEMS_INLINE_ROUTINE void _Watchdog_Activate( |
---|
230 | Watchdog_Control *the_watchdog |
---|
231 | ) |
---|
232 | { |
---|
233 | |
---|
234 | the_watchdog->state = WATCHDOG_ACTIVE; |
---|
235 | |
---|
236 | } |
---|
237 | |
---|
238 | /** |
---|
239 | * This routine deactivates THE_WATCHDOG timer which will remain |
---|
240 | * on a watchdog chain. |
---|
241 | */ |
---|
242 | |
---|
243 | RTEMS_INLINE_ROUTINE void _Watchdog_Deactivate( |
---|
244 | Watchdog_Control *the_watchdog |
---|
245 | ) |
---|
246 | { |
---|
247 | |
---|
248 | the_watchdog->state = WATCHDOG_REMOVE_IT; |
---|
249 | |
---|
250 | } |
---|
251 | |
---|
252 | /** |
---|
253 | * This routine is invoked at each clock tick to update the ticks |
---|
254 | * watchdog chain. |
---|
255 | */ |
---|
256 | |
---|
257 | RTEMS_INLINE_ROUTINE void _Watchdog_Tickle_ticks( void ) |
---|
258 | { |
---|
259 | |
---|
260 | _Watchdog_Tickle( &_Watchdog_Ticks_chain ); |
---|
261 | |
---|
262 | } |
---|
263 | |
---|
264 | /** |
---|
265 | * This routine is invoked at each clock tick to update the seconds |
---|
266 | * watchdog chain. |
---|
267 | */ |
---|
268 | |
---|
269 | RTEMS_INLINE_ROUTINE void _Watchdog_Tickle_seconds( void ) |
---|
270 | { |
---|
271 | |
---|
272 | _Watchdog_Tickle( &_Watchdog_Seconds_chain ); |
---|
273 | |
---|
274 | } |
---|
275 | |
---|
276 | /** |
---|
277 | * This routine inserts THE_WATCHDOG into the ticks watchdog chain |
---|
278 | * for a time of UNITS ticks. The INSERT_MODE indicates whether |
---|
279 | * THE_WATCHDOG is to be activated automatically or later, explicitly |
---|
280 | * by the caller. |
---|
281 | */ |
---|
282 | |
---|
283 | RTEMS_INLINE_ROUTINE void _Watchdog_Insert_ticks( |
---|
284 | Watchdog_Control *the_watchdog, |
---|
285 | Watchdog_Interval units |
---|
286 | ) |
---|
287 | { |
---|
288 | |
---|
289 | the_watchdog->initial = units; |
---|
290 | |
---|
291 | _Watchdog_Insert( &_Watchdog_Ticks_chain, the_watchdog ); |
---|
292 | |
---|
293 | } |
---|
294 | |
---|
295 | /** |
---|
296 | * This routine inserts THE_WATCHDOG into the seconds watchdog chain |
---|
297 | * for a time of UNITS seconds. The INSERT_MODE indicates whether |
---|
298 | * THE_WATCHDOG is to be activated automatically or later, explicitly |
---|
299 | * by the caller. |
---|
300 | */ |
---|
301 | |
---|
302 | RTEMS_INLINE_ROUTINE void _Watchdog_Insert_seconds( |
---|
303 | Watchdog_Control *the_watchdog, |
---|
304 | Watchdog_Interval units |
---|
305 | ) |
---|
306 | { |
---|
307 | |
---|
308 | the_watchdog->initial = units; |
---|
309 | |
---|
310 | _Watchdog_Insert( &_Watchdog_Seconds_chain, the_watchdog ); |
---|
311 | |
---|
312 | } |
---|
313 | |
---|
314 | /** |
---|
315 | * This routine adjusts the seconds watchdog chain in the forward |
---|
316 | * or backward DIRECTION for UNITS seconds. This is invoked when the |
---|
317 | * current time of day is changed. |
---|
318 | */ |
---|
319 | |
---|
320 | RTEMS_INLINE_ROUTINE void _Watchdog_Adjust_seconds( |
---|
321 | Watchdog_Adjust_directions direction, |
---|
322 | Watchdog_Interval units |
---|
323 | ) |
---|
324 | { |
---|
325 | |
---|
326 | _Watchdog_Adjust( &_Watchdog_Seconds_chain, direction, units ); |
---|
327 | |
---|
328 | } |
---|
329 | |
---|
330 | /** |
---|
331 | * This routine adjusts the ticks watchdog chain in the forward |
---|
332 | * or backward DIRECTION for UNITS ticks. |
---|
333 | */ |
---|
334 | |
---|
335 | RTEMS_INLINE_ROUTINE void _Watchdog_Adjust_ticks( |
---|
336 | Watchdog_Adjust_directions direction, |
---|
337 | Watchdog_Interval units |
---|
338 | ) |
---|
339 | { |
---|
340 | |
---|
341 | _Watchdog_Adjust( &_Watchdog_Ticks_chain, direction, units ); |
---|
342 | |
---|
343 | } |
---|
344 | |
---|
345 | /** |
---|
346 | * This routine resets THE_WATCHDOG timer to its state at INSERT |
---|
347 | * time. This routine is valid only on interval watchdog timers |
---|
348 | * and is used to make an interval watchdog timer fire "every" so |
---|
349 | * many ticks. |
---|
350 | */ |
---|
351 | |
---|
352 | RTEMS_INLINE_ROUTINE void _Watchdog_Reset( |
---|
353 | Watchdog_Control *the_watchdog |
---|
354 | ) |
---|
355 | { |
---|
356 | |
---|
357 | (void) _Watchdog_Remove( the_watchdog ); |
---|
358 | |
---|
359 | _Watchdog_Insert( &_Watchdog_Ticks_chain, the_watchdog ); |
---|
360 | |
---|
361 | } |
---|
362 | |
---|
363 | /** |
---|
364 | * This routine returns a pointer to the watchdog timer following |
---|
365 | * THE_WATCHDOG on the watchdog chain. |
---|
366 | */ |
---|
367 | |
---|
368 | RTEMS_INLINE_ROUTINE Watchdog_Control *_Watchdog_Next( |
---|
369 | Watchdog_Control *the_watchdog |
---|
370 | ) |
---|
371 | { |
---|
372 | |
---|
373 | return ( (Watchdog_Control *) the_watchdog->Node.next ); |
---|
374 | |
---|
375 | } |
---|
376 | |
---|
377 | /** |
---|
378 | * This routine returns a pointer to the watchdog timer preceding |
---|
379 | * THE_WATCHDOG on the watchdog chain. |
---|
380 | */ |
---|
381 | |
---|
382 | RTEMS_INLINE_ROUTINE Watchdog_Control *_Watchdog_Previous( |
---|
383 | Watchdog_Control *the_watchdog |
---|
384 | ) |
---|
385 | { |
---|
386 | |
---|
387 | return ( (Watchdog_Control *) the_watchdog->Node.previous ); |
---|
388 | |
---|
389 | } |
---|
390 | |
---|
391 | /** |
---|
392 | * This routine returns a pointer to the first watchdog timer |
---|
393 | * on the watchdog chain HEADER. |
---|
394 | */ |
---|
395 | |
---|
396 | RTEMS_INLINE_ROUTINE Watchdog_Control *_Watchdog_First( |
---|
397 | Chain_Control *header |
---|
398 | ) |
---|
399 | { |
---|
400 | |
---|
401 | return ( (Watchdog_Control *) _Chain_First( header ) ); |
---|
402 | |
---|
403 | } |
---|
404 | |
---|
405 | /** |
---|
406 | * This routine returns a pointer to the last watchdog timer |
---|
407 | * on the watchdog chain HEADER. |
---|
408 | */ |
---|
409 | |
---|
410 | RTEMS_INLINE_ROUTINE Watchdog_Control *_Watchdog_Last( |
---|
411 | Chain_Control *header |
---|
412 | ) |
---|
413 | { |
---|
414 | |
---|
415 | return ( (Watchdog_Control *) _Chain_Last( header ) ); |
---|
416 | |
---|
417 | } |
---|
418 | |
---|
419 | /** @} */ |
---|
420 | |
---|
421 | #ifdef __cplusplus |
---|
422 | } |
---|
423 | #endif |
---|
424 | |
---|
425 | #endif |
---|
426 | /* end of include file */ |
---|