1 | /** |
---|
2 | * @file watchdogadjusttochain.c |
---|
3 | * |
---|
4 | * This is used by the Timer Server task. |
---|
5 | */ |
---|
6 | |
---|
7 | /* COPYRIGHT (c) 1989-2009. |
---|
8 | * On-Line Applications Research Corporation (OAR). |
---|
9 | * |
---|
10 | * The license and distribution terms for this file may be |
---|
11 | * found in the file LICENSE in this distribution or at |
---|
12 | * http://www.rtems.com/license/LICENSE. |
---|
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 | void _Watchdog_Adjust_to_chain( |
---|
24 | Chain_Control *header, |
---|
25 | Watchdog_Interval units_arg, |
---|
26 | Chain_Control *to_fire |
---|
27 | |
---|
28 | ) |
---|
29 | { |
---|
30 | Watchdog_Interval units = units_arg; |
---|
31 | ISR_Level level; |
---|
32 | Watchdog_Control *first; |
---|
33 | |
---|
34 | if ( units <= 0 ) { |
---|
35 | return; |
---|
36 | } |
---|
37 | |
---|
38 | _ISR_Disable( level ); |
---|
39 | |
---|
40 | while ( 1 ) { |
---|
41 | if ( units <= 0 ) { |
---|
42 | break; |
---|
43 | } |
---|
44 | if ( _Chain_Is_empty( header ) ) { |
---|
45 | break; |
---|
46 | } |
---|
47 | first = _Watchdog_First( header ); |
---|
48 | |
---|
49 | /* |
---|
50 | * If it is longer than "units" until the first element on the chain |
---|
51 | * fires, then bump it and quit. |
---|
52 | */ |
---|
53 | if ( units < first->delta_interval ) { |
---|
54 | first->delta_interval -= units; |
---|
55 | break; |
---|
56 | } |
---|
57 | |
---|
58 | /* |
---|
59 | * The first set happens in less than units, so take all of them |
---|
60 | * off the chain and adjust units to reflect this. |
---|
61 | */ |
---|
62 | units -= first->delta_interval; |
---|
63 | first->delta_interval = 0; |
---|
64 | |
---|
65 | while ( 1 ) { |
---|
66 | _Chain_Extract_unprotected( &first->Node ); |
---|
67 | _Chain_Append_unprotected( to_fire, &first->Node ); |
---|
68 | |
---|
69 | _ISR_Flash( level ); |
---|
70 | |
---|
71 | if ( _Chain_Is_empty( header ) ) |
---|
72 | break; |
---|
73 | first = _Watchdog_First( header ); |
---|
74 | if ( first->delta_interval != 0 ) |
---|
75 | break; |
---|
76 | } |
---|
77 | } |
---|
78 | |
---|
79 | _ISR_Enable( level ); |
---|
80 | } |
---|
81 | |
---|