comparison packages/devs/watchdog/current/src/mn10300.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/mn10300.cxx
4 //
5 // Watchdog implementation for MN10300
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 // with the MN10300 hardware watchdog timer.
38 //
39 //####DESCRIPTIONEND####
40 //
41 //==========================================================================
42
43 #include <pkgconf/system.h> // system configuration file
44 #include <pkgconf/watchdog.h> // configuration for this package
45
46 #if defined(CYG_HAL_MN10300_MN103002) && !defined(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/hal/hal_io.h> // IO register access
54
55 #include <cyg/kernel/sched.hxx> // scheduler
56 #include <cyg/kernel/intr.hxx> // interrupts
57
58 #include <cyg/kernel/sched.inl> // scheduler inlines
59
60 #include <cyg/devs/watchdog.hxx> // my header
61
62 // -------------------------------------------------------------------------
63 // MN10300 watchdog timer registers
64
65 #define WATCHDOG_BASE 0x34004000
66 #define WATCHDOG_COUNTER (WATCHDOG_BASE)
67 #define WATCHDOG_CONTROL (WATCHDOG_BASE+2)
68 #define WATCHDOG_RESET (WATCHDOG_BASE+4)
69
70 #define WATCHDOG_WDCK0 0x07
71 #define WATCHDOG_WDCK0_DEFAULT 0x04 // 1016.801ms cycle
72 #define WATCHDOG_WDRST 0x40
73 #define WATCHDOG_WDCNE 0x80
74
75 // -------------------------------------------------------------------------
76 // Forward definitions
77
78 static cyg_ISR watchdog_isr;
79 static cyg_DSR watchdog_dsr;
80
81 // -------------------------------------------------------------------------
82 // Statics
83
84 // A static pointer to the single system defined watchdog device.
85 Cyg_Watchdog Cyg_Watchdog::watchdog;
86
87 // Interrupt object
88 static Cyg_Interrupt interrupt(
89 CYG_VECTOR_WATCHDOG,
90 0,
91 0,
92 watchdog_isr,
93 watchdog_dsr
94 );
95
96 // -------------------------------------------------------------------------
97 // Constructor
98
99 Cyg_Watchdog::Cyg_Watchdog()
100 {
101 CYG_REPORT_FUNCTION();
102
103 action_list = 0;
104
105 CYG_REPORT_RETURN();
106 }
107
108 // -------------------------------------------------------------------------
109 // Start the watchdog running.
110
111 void Cyg_Watchdog::start()
112 {
113 CYG_REPORT_FUNCTION();
114
115 interrupt.attach();
116
117 HAL_WRITE_UINT8( WATCHDOG_COUNTER, 0 );
118
119 // Set overflow cycle
120 // Enable and reset counter
121 HAL_WRITE_UINT8( WATCHDOG_CONTROL,
122 WATCHDOG_WDCK0_DEFAULT|WATCHDOG_WDCNE|WATCHDOG_WDRST);
123
124 CYG_REPORT_RETURN();
125 }
126
127 // -------------------------------------------------------------------------
128 // Reset watchdog timer. This needs to be called regularly to prevent
129 // the watchdog firing.
130
131 void Cyg_Watchdog::reset()
132 {
133 CYG_REPORT_FUNCTION();
134
135 cyg_uint8 ctrl;
136
137 HAL_READ_UINT8( WATCHDOG_CONTROL, ctrl );
138
139 ctrl |= WATCHDOG_WDRST;
140
141 HAL_WRITE_UINT8( WATCHDOG_CONTROL, ctrl );
142
143 CYG_REPORT_RETURN();
144 }
145
146 // -------------------------------------------------------------------------
147 // Trigger the watchdog as if the timer had expired.
148
149 void Cyg_Watchdog::trigger()
150 {
151 CYG_REPORT_FUNCTION();
152
153 Cyg_Scheduler::lock();
154
155 // Disable interrupt just in case
156 interrupt.detach();
157
158 Cyg_Watchdog_Action *act = action_list;
159
160 while( 0 != act )
161 {
162 act->action( act->data );
163
164 act = act->next;
165 }
166
167 Cyg_Scheduler::unlock();
168
169 CYG_REPORT_RETURN();
170 }
171
172 // -------------------------------------------------------------------------
173 // Register an action routine that will be called when the timer
174 // triggers.
175
176 void Cyg_Watchdog::install_action( Cyg_Watchdog_Action *action )
177 {
178 CYG_REPORT_FUNCTION();
179
180 Cyg_Scheduler::lock();
181
182 action->next = action_list;
183 action_list = action;
184
185 Cyg_Scheduler::unlock();
186
187 CYG_REPORT_RETURN();
188 }
189
190 // -------------------------------------------------------------------------
191 // Deregister a previously registered action routine.
192
193 void Cyg_Watchdog::uninstall_action( Cyg_Watchdog_Action *action )
194 {
195 CYG_REPORT_FUNCTION();
196
197 Cyg_Scheduler::lock();
198
199 Cyg_Watchdog_Action **act_ptr = &action_list;
200
201 while( 0 != *act_ptr )
202 {
203 Cyg_Watchdog_Action *a = *act_ptr;
204
205 if( a == action )
206 {
207 *act_ptr = a->next;
208 break;
209 }
210 act_ptr = &a->next;
211 }
212
213 Cyg_Scheduler::unlock();
214
215 CYG_REPORT_RETURN();
216 }
217
218 // -------------------------------------------------------------------------
219 // ISR and DSR
220
221 cyg_uint32 watchdog_isr( cyg_vector vector, CYG_ADDRWORD data)
222 {
223 CYG_REPORT_FUNCTION();
224
225 Cyg_Watchdog::watchdog.trigger();
226
227 CYG_REPORT_RETURN();
228
229 return 0;
230 }
231
232 void watchdog_dsr(cyg_vector vector, cyg_ucount32 count, CYG_ADDRWORD data)
233 {
234 }
235
236 #endif // defined(CYG_HAL_MN10300_MN103002) && !defined(CYGIMP_WATCHDOG_EMULATE)
237 // -------------------------------------------------------------------------
238 // EOF watchdog/mn10300.cxx