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

4.115
Last change on this file since bcf536a was bcf536a, checked in by Sebastian Huber <sebastian.huber@…>, on Apr 10, 2015 at 1:51:50 PM

score: Split _Watchdog_Adjust()

Split _Watchdog_Adjust() into _Watchdog_Adjust_backward() and
_Watchdog_Adjust_forward(). Remove Watchdog_Adjust_directions,
_Watchdog_Adjust_seconds() and _Watchdog_Adjust_ticks(). This avoids to
check the same condition again.

Update #2307.

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