source: rtems/cpukit/score/src/watchdogtickle.c @ e3f6d35

4.10
Last change on this file since e3f6d35 was 28352fae, checked in by Ralf Corsepius <ralf.corsepius@…>, on 11/29/09 at 13:51:53

Whitespace removal.

  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*
2 *  Watchdog Handler
3 *
4 *
5 *  COPYRIGHT (c) 1989-1999.
6 *  On-Line Applications Research Corporation (OAR).
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.rtems.com/license/LICENSE.
11 *
12 *  $Id$
13 */
14
15#if HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#include <rtems/system.h>
20#include <rtems/score/isr.h>
21#include <rtems/score/watchdog.h>
22
23/*PAGE
24 *
25 *  _Watchdog_Tickle
26 *
27 *  This routine decrements the delta counter in response to a tick.  The
28 *  delta chain is updated accordingly.
29 *
30 *  Input parameters:
31 *    header - pointer to the delta chain to be tickled
32 *
33 *  Output parameters: NONE
34 */
35
36void _Watchdog_Tickle(
37  Chain_Control *header
38)
39{
40  ISR_Level level;
41  Watchdog_Control *the_watchdog;
42  Watchdog_States  watchdog_state;
43
44  /*
45   * See the comment in watchdoginsert.c and watchdogadjust.c
46   * about why it's safe not to declare header a pointer to
47   * volatile data - till, 2003/7
48   */
49
50  _ISR_Disable( level );
51
52  if ( _Chain_Is_empty( header ) )
53    goto leave;
54
55  the_watchdog = _Watchdog_First( header );
56
57  /*
58   * For some reason, on rare occasions the_watchdog->delta_interval
59   * of the head of the watchdog chain is 0.  Before this test was
60   * added, on these occasions an event (which usually was supposed
61   * to have a timeout of 1 tick would have a delta_interval of 0, which
62   * would be decremented to 0xFFFFFFFF by the unprotected
63   * "the_watchdog->delta_interval--;" operation.
64   * This would mean the event would not timeout, and also the chain would
65   * be blocked, because a timeout with a very high number would be at the
66   * head, rather than at the end.
67   * The test "if (the_watchdog->delta_interval != 0)"
68   * here prevents this from occuring.
69   *
70   * We were not able to categorically identify the situation that causes
71   * this, but proved it to be true empirically.  So this check causes
72   * correct behaviour in this circumstance.
73   *
74   * The belief is that a race condition exists whereby an event at the head
75   * of the chain is removed (by a pending ISR or higher priority task)
76   * during the _ISR_Flash( level ); in _Watchdog_Insert, but the watchdog
77   * to be inserted has already had its delta_interval adjusted to 0, and
78   * so is added to the head of the chain with a delta_interval of 0.
79   *
80   * Steven Johnson - 12/2005 (gcc-3.2.3 -O3 on powerpc)
81   */
82  if (the_watchdog->delta_interval != 0) {
83    the_watchdog->delta_interval--;
84    if ( the_watchdog->delta_interval != 0 )
85      goto leave;
86  }
87
88  do {
89     watchdog_state = _Watchdog_Remove( the_watchdog );
90
91     _ISR_Enable( level );
92
93     switch( watchdog_state ) {
94       case WATCHDOG_ACTIVE:
95         (*the_watchdog->routine)(
96           the_watchdog->id,
97           the_watchdog->user_data
98         );
99         break;
100
101       case WATCHDOG_INACTIVE:
102         /*
103          *  This state indicates that the watchdog is not on any chain.
104          *  Thus, it is NOT on a chain being tickled.  This case should
105          *  never occur.
106          */
107         break;
108
109       case WATCHDOG_BEING_INSERTED:
110         /*
111          *  This state indicates that the watchdog is in the process of
112          *  BEING inserted on the chain.  Thus, it can NOT be on a chain
113          *  being tickled.  This case should never occur.
114          */
115         break;
116
117       case WATCHDOG_REMOVE_IT:
118         break;
119     }
120
121     _ISR_Disable( level );
122
123     the_watchdog = _Watchdog_First( header );
124   } while ( !_Chain_Is_empty( header ) &&
125             (the_watchdog->delta_interval == 0) );
126
127leave:
128   _ISR_Enable(level);
129}
Note: See TracBrowser for help on using the repository browser.