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 | #include <rtems/system.h> |
---|
16 | #include <rtems/score/isr.h> |
---|
17 | #include <rtems/score/watchdog.h> |
---|
18 | |
---|
19 | /*PAGE |
---|
20 | * |
---|
21 | * _Watchdog_Insert |
---|
22 | * |
---|
23 | * This routine inserts a watchdog timer on to the appropriate delta |
---|
24 | * chain while updating the delta interval counters. |
---|
25 | */ |
---|
26 | |
---|
27 | void _Watchdog_Insert( |
---|
28 | Chain_Control *header, |
---|
29 | Watchdog_Control *the_watchdog |
---|
30 | ) |
---|
31 | { |
---|
32 | ISR_Level level; |
---|
33 | Watchdog_Control *after; |
---|
34 | uint32_t insert_isr_nest_level; |
---|
35 | Watchdog_Interval delta_interval; |
---|
36 | |
---|
37 | |
---|
38 | insert_isr_nest_level = _ISR_Nest_level; |
---|
39 | the_watchdog->state = WATCHDOG_BEING_INSERTED; |
---|
40 | |
---|
41 | _ISR_Disable( level ); |
---|
42 | |
---|
43 | _Watchdog_Sync_count++; |
---|
44 | |
---|
45 | restart: |
---|
46 | delta_interval = the_watchdog->initial; |
---|
47 | |
---|
48 | /* |
---|
49 | * We CANT use _Watchdog_First() here, because a TICK interrupt |
---|
50 | * could modify the chain during the _ISR_Flash() below. Hence, |
---|
51 | * the header is pointing to volatile data. The _Watchdog_First() |
---|
52 | * INLINE routine (but not the macro - note the subtle difference) |
---|
53 | * casts away the 'volatile'... |
---|
54 | * |
---|
55 | * Also, this is only necessary because we call no other routine |
---|
56 | * from this piece of code, hence the compiler thinks it's safe to |
---|
57 | * cache *header!! |
---|
58 | * |
---|
59 | * Till Straumann, 7/2003 (gcc-3.2.2 -O4 on powerpc) |
---|
60 | * |
---|
61 | */ |
---|
62 | for ( after = (Watchdog_Control *) ((volatile Chain_Control *)header)->first ; |
---|
63 | ; |
---|
64 | after = _Watchdog_Next( after ) ) { |
---|
65 | |
---|
66 | if ( delta_interval == 0 || !_Watchdog_Next( after ) ) |
---|
67 | break; |
---|
68 | |
---|
69 | if ( delta_interval < after->delta_interval ) { |
---|
70 | after->delta_interval -= delta_interval; |
---|
71 | break; |
---|
72 | } |
---|
73 | |
---|
74 | delta_interval -= after->delta_interval; |
---|
75 | |
---|
76 | /* |
---|
77 | * If you experience problems comment out the _ISR_Flash line. |
---|
78 | * 3.2.0 was the first release with this critical section redesigned. |
---|
79 | * Under certain circumstances, the PREVIOUS critical section algorithm |
---|
80 | * used around this flash point allowed interrupts to execute |
---|
81 | * which violated the design assumptions. The critical section |
---|
82 | * mechanism used here WAS redesigned to address this. |
---|
83 | */ |
---|
84 | |
---|
85 | _ISR_Flash( level ); |
---|
86 | |
---|
87 | if ( the_watchdog->state != WATCHDOG_BEING_INSERTED ) { |
---|
88 | goto exit_insert; |
---|
89 | } |
---|
90 | |
---|
91 | if ( _Watchdog_Sync_level > insert_isr_nest_level ) { |
---|
92 | _Watchdog_Sync_level = insert_isr_nest_level; |
---|
93 | goto restart; |
---|
94 | } |
---|
95 | } |
---|
96 | |
---|
97 | _Watchdog_Activate( the_watchdog ); |
---|
98 | |
---|
99 | the_watchdog->delta_interval = delta_interval; |
---|
100 | |
---|
101 | _Chain_Insert_unprotected( after->Node.previous, &the_watchdog->Node ); |
---|
102 | |
---|
103 | the_watchdog->start_time = _Watchdog_Ticks_since_boot; |
---|
104 | |
---|
105 | exit_insert: |
---|
106 | _Watchdog_Sync_level = insert_isr_nest_level; |
---|
107 | _Watchdog_Sync_count--; |
---|
108 | _ISR_Enable( level ); |
---|
109 | } |
---|