source: rtems/cpukit/score/src/watchdoginsert.c @ f26145b

4.104.114.84.95
Last change on this file since f26145b was a8eed23, checked in by Ralf Corsepius <ralf.corsepius@…>, on 01/27/05 at 05:57:05

Include config.h.

  • Property mode set to 100644
File size: 2.9 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  the_watchdog->state = WATCHDOG_BEING_INSERTED;
44
45  _ISR_Disable( level );
46
47  _Watchdog_Sync_count++;
48
49restart:
50  delta_interval = the_watchdog->initial;
51
52  /*
53   * We CANT use _Watchdog_First() here, because a TICK interrupt
54   * could modify the chain during the _ISR_Flash() below. Hence,
55   * the header is pointing to volatile data. The _Watchdog_First()
56   * INLINE routine (but not the macro - note the subtle difference)
57   * casts away the 'volatile'...
58   *
59   * Also, this is only necessary because we call no other routine
60   * from this piece of code, hence the compiler thinks it's safe to
61   * cache *header!!
62   *
63   *  Till Straumann, 7/2003 (gcc-3.2.2 -O4 on powerpc)
64   *
65   */
66  for ( after = (Watchdog_Control *) ((volatile Chain_Control *)header)->first ;
67        ;
68        after = _Watchdog_Next( after ) ) {
69
70     if ( delta_interval == 0 || !_Watchdog_Next( after ) )
71       break;
72
73     if ( delta_interval < after->delta_interval ) {
74       after->delta_interval -= delta_interval;
75       break;
76     }
77
78     delta_interval -= after->delta_interval;
79
80     /*
81      *  If you experience problems comment out the _ISR_Flash line.
82      *  3.2.0 was the first release with this critical section redesigned.
83      *  Under certain circumstances, the PREVIOUS critical section algorithm
84      *  used around this flash point allowed interrupts to execute
85      *  which violated the design assumptions.  The critical section
86      *  mechanism used here WAS redesigned to address this.
87      */
88
89     _ISR_Flash( level );
90
91     if ( the_watchdog->state != WATCHDOG_BEING_INSERTED ) {
92       goto exit_insert;
93     }
94
95     if ( _Watchdog_Sync_level > insert_isr_nest_level ) {
96       _Watchdog_Sync_level = insert_isr_nest_level;
97       goto restart;
98     }
99  }
100
101  _Watchdog_Activate( the_watchdog );
102
103  the_watchdog->delta_interval = delta_interval;
104
105  _Chain_Insert_unprotected( after->Node.previous, &the_watchdog->Node );
106
107  the_watchdog->start_time = _Watchdog_Ticks_since_boot;
108
109exit_insert:
110  _Watchdog_Sync_level = insert_isr_nest_level;
111  _Watchdog_Sync_count--;
112  _ISR_Enable( level );
113}
Note: See TracBrowser for help on using the repository browser.