Mercurial > ecos
annotate packages/devs/watchdog/current/src/emulate.cxx @ 66:bf00f99aec69 ecos-sw-2000-02-02
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
| author | jlarmour |
|---|---|
| date | Wed, 02 Feb 2000 19:57:02 +0000 |
| parents | c38311975d4f |
| children |
| rev | line source |
|---|---|
| 0 | 1 //========================================================================== |
| 2 // | |
| 2 | 3 // watchdog/emulate.cxx |
| 0 | 4 // |
| 2 | 5 // Watchdog implementation emulation |
| 0 | 6 // |
| 7 //========================================================================== | |
| 8 //####COPYRIGHTBEGIN#### | |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
32
diff
changeset
|
9 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
32
diff
changeset
|
10 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
32
diff
changeset
|
11 // The contents of this file are subject to the Red Hat eCos Public License |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
12 // Version 1.1 (the "License"); you may not use this file except in |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
32
diff
changeset
|
13 // compliance with the License. You may obtain a copy of the License at |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
14 // http://www.redhat.com/ |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
32
diff
changeset
|
15 // |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
16 // Software distributed under the License is distributed on an "AS IS" |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
32
diff
changeset
|
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
32
diff
changeset
|
18 // License for the specific language governing rights and limitations under |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
32
diff
changeset
|
19 // the License. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
32
diff
changeset
|
20 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
32
diff
changeset
|
21 // The Original Code is eCos - Embedded Configurable Operating System, |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
32
diff
changeset
|
22 // released September 30, 1998. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
32
diff
changeset
|
23 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
32
diff
changeset
|
24 // The Initial Developer of the Original Code is Red Hat. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
32
diff
changeset
|
25 // Portions created by Red Hat are |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
32
diff
changeset
|
26 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
32
diff
changeset
|
27 // All Rights Reserved. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
32
diff
changeset
|
28 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
32
diff
changeset
|
29 // |
| 0 | 30 //####COPYRIGHTEND#### |
| 31 //========================================================================== | |
| 32 //#####DESCRIPTIONBEGIN#### | |
| 33 // | |
| 2 | 34 // Author(s): nickg |
| 35 // Contributors: nickg | |
| 36 // Date: 1998-07-29 | |
| 37 // Purpose: Watchdog class implementation | |
| 38 // Description: Contains an implementation of the Watchdog class for use | |
| 0 | 39 // when there is no hardware watchdog timer. Instead it is |
| 40 // emulated using an Alarm object. | |
| 41 // | |
| 42 //####DESCRIPTIONEND#### | |
| 43 // | |
| 44 //========================================================================== | |
| 45 | |
| 46 #include <pkgconf/watchdog.h> // watchdog configuration file | |
| 47 | |
| 48 #ifdef CYGIMP_WATCHDOG_EMULATE | |
| 49 | |
|
24
306eee292492
Merge from eCos master repository on 1999-07-16-05:47:06-BST
jlarmour
parents:
2
diff
changeset
|
50 #include <pkgconf/kernel.h> // Kernel config |
|
306eee292492
Merge from eCos master repository on 1999-07-16-05:47:06-BST
jlarmour
parents:
2
diff
changeset
|
51 |
| 0 | 52 #include <cyg/kernel/ktypes.h> // base kernel types |
| 53 #include <cyg/infra/cyg_trac.h> // tracing macros | |
| 54 #include <cyg/infra/cyg_ass.h> // assertion macros | |
| 55 #include <cyg/kernel/instrmnt.h> // instrumentation | |
| 56 | |
| 57 #include <cyg/kernel/clock.hxx> // clock and alarm | |
| 58 #include <cyg/kernel/sched.hxx> // scheduler | |
| 59 | |
| 60 #include <cyg/devs/watchdog.hxx> // my header | |
| 61 | |
| 62 #include <cyg/kernel/sched.inl> // scheduler inlines | |
| 63 | |
| 64 // ------------------------------------------------------------------------- | |
| 65 // Forward definitions | |
| 66 | |
| 67 static cyg_alarm_fn watchdog_alarm; | |
| 68 | |
| 69 // ------------------------------------------------------------------------- | |
| 70 // Statics | |
| 71 | |
| 72 // A static pointer to the single system defined watchdog device. | |
| 73 Cyg_Watchdog Cyg_Watchdog::watchdog; | |
| 74 | |
| 75 static Cyg_Alarm alarm( Cyg_Clock::real_time_clock, watchdog_alarm, 0 ); | |
| 76 | |
| 77 // One second's worth of ticks. | |
| 78 static cyg_tick_count one_sec; | |
| 79 | |
| 80 // ------------------------------------------------------------------------- | |
| 81 // Constructor | |
| 82 | |
| 83 Cyg_Watchdog::Cyg_Watchdog() | |
| 84 { | |
| 85 CYG_REPORT_FUNCTION(); | |
| 86 | |
| 87 action_list = 0; | |
| 88 | |
| 89 Cyg_Clock::cyg_resolution res = Cyg_Clock::real_time_clock->get_resolution(); | |
| 90 | |
| 91 one_sec = ( res.divisor * 1000000000LL ) / res.dividend ; | |
|
32
5af43b635655
Merge from eCos master repository on 1999-08-18-15:20:01-BST
jlarmour
parents:
24
diff
changeset
|
92 |
|
5af43b635655
Merge from eCos master repository on 1999-08-18-15:20:01-BST
jlarmour
parents:
24
diff
changeset
|
93 resolution = 1000000000LL; |
| 0 | 94 |
| 95 CYG_REPORT_RETURN(); | |
| 96 } | |
| 97 | |
| 98 // ------------------------------------------------------------------------- | |
|
32
5af43b635655
Merge from eCos master repository on 1999-08-18-15:20:01-BST
jlarmour
parents:
24
diff
changeset
|
99 // Return reset resolution |
|
5af43b635655
Merge from eCos master repository on 1999-08-18-15:20:01-BST
jlarmour
parents:
24
diff
changeset
|
100 |
|
5af43b635655
Merge from eCos master repository on 1999-08-18-15:20:01-BST
jlarmour
parents:
24
diff
changeset
|
101 cyg_uint64 Cyg_Watchdog::get_resolution() |
|
5af43b635655
Merge from eCos master repository on 1999-08-18-15:20:01-BST
jlarmour
parents:
24
diff
changeset
|
102 { |
|
5af43b635655
Merge from eCos master repository on 1999-08-18-15:20:01-BST
jlarmour
parents:
24
diff
changeset
|
103 return resolution; |
|
5af43b635655
Merge from eCos master repository on 1999-08-18-15:20:01-BST
jlarmour
parents:
24
diff
changeset
|
104 } |
|
5af43b635655
Merge from eCos master repository on 1999-08-18-15:20:01-BST
jlarmour
parents:
24
diff
changeset
|
105 |
|
5af43b635655
Merge from eCos master repository on 1999-08-18-15:20:01-BST
jlarmour
parents:
24
diff
changeset
|
106 // ------------------------------------------------------------------------- |
| 0 | 107 // Start the watchdog running. |
| 108 | |
| 109 void Cyg_Watchdog::start() | |
| 110 { | |
| 111 CYG_REPORT_FUNCTION(); | |
| 112 | |
| 113 Cyg_Clock::cyg_resolution res = Cyg_Clock::real_time_clock->get_resolution(); | |
| 114 | |
| 115 // Set alarm to a one second single-shot trigger | |
| 116 alarm.initialize( Cyg_Clock::real_time_clock->current_value() + one_sec, 0 ); | |
| 117 | |
| 118 CYG_REPORT_RETURN(); | |
| 119 } | |
| 120 | |
| 121 // ------------------------------------------------------------------------- | |
| 122 // Reset watchdog timer. This needs to be called regularly to prevent | |
| 123 // the watchdog firing. | |
| 124 | |
| 125 void Cyg_Watchdog::reset() | |
| 126 { | |
| 127 CYG_REPORT_FUNCTION(); | |
| 128 | |
| 129 Cyg_Clock::cyg_resolution res = Cyg_Clock::real_time_clock->get_resolution(); | |
| 130 | |
| 131 Cyg_Scheduler::lock(); | |
| 132 | |
| 133 // Set alarm to a one second single-shot trigger | |
| 134 alarm.initialize( Cyg_Clock::real_time_clock->current_value() + one_sec, 0 ); | |
| 135 | |
| 136 Cyg_Scheduler::unlock(); | |
| 137 | |
| 138 CYG_REPORT_RETURN(); | |
| 139 } | |
| 140 | |
| 141 // ------------------------------------------------------------------------- | |
| 142 // Trigger the watchdog as if the timer had expired. | |
| 143 | |
| 144 void Cyg_Watchdog::trigger() | |
| 145 { | |
| 146 CYG_REPORT_FUNCTION(); | |
| 147 | |
| 148 Cyg_Scheduler::lock(); | |
| 149 | |
| 150 // Disable alarm just in case | |
| 151 alarm.disable(); | |
| 152 | |
| 153 Cyg_Watchdog_Action *act = action_list; | |
| 154 | |
| 155 while( 0 != act ) | |
| 156 { | |
| 157 act->action( act->data ); | |
| 158 | |
| 159 act = act->next; | |
| 160 } | |
| 161 | |
| 162 Cyg_Scheduler::unlock(); | |
| 163 | |
| 164 CYG_REPORT_RETURN(); | |
| 165 } | |
| 166 | |
| 167 // ------------------------------------------------------------------------- | |
| 168 // Register an action routine that will be called when the timer | |
| 169 // triggers. | |
| 170 | |
| 171 void Cyg_Watchdog::install_action( Cyg_Watchdog_Action *action ) | |
| 172 { | |
| 173 CYG_REPORT_FUNCTION(); | |
| 174 | |
| 175 Cyg_Scheduler::lock(); | |
| 176 | |
| 177 action->next = action_list; | |
| 178 action_list = action; | |
| 179 | |
| 180 Cyg_Scheduler::unlock(); | |
| 181 | |
| 182 CYG_REPORT_RETURN(); | |
| 183 } | |
| 184 | |
| 185 // ------------------------------------------------------------------------- | |
| 186 // Deregister a previously registered action routine. | |
| 187 | |
| 188 void Cyg_Watchdog::uninstall_action( Cyg_Watchdog_Action *action ) | |
| 189 { | |
| 190 CYG_REPORT_FUNCTION(); | |
| 191 | |
| 192 Cyg_Scheduler::lock(); | |
| 193 | |
| 194 Cyg_Watchdog_Action **act_ptr = &action_list; | |
| 195 | |
| 196 while( 0 != *act_ptr ) | |
| 197 { | |
| 198 Cyg_Watchdog_Action *a = *act_ptr; | |
| 199 | |
| 200 if( a == action ) | |
| 201 { | |
| 202 *act_ptr = a->next; | |
| 203 break; | |
| 204 } | |
| 205 act_ptr = &a->next; | |
| 206 } | |
| 207 | |
| 208 Cyg_Scheduler::unlock(); | |
| 209 | |
| 210 CYG_REPORT_RETURN(); | |
| 211 } | |
| 212 | |
| 213 // ------------------------------------------------------------------------- | |
| 214 // Alarm function | |
| 215 | |
| 216 void watchdog_alarm( Cyg_Alarm *a, CYG_ADDRWORD data) | |
| 217 { | |
| 218 CYG_REPORT_FUNCTION(); | |
| 219 | |
| 220 Cyg_Watchdog::watchdog.trigger(); | |
| 221 } | |
| 222 | |
| 223 #endif // CYGIMP_WATCHDOG_EMULATE | |
| 224 // ------------------------------------------------------------------------- | |
| 225 // EOF watchdog/emulate.cxx |
