source: rtems/cpukit/score/include/rtems/score/watchdogimpl.h @ 54cf0e34

4.115
Last change on this file since 54cf0e34 was 54cf0e34, checked in by Sebastian Huber <sebastian.huber@…>, on Apr 10, 2015 at 2:19:48 PM

score: Add Watchdog_Header

This type is intended to encapsulate all state to manage a watchdog
chain.

Update #2307.

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