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

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on Mar 20, 2014 at 9:10:47 PM

Change all references of rtems.com to rtems.org.

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