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

4.115
Last change on this file since 2903090 was 2903090, checked in by Sebastian Huber <sebastian.huber@…>, on 04/15/15 at 09:26:46

score: Add header to _Watchdog_Remove()

Add watchdog header parameter to _Watchdog_Remove() to be in line with
the other operations. Add _Watchdog_Remove_ticks() and
_Watchdog_Remove_seconds() for convenience.

Update #2307.

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