source: rtems/cpukit/score/include/rtems/score/watchdogimpl.h @ fd53d25

4.115
Last change on this file since fd53d25 was fd53d25, checked in by Sebastian Huber <sebastian.huber@…>, on 04/24/15 at 07:53:58

score: Move _Watchdog_Tickle()

Make internal function _Watchdog_Remove_it() static to avoid accidental
usage.

Update #2307.

  • Property mode set to 100644
File size: 10.3 KB
Line 
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#include <rtems/score/isrlock.h>
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30/**
31 *  @addtogroup ScoreWatchdog
32 *  @{
33 */
34
35/**
36 * @brief Watchdog initializer for static initialization.
37 *
38 * @see _Watchdog_Initialize().
39 */
40#define WATCHDOG_INITIALIZER( routine, id, user_data ) \
41  { \
42    { NULL, NULL }, \
43    WATCHDOG_INACTIVE, \
44    0, 0, 0, 0, \
45    ( routine ), ( id ), ( user_data ) \
46  }
47
48/**
49 * @brief Iterator item to synchronize concurrent insert, remove and tickle
50 * operations.
51 */
52typedef struct {
53  /**
54   * @brief A node for a Watchdog_Header::Iterators chain.
55   */
56  Chain_Node Node;
57
58  /**
59   * @brief The current delta interval of the new watchdog to insert.
60   */
61  Watchdog_Interval delta_interval;
62
63  /**
64   * @brief The current watchdog of the chain on the way to insert the new
65   * watchdog.
66   */
67  Chain_Node *current;
68} Watchdog_Iterator;
69
70/**
71 * @brief Watchdog header.
72 */
73typedef struct {
74  /**
75   * @brief ISR lock to protect this watchdog chain.
76   */
77  ISR_LOCK_MEMBER( Lock )
78
79  /**
80   * @brief The chain of active or transient watchdogs.
81   */
82  Chain_Control Watchdogs;
83
84  /**
85   * @brief Currently active iterators.
86   *
87   * The iterators are registered in _Watchdog_Insert() and updated in case the
88   * watchdog chain changes.
89   */
90  Chain_Control Iterators;
91} Watchdog_Header;
92
93/**
94 *  @brief Watchdog chain which is managed at ticks.
95 *
96 *  This is the watchdog chain which is managed at ticks.
97 */
98SCORE_EXTERN Watchdog_Header _Watchdog_Ticks_header;
99
100/**
101 *  @brief Watchdog chain which is managed at second boundaries.
102 *
103 *  This is the watchdog chain which is managed at second boundaries.
104 */
105SCORE_EXTERN Watchdog_Header _Watchdog_Seconds_header;
106
107RTEMS_INLINE_ROUTINE void _Watchdog_Acquire(
108  Watchdog_Header  *header,
109  ISR_lock_Context *lock_context
110)
111{
112  _ISR_lock_ISR_disable_and_acquire( &header->Lock, lock_context );
113}
114
115RTEMS_INLINE_ROUTINE void _Watchdog_Release(
116  Watchdog_Header  *header,
117  ISR_lock_Context *lock_context
118)
119{
120  _ISR_lock_Release_and_ISR_enable( &header->Lock, lock_context );
121}
122
123RTEMS_INLINE_ROUTINE void _Watchdog_Flash(
124  Watchdog_Header  *header,
125  ISR_lock_Context *lock_context
126)
127{
128  _ISR_lock_Flash( &header->Lock, lock_context );
129}
130
131/**
132 *  @brief Initialize the watchdog handler.
133 *
134 *  This routine initializes the watchdog handler.  The watchdog
135 *  synchronization flag is initialized and the watchdog chains are
136 *  initialized and emptied.
137 */
138void _Watchdog_Handler_initialization( void );
139
140/**
141 *  @brief Removes @a the_watchdog from the watchdog chain.
142 *
143 *  This routine removes @a the_watchdog from the watchdog chain on which
144 *  it resides and returns the state @a the_watchdog timer was in.
145 *
146 *  @param[in] header The watchdog chain.
147 *  @param[in] the_watchdog will be removed
148 *  @retval the state in which @a the_watchdog was in when removed
149 */
150Watchdog_States _Watchdog_Remove (
151  Watchdog_Header  *header,
152  Watchdog_Control *the_watchdog
153);
154
155/**
156 *  @brief Adjusts the header watchdog chain in the backward direction for
157 *  units ticks.
158 *
159 *  @param[in] header The watchdog chain.
160 *  @param[in] units The units of ticks to adjust.
161 */
162void _Watchdog_Adjust_backward(
163  Watchdog_Header   *header,
164  Watchdog_Interval  units
165);
166
167/**
168 *  @brief Adjusts the header watchdog chain in the forward direction for units
169 *  ticks.
170 *
171 *  This may lead to several _Watchdog_Tickle() invocations.
172 *
173 *  @param[in] header The watchdog chain.
174 *  @param[in] units The units of ticks to adjust.
175 */
176void _Watchdog_Adjust_forward(
177  Watchdog_Header   *header,
178  Watchdog_Interval  units
179);
180
181/**
182 *  @brief Adjusts the @a header watchdog chain in the forward
183 *  @a direction for @a units_arg ticks.
184 *
185 *  This routine adjusts the @a header watchdog chain in the forward
186 *  @a direction for @a units_arg ticks.
187 *
188 *  @param[in] header is the watchdog chain to adjust
189 *  @param[in] units_arg is the number of units to adjust @a header
190 *  @param[in] to_fire is a pointer to an initialized Chain_Control to which
191 *             all watchdog instances that are to be fired will be placed.
192 *
193 *  @note This always adjusts forward.
194 */
195void _Watchdog_Adjust_to_chain(
196  Watchdog_Header   *header,
197  Watchdog_Interval  units_arg,
198  Chain_Control     *to_fire
199
200);
201
202/**
203 *  @brief Inserts @a the_watchdog into the @a header watchdog chain
204 *  for a time of @a units.
205 *
206 *  This routine inserts @a the_watchdog into the @a header watchdog chain
207 *  for a time of @a units.
208 *  Update the delta interval counters.
209 *
210 *  @param[in] header is @a the_watchdog list to insert @a the_watchdog on
211 *  @param[in] the_watchdog is the watchdog to insert
212 */
213void _Watchdog_Insert (
214  Watchdog_Header  *header,
215  Watchdog_Control *the_watchdog
216);
217
218/**
219 *  @brief This routine is invoked at appropriate intervals to update
220 *  the @a header watchdog chain.
221 *
222 *  This routine is invoked at appropriate intervals to update
223 *  the @a header watchdog chain.
224 *  This routine decrements the delta counter in response to a tick.
225 *
226 *  @param[in] header is the watchdog chain to tickle
227 */
228void _Watchdog_Tickle (
229  Watchdog_Header *header
230);
231
232/**
233 * This routine initializes the specified watchdog.  The watchdog is
234 * made inactive, the watchdog id and handler routine are set to the
235 * specified values.
236 */
237
238RTEMS_INLINE_ROUTINE void _Watchdog_Initialize(
239  Watchdog_Control               *the_watchdog,
240  Watchdog_Service_routine_entry  routine,
241  Objects_Id                      id,
242  void                           *user_data
243)
244{
245  the_watchdog->state     = WATCHDOG_INACTIVE;
246  the_watchdog->routine   = routine;
247  the_watchdog->id        = id;
248  the_watchdog->user_data = user_data;
249}
250
251/**
252 * This routine returns true if the watchdog timer is in the ACTIVE
253 * state, and false otherwise.
254 */
255
256RTEMS_INLINE_ROUTINE bool _Watchdog_Is_active(
257  Watchdog_Control *the_watchdog
258)
259{
260
261  return ( the_watchdog->state == WATCHDOG_ACTIVE );
262
263}
264
265/**
266 * This routine activates THE_WATCHDOG timer which is already
267 * on a watchdog chain.
268 */
269
270RTEMS_INLINE_ROUTINE void _Watchdog_Activate(
271  Watchdog_Control *the_watchdog
272)
273{
274
275  the_watchdog->state = WATCHDOG_ACTIVE;
276
277}
278
279/**
280 * This routine deactivates THE_WATCHDOG timer which will remain
281 * on a watchdog chain.
282 */
283
284RTEMS_INLINE_ROUTINE void _Watchdog_Deactivate(
285  Watchdog_Control *the_watchdog
286)
287{
288
289  the_watchdog->state = WATCHDOG_REMOVE_IT;
290
291}
292
293/**
294 * This routine is invoked at each clock tick to update the ticks
295 * watchdog chain.
296 */
297
298RTEMS_INLINE_ROUTINE void _Watchdog_Tickle_ticks( void )
299{
300
301  _Watchdog_Tickle( &_Watchdog_Ticks_header );
302
303}
304
305/**
306 * This routine is invoked at each clock tick to update the seconds
307 * watchdog chain.
308 */
309
310RTEMS_INLINE_ROUTINE void _Watchdog_Tickle_seconds( void )
311{
312
313  _Watchdog_Tickle( &_Watchdog_Seconds_header );
314
315}
316
317/**
318 * This routine inserts THE_WATCHDOG into the ticks watchdog chain
319 * for a time of UNITS ticks.  The INSERT_MODE indicates whether
320 * THE_WATCHDOG is to be activated automatically or later, explicitly
321 * by the caller.
322 */
323
324RTEMS_INLINE_ROUTINE void _Watchdog_Insert_ticks(
325  Watchdog_Control      *the_watchdog,
326  Watchdog_Interval      units
327)
328{
329
330  the_watchdog->initial = units;
331
332  _Watchdog_Insert( &_Watchdog_Ticks_header, the_watchdog );
333
334}
335
336/**
337 * This routine inserts THE_WATCHDOG into the seconds watchdog chain
338 * for a time of UNITS seconds.  The INSERT_MODE indicates whether
339 * THE_WATCHDOG is to be activated automatically or later, explicitly
340 * by the caller.
341 */
342
343RTEMS_INLINE_ROUTINE void _Watchdog_Insert_seconds(
344  Watchdog_Control      *the_watchdog,
345  Watchdog_Interval      units
346)
347{
348
349  the_watchdog->initial = units;
350
351  _Watchdog_Insert( &_Watchdog_Seconds_header, the_watchdog );
352
353}
354
355RTEMS_INLINE_ROUTINE Watchdog_States _Watchdog_Remove_ticks(
356  Watchdog_Control *the_watchdog
357)
358{
359  return _Watchdog_Remove( &_Watchdog_Ticks_header, the_watchdog );
360}
361
362RTEMS_INLINE_ROUTINE Watchdog_States _Watchdog_Remove_seconds(
363  Watchdog_Control *the_watchdog
364)
365{
366  return _Watchdog_Remove( &_Watchdog_Seconds_header, the_watchdog );
367}
368
369/**
370 * This routine resets THE_WATCHDOG timer to its state at INSERT
371 * time.  This routine is valid only on interval watchdog timers
372 * and is used to make an interval watchdog timer fire "every" so
373 * many ticks.
374 */
375
376RTEMS_INLINE_ROUTINE void _Watchdog_Reset_ticks(
377  Watchdog_Control *the_watchdog
378)
379{
380
381  _Watchdog_Remove_ticks( the_watchdog );
382
383  _Watchdog_Insert( &_Watchdog_Ticks_header, the_watchdog );
384
385}
386
387/**
388 * This routine returns a pointer to the watchdog timer following
389 * THE_WATCHDOG on the watchdog chain.
390 */
391
392RTEMS_INLINE_ROUTINE Watchdog_Control *_Watchdog_Next(
393  Watchdog_Control *the_watchdog
394)
395{
396
397  return ( (Watchdog_Control *) the_watchdog->Node.next );
398
399}
400
401/**
402 * This routine returns a pointer to the watchdog timer preceding
403 * THE_WATCHDOG on the watchdog chain.
404 */
405
406RTEMS_INLINE_ROUTINE Watchdog_Control *_Watchdog_Previous(
407  Watchdog_Control *the_watchdog
408)
409{
410
411  return ( (Watchdog_Control *) the_watchdog->Node.previous );
412
413}
414
415/**
416 * This routine returns a pointer to the first watchdog timer
417 * on the watchdog chain HEADER.
418 */
419
420RTEMS_INLINE_ROUTINE Watchdog_Control *_Watchdog_First(
421  Watchdog_Header *header
422)
423{
424
425  return ( (Watchdog_Control *) _Chain_First( &header->Watchdogs ) );
426
427}
428
429/**
430 * This routine returns a pointer to the last watchdog timer
431 * on the watchdog chain HEADER.
432 */
433
434RTEMS_INLINE_ROUTINE Watchdog_Control *_Watchdog_Last(
435  Watchdog_Header *header
436)
437{
438
439  return ( (Watchdog_Control *) _Chain_Last( &header->Watchdogs ) );
440
441}
442
443RTEMS_INLINE_ROUTINE bool _Watchdog_Is_empty(
444  const Watchdog_Header *header
445)
446{
447  return _Chain_Is_empty( &header->Watchdogs );
448}
449
450RTEMS_INLINE_ROUTINE void _Watchdog_Header_initialize(
451  Watchdog_Header *header
452)
453{
454  _ISR_lock_Initialize( &header->Lock, "Watchdog" );
455  _Chain_Initialize_empty( &header->Watchdogs );
456  _Chain_Initialize_empty( &header->Iterators );
457}
458
459/** @} */
460
461#ifdef __cplusplus
462}
463#endif
464
465#endif
466/* end of include file */
Note: See TracBrowser for help on using the repository browser.