source: rtems/cpukit/score/src/watchdoginsert.c @ 749d64a

4.104.115
Last change on this file since 749d64a was 55e01299, checked in by Joel Sherrill <joel.sherrill@…>, on 08/17/05 at 22:49:56

2005-08-17 Andrew Sinclair <Andrew.Sinclair@…>

PR 807/rtems

  • rtems/src/timerfireafter.c, rtems/src/timerserverfireafter.c, score/src/watchdoginsert.c: Tighten critical section checks on an ISR using the same timer being inserted by a lower priority ISR or interupt task.
  • Property mode set to 100644
File size: 3.1 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_Insert
26 *
27 *  This routine inserts a watchdog timer on to the appropriate delta
28 *  chain while updating the delta interval counters.
29 */
30
31void _Watchdog_Insert(
32  Chain_Control         *header,
33  Watchdog_Control      *the_watchdog
34)
35{
36  ISR_Level          level;
37  Watchdog_Control  *after;
38  uint32_t           insert_isr_nest_level;
39  Watchdog_Interval  delta_interval;
40
41
42  insert_isr_nest_level   = _ISR_Nest_level;
43
44  _ISR_Disable( level );
45
46  /*
47   *  Check to see if the watchdog has just been inserted by a
48   *  higher priority interrupt.  If so, abandon this insert.
49   */
50
51  if ( the_watchdog->state != WATCHDOG_INACTIVE ) {
52    _ISR_Enable( level );
53    return;
54  }
55
56  the_watchdog->state = WATCHDOG_BEING_INSERTED;
57  _Watchdog_Sync_count++;
58
59restart:
60  delta_interval = the_watchdog->initial;
61
62  /*
63   * We CANT use _Watchdog_First() here, because a TICK interrupt
64   * could modify the chain during the _ISR_Flash() below. Hence,
65   * the header is pointing to volatile data. The _Watchdog_First()
66   * INLINE routine (but not the macro - note the subtle difference)
67   * casts away the 'volatile'...
68   *
69   * Also, this is only necessary because we call no other routine
70   * from this piece of code, hence the compiler thinks it's safe to
71   * cache *header!!
72   *
73   *  Till Straumann, 7/2003 (gcc-3.2.2 -O4 on powerpc)
74   *
75   */
76  for ( after = (Watchdog_Control *) ((volatile Chain_Control *)header)->first ;
77        ;
78        after = _Watchdog_Next( after ) ) {
79
80     if ( delta_interval == 0 || !_Watchdog_Next( after ) )
81       break;
82
83     if ( delta_interval < after->delta_interval ) {
84       after->delta_interval -= delta_interval;
85       break;
86     }
87
88     delta_interval -= after->delta_interval;
89
90     /*
91      *  If you experience problems comment out the _ISR_Flash line.
92      *  3.2.0 was the first release with this critical section redesigned.
93      *  Under certain circumstances, the PREVIOUS critical section algorithm
94      *  used around this flash point allowed interrupts to execute
95      *  which violated the design assumptions.  The critical section
96      *  mechanism used here WAS redesigned to address this.
97      */
98
99     _ISR_Flash( level );
100
101     if ( the_watchdog->state != WATCHDOG_BEING_INSERTED ) {
102       goto exit_insert;
103     }
104
105     if ( _Watchdog_Sync_level > insert_isr_nest_level ) {
106       _Watchdog_Sync_level = insert_isr_nest_level;
107       goto restart;
108     }
109  }
110
111  _Watchdog_Activate( the_watchdog );
112
113  the_watchdog->delta_interval = delta_interval;
114
115  _Chain_Insert_unprotected( after->Node.previous, &the_watchdog->Node );
116
117  the_watchdog->start_time = _Watchdog_Ticks_since_boot;
118
119exit_insert:
120  _Watchdog_Sync_level = insert_isr_nest_level;
121  _Watchdog_Sync_count--;
122  _ISR_Enable( level );
123}
Note: See TracBrowser for help on using the repository browser.