Mercurial > nand-ecoscentric
comparison packages/devs/watchdog/current/src/emulate.cxx @ 0:3111d98ba7b3 ecos-v1_1-release
Initial commit of eCos version 1.1
| author | jlarmour |
|---|---|
| date | Tue, 11 May 1999 11:16:07 +0000 |
| parents | |
| children | 443894e2e912 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:3111d98ba7b3 |
|---|---|
| 1 //========================================================================== | |
| 2 // | |
| 3 // watchdog/emulate.cxx | |
| 4 // | |
| 5 // Watchdog implementation emulation | |
| 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 | |
| 25 // by Cygnus are Copyright (C) 1998 Cygnus Solutions. All Rights Reserved. | |
| 26 // ------------------------------------------- | |
| 27 // | |
| 28 //####COPYRIGHTEND#### | |
| 29 //========================================================================== | |
| 30 //#####DESCRIPTIONBEGIN#### | |
| 31 // | |
| 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 | |
| 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 | |
| 48 #include <cyg/kernel/ktypes.h> // base kernel types | |
| 49 #include <cyg/infra/cyg_trac.h> // tracing macros | |
| 50 #include <cyg/infra/cyg_ass.h> // assertion macros | |
| 51 #include <cyg/kernel/instrmnt.h> // instrumentation | |
| 52 | |
| 53 #include <cyg/kernel/clock.hxx> // clock and alarm | |
| 54 #include <cyg/kernel/sched.hxx> // scheduler | |
| 55 | |
| 56 #include <cyg/devs/watchdog.hxx> // my header | |
| 57 | |
| 58 #include <cyg/kernel/sched.inl> // scheduler inlines | |
| 59 | |
| 60 // ------------------------------------------------------------------------- | |
| 61 // Forward definitions | |
| 62 | |
| 63 static cyg_alarm_fn watchdog_alarm; | |
| 64 | |
| 65 // ------------------------------------------------------------------------- | |
| 66 // Statics | |
| 67 | |
| 68 // A static pointer to the single system defined watchdog device. | |
| 69 Cyg_Watchdog Cyg_Watchdog::watchdog; | |
| 70 | |
| 71 static Cyg_Alarm alarm( Cyg_Clock::real_time_clock, watchdog_alarm, 0 ); | |
| 72 | |
| 73 // One second's worth of ticks. | |
| 74 static cyg_tick_count one_sec; | |
| 75 | |
| 76 // ------------------------------------------------------------------------- | |
| 77 // Constructor | |
| 78 | |
| 79 Cyg_Watchdog::Cyg_Watchdog() | |
| 80 { | |
| 81 CYG_REPORT_FUNCTION(); | |
| 82 | |
| 83 action_list = 0; | |
| 84 | |
| 85 Cyg_Clock::cyg_resolution res = Cyg_Clock::real_time_clock->get_resolution(); | |
| 86 | |
| 87 one_sec = ( res.divisor * 1000000000LL ) / res.dividend ; | |
| 88 | |
| 89 CYG_REPORT_RETURN(); | |
| 90 } | |
| 91 | |
| 92 // ------------------------------------------------------------------------- | |
| 93 // Start the watchdog running. | |
| 94 | |
| 95 void Cyg_Watchdog::start() | |
| 96 { | |
| 97 CYG_REPORT_FUNCTION(); | |
| 98 | |
| 99 Cyg_Clock::cyg_resolution res = Cyg_Clock::real_time_clock->get_resolution(); | |
| 100 | |
| 101 // Set alarm to a one second single-shot trigger | |
| 102 alarm.initialize( Cyg_Clock::real_time_clock->current_value() + one_sec, 0 ); | |
| 103 | |
| 104 CYG_REPORT_RETURN(); | |
| 105 } | |
| 106 | |
| 107 // ------------------------------------------------------------------------- | |
| 108 // Reset watchdog timer. This needs to be called regularly to prevent | |
| 109 // the watchdog firing. | |
| 110 | |
| 111 void Cyg_Watchdog::reset() | |
| 112 { | |
| 113 CYG_REPORT_FUNCTION(); | |
| 114 | |
| 115 Cyg_Clock::cyg_resolution res = Cyg_Clock::real_time_clock->get_resolution(); | |
| 116 | |
| 117 Cyg_Scheduler::lock(); | |
| 118 | |
| 119 // Set alarm to a one second single-shot trigger | |
| 120 alarm.initialize( Cyg_Clock::real_time_clock->current_value() + one_sec, 0 ); | |
| 121 | |
| 122 Cyg_Scheduler::unlock(); | |
| 123 | |
| 124 CYG_REPORT_RETURN(); | |
| 125 } | |
| 126 | |
| 127 // ------------------------------------------------------------------------- | |
| 128 // Trigger the watchdog as if the timer had expired. | |
| 129 | |
| 130 void Cyg_Watchdog::trigger() | |
| 131 { | |
| 132 CYG_REPORT_FUNCTION(); | |
| 133 | |
| 134 Cyg_Scheduler::lock(); | |
| 135 | |
| 136 // Disable alarm just in case | |
| 137 alarm.disable(); | |
| 138 | |
| 139 Cyg_Watchdog_Action *act = action_list; | |
| 140 | |
| 141 while( 0 != act ) | |
| 142 { | |
| 143 act->action( act->data ); | |
| 144 | |
| 145 act = act->next; | |
| 146 } | |
| 147 | |
| 148 Cyg_Scheduler::unlock(); | |
| 149 | |
| 150 CYG_REPORT_RETURN(); | |
| 151 } | |
| 152 | |
| 153 // ------------------------------------------------------------------------- | |
| 154 // Register an action routine that will be called when the timer | |
| 155 // triggers. | |
| 156 | |
| 157 void Cyg_Watchdog::install_action( Cyg_Watchdog_Action *action ) | |
| 158 { | |
| 159 CYG_REPORT_FUNCTION(); | |
| 160 | |
| 161 Cyg_Scheduler::lock(); | |
| 162 | |
| 163 action->next = action_list; | |
| 164 action_list = action; | |
| 165 | |
| 166 Cyg_Scheduler::unlock(); | |
| 167 | |
| 168 CYG_REPORT_RETURN(); | |
| 169 } | |
| 170 | |
| 171 // ------------------------------------------------------------------------- | |
| 172 // Deregister a previously registered action routine. | |
| 173 | |
| 174 void Cyg_Watchdog::uninstall_action( Cyg_Watchdog_Action *action ) | |
| 175 { | |
| 176 CYG_REPORT_FUNCTION(); | |
| 177 | |
| 178 Cyg_Scheduler::lock(); | |
| 179 | |
| 180 Cyg_Watchdog_Action **act_ptr = &action_list; | |
| 181 | |
| 182 while( 0 != *act_ptr ) | |
| 183 { | |
| 184 Cyg_Watchdog_Action *a = *act_ptr; | |
| 185 | |
| 186 if( a == action ) | |
| 187 { | |
| 188 *act_ptr = a->next; | |
| 189 break; | |
| 190 } | |
| 191 act_ptr = &a->next; | |
| 192 } | |
| 193 | |
| 194 Cyg_Scheduler::unlock(); | |
| 195 | |
| 196 CYG_REPORT_RETURN(); | |
| 197 } | |
| 198 | |
| 199 // ------------------------------------------------------------------------- | |
| 200 // Alarm function | |
| 201 | |
| 202 void watchdog_alarm( Cyg_Alarm *a, CYG_ADDRWORD data) | |
| 203 { | |
| 204 CYG_REPORT_FUNCTION(); | |
| 205 | |
| 206 Cyg_Watchdog::watchdog.trigger(); | |
| 207 } | |
| 208 | |
| 209 #endif // CYGIMP_WATCHDOG_EMULATE | |
| 210 // ------------------------------------------------------------------------- | |
| 211 // EOF watchdog/emulate.cxx |
