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