1 |
27 |
unneback |
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
|
|
|
9 |
|
|
|
10 |
|
|
|
11 |
|
|
|
12 |
|
|
|
13 |
|
|
|
14 |
|
|
|
15 |
|
|
|
16 |
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
|
|
|
20 |
|
|
|
21 |
|
|
|
22 |
|
|
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
|
26 |
|
|
|
27 |
|
|
|
28 |
|
|
|
29 |
|
|
|
30 |
|
|
|
31 |
|
|
|
32 |
|
|
|
33 |
|
|
|
34 |
|
|
|
35 |
|
|
|
36 |
|
|
|
37 |
|
|
|
38 |
|
|
Synthetic Target Watchdog Device
|
39 |
|
|
|
40 |
|
|
|
41 |
|
|
|
42 |
|
|
Synthetic Target Watchdog Device
|
43 |
|
|
|
44 |
|
|
|
45 |
|
|
Synthetic Target Watchdog Device
|
46 |
|
|
Emulate watchdog hardware in the synthetic target
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
Overview
|
50 |
|
|
|
51 |
|
|
Some target hardware comes equipped with a watchdog timer. Application
|
52 |
|
|
code can start this timer and after a certain period of time,
|
53 |
|
|
typically a second, the watchdog will trigger. Usually this causes the
|
54 |
|
|
hardware to reboot. The application can prevent this by regularly
|
55 |
|
|
resetting the watchdog. An automatic reboot can be very useful when
|
56 |
|
|
deploying hardware in the field: a hardware glitch could cause the
|
57 |
|
|
unit to hang; or the software could receive an unexpected sequence of
|
58 |
|
|
inputs, never seen in the laboratory, causing the system to lock up.
|
59 |
|
|
Often the hardware is still functional, and a reboot sorts out the
|
60 |
|
|
problem with only a brief interruption in service.
|
61 |
|
|
|
62 |
|
|
|
63 |
|
|
The synthetic target watchdog package emulates watchdog hardware.
|
64 |
|
|
During system initialization watchdog device will be instantiated,
|
65 |
|
|
and the watchdog.tcl script will be loaded by the
|
66 |
|
|
I/O auxiliary. When the eCos application starts the watchdog device,
|
67 |
|
|
the watchdog.tcl script will start checking the
|
68 |
|
|
state of the eCos application at one second intervals. A watchdog
|
69 |
|
|
reset call simply involves a message to the I/O auxiliary. If the
|
70 |
|
|
watchdog.tcl script detects that a second has
|
71 |
|
|
elapsed
|
72 |
|
|
without a reset then it will send a SIGPWR signal
|
73 |
|
|
to the eCos application, causing the latter to terminate. If gdb is
|
74 |
|
|
being used to run the application, the user will get a chance to
|
75 |
|
|
investigate what is happening. This behaviour is different from real
|
76 |
|
|
hardware in that there is no automatic reboot, but the synthetic
|
77 |
|
|
target is used only for development purposes, not deployment in the
|
78 |
|
|
field: if a reboot is desired then this can be achieved very easily
|
79 |
|
|
by using gdb commands to run another instance of the application.
|
80 |
|
|
|
81 |
|
|
|
82 |
|
|
|
83 |
|
|
Installation
|
84 |
|
|
|
85 |
|
|
Before a synthetic target eCos application can use a watchdog device
|
86 |
|
|
it is necessary to build and install host-side support. The relevant
|
87 |
|
|
code resides in the host
|
88 |
|
|
subdirectory of the synthetic target watchdog package, and building it
|
89 |
|
|
involves the standard configure,
|
90 |
|
|
make and make install steps. The
|
91 |
|
|
implementation of the watchdog support does not require any
|
92 |
|
|
executables, just a Tcl script watchdog.tcl and
|
93 |
|
|
some support files, so the make step is a no-op.
|
94 |
|
|
|
95 |
|
|
|
96 |
|
|
There are two main ways of building the host-side software. It is
|
97 |
|
|
possible to build both the generic host-side software and all
|
98 |
|
|
package-specific host-side software, including the watchdog support,
|
99 |
|
|
in a single build tree. This involves using the
|
100 |
|
|
configure script at the toplevel of the eCos
|
101 |
|
|
repository. For more information on this, see the
|
102 |
|
|
README.host file at the top of the repository.
|
103 |
|
|
Note that if you have an existing build tree which does not include
|
104 |
|
|
the synthetic target watchdog support then it will be necessary to
|
105 |
|
|
rerun the toplevel configure script: the search for appropriate
|
106 |
|
|
packages happens at configure time.
|
107 |
|
|
|
108 |
|
|
|
109 |
|
|
The alternative is to build just the host-side for this package.
|
110 |
|
|
This requires a separate build directory, building directly in the
|
111 |
|
|
source tree is disallowed. The configure options
|
112 |
|
|
are much the same as for a build from the toplevel, and the
|
113 |
|
|
README.host file can be consulted for more
|
114 |
|
|
details. It is essential that the watchdog support be configured with
|
115 |
|
|
the same option as other eCos host-side
|
116 |
|
|
software, especially the I/O auxiliary provided by the architectural
|
117 |
|
|
synthetic target HAL package, otherwise the I/O auxiliary will be
|
118 |
|
|
unable to locate the watchdog support.
|
119 |
|
|
|
120 |
|
|
|
121 |
|
|
|
122 |
|
|
Target-side
|
123 |
|
|
Configuration
|
124 |
|
|
|
125 |
|
|
The watchdog device depends on the generic watchdog support,
|
126 |
|
|
CYGPKG_IO_WATCHDOG: if the generic support is
|
127 |
|
|
absent then the watchdog device will be inactive. Some templates
|
128 |
|
|
include this generic package by default, but not all. If the
|
129 |
|
|
configuration does not include the generic package then it can be
|
130 |
|
|
added using the eCos configuration tools, for example:
|
131 |
|
|
|
132 |
|
|
|
133 |
|
|
$ ecosconfig add CYGPKG_IO_WATCHDOG
|
134 |
|
|
|
135 |
|
|
|
136 |
|
|
By default the configuration will use the hardware-specific support,
|
137 |
|
|
i.e. this package. However the generic watchdog package contains an
|
138 |
|
|
alternative implementation using the kernel alarm facility, and that
|
139 |
|
|
implementation can be selected if desired. However usually it will be
|
140 |
|
|
better to rely on an external watchdog facility as provided by the I/O
|
141 |
|
|
auxiliary and the watchdog.tcl script: if there
|
142 |
|
|
are serious problems within the application, for example memory
|
143 |
|
|
corruption, then an internal software-only implementation will not be
|
144 |
|
|
reliable.
|
145 |
|
|
|
146 |
|
|
|
147 |
|
|
The watchdog resolution is currently fixed to one second: if the
|
148 |
|
|
device does not receive a reset signal at least once a second then
|
149 |
|
|
the watchdog will trigger and the eCos application will be terminated
|
150 |
|
|
with a SIGPWR signal. The current implementation
|
151 |
|
|
does not allow this resolution to be changed.
|
152 |
|
|
|
153 |
|
|
|
154 |
|
|
On some targets the watchdog device does not perform a hard reset.
|
155 |
|
|
Instead the device works more or less via the interrupt subsystem,
|
156 |
|
|
allowing application code to install action routines that will be
|
157 |
|
|
called when the watchdog triggers. The synthetic target watchdog
|
158 |
|
|
support effectively does perform a hard reset, by sending a
|
159 |
|
|
SIGPWR signal to the eCos application, and there is
|
160 |
|
|
no support for action routines.
|
161 |
|
|
|
162 |
|
|
|
163 |
|
|
The synthetic target watchdog package provides some configuration
|
164 |
|
|
options for manipulating the compiler flags used for building the
|
165 |
|
|
target-side code. That code is fairly simple, so for nearly all
|
166 |
|
|
applications the default flags will suffice.
|
167 |
|
|
|
168 |
|
|
|
169 |
|
|
It should be noted that the watchdog device is subject to selective
|
170 |
|
|
linking. Unless some code explicitly references the device, for
|
171 |
|
|
example by calling the start and reset functions, the watchdog support
|
172 |
|
|
will not appear in the final executable. This is desirable because a
|
173 |
|
|
watchdog device has no effect until started.
|
174 |
|
|
|
175 |
|
|
|
176 |
|
|
|
177 |
|
|
Wallclock versus Elapsed Time
|
178 |
|
|
|
179 |
|
|
On real hardware the watchdog device uses wallclock time: if the
|
180 |
|
|
device does not receive a reset signal within a set period of time
|
181 |
|
|
then the watchdog will trigger. When developing for the synthetic
|
182 |
|
|
target this is not always appropriate. There may be other processes
|
183 |
|
|
running, using up some or most of the cpu time. For example, the
|
184 |
|
|
application may be written such that it will issue a reset after some
|
185 |
|
|
calculations which are known to complete within half a second, well
|
186 |
|
|
within the one-second resolution of the watchdog device. However if
|
187 |
|
|
other Linux processes are running then the synthetic target
|
188 |
|
|
application may get timesliced, and half a second of computation may
|
189 |
|
|
take several seconds of wallclock time.
|
190 |
|
|
|
191 |
|
|
|
192 |
|
|
Another problem with using wallclock time is that it interferes with
|
193 |
|
|
debugging: if the application hits a breakpoint then it is unlikely
|
194 |
|
|
that the user will manage to restart it in less than a second, and the
|
195 |
|
|
watchdog will not get reset in time.
|
196 |
|
|
|
197 |
|
|
|
198 |
|
|
To avoid these problems the synthetic target watchdog normally uses
|
199 |
|
|
consumed cpu time rather than wallclock time. If the application is
|
200 |
|
|
timesliced or if it is halted inside gdb then it does not consume any
|
201 |
|
|
cpu time. The application actually has to spend a whole second's worth
|
202 |
|
|
of cpu cycles without issuing a reset before the watchdog triggers.
|
203 |
|
|
|
204 |
|
|
|
205 |
|
|
However using consumed cpu time is not a perfect solution either. If
|
206 |
|
|
the application makes blocking system calls then it is not using cpu
|
207 |
|
|
time. Interaction with the I/O auxiliary involves system calls, but
|
208 |
|
|
these should take only a short amount of time so their effects can be
|
209 |
|
|
ignored. If the application makes direct system calls such as
|
210 |
|
|
cyg_hal_sys_read then the system behaviour
|
211 |
|
|
becomes undefined. In addition by default the idle thread will make
|
212 |
|
|
blocking select system calls, effectively waiting
|
213 |
|
|
until an interrupt occurs. If an application spends much of its time
|
214 |
|
|
idle then the watchdog device may take much longer to trigger than
|
215 |
|
|
expected. It may be desirable to enable the synthetic target HAL
|
216 |
|
|
configuration option CYGIMP_HAL_IDLE_THREAD_SPIN,
|
217 |
|
|
causing the idle thread to spin rather than block, at the cost of
|
218 |
|
|
wasted cpu cycles.
|
219 |
|
|
|
220 |
|
|
|
221 |
|
|
The default is to use consumed cpu time, but this can be changed in
|
222 |
|
|
the target definition file:
|
223 |
|
|
|
224 |
|
|
|
225 |
|
|
synth_device watchdog {
|
226 |
|
|
use wallclock_time
|
227 |
|
|
…
|
228 |
|
|
}
|
229 |
|
|
|
230 |
|
|
|
231 |
|
|
|
232 |
|
|
User Interface
|
233 |
|
|
|
234 |
|
|
When the synthetic target is run in graphical mode the watchdog device
|
235 |
|
|
extends the user interface in two ways. The Help
|
236 |
|
|
menu is extended with an entry for the watchdog-specific
|
237 |
|
|
documentation. There is also a graphical display of the current state
|
238 |
|
|
of the watchdog. Initially the watchdog is asleep:
|
239 |
|
|
|
240 |
|
|
|
241 |
|
|
|
242 |
|
|
|
243 |
|
|
|
244 |
|
|
|
245 |
|
|
|
246 |
|
|
|
247 |
|
|
|
248 |
|
|
When application code starts the device the watchdog will begin to
|
249 |
|
|
keep an eye on things (or occasionally both eyes).
|
250 |
|
|
|
251 |
|
|
|
252 |
|
|
|
253 |
|
|
|
254 |
|
|
|
255 |
|
|
|
256 |
|
|
|
257 |
|
|
|
258 |
|
|
|
259 |
|
|
If the watchdog triggers the display will change again, and optionally
|
260 |
|
|
the user can receive an audible alert. The location of the watchdog
|
261 |
|
|
display within the I/O auxiliary's window can be controlled via
|
262 |
|
|
a watchdog_pack entry in the target definition
|
263 |
|
|
file. For example the following can be used to put the watchdog
|
264 |
|
|
display to the right of the central text window:
|
265 |
|
|
|
266 |
|
|
|
267 |
|
|
synth_device watchdog {
|
268 |
|
|
watchdog_pack -in .main.e -side top
|
269 |
|
|
…
|
270 |
|
|
}
|
271 |
|
|
|
272 |
|
|
|
273 |
|
|
The user interface section of the generic synthetic target HAL
|
274 |
|
|
documentation can be consulted for more information on window packing.
|
275 |
|
|
|
276 |
|
|
|
277 |
|
|
By default the watchdog support will not generate an audible alert
|
278 |
|
|
when the watchdog triggers, to avoid annoying colleagues. Sound can be
|
279 |
|
|
enabled in the target definition file, and two suitable files
|
280 |
|
|
sound1.au and sound2.au are
|
281 |
|
|
supplied as standard:
|
282 |
|
|
|
283 |
|
|
|
284 |
|
|
synth_device watchdog {
|
285 |
|
|
sound sound1.au
|
286 |
|
|
…
|
287 |
|
|
}
|
288 |
|
|
|
289 |
|
|
|
290 |
|
|
An absolute path can be specified if desired:
|
291 |
|
|
|
292 |
|
|
|
293 |
|
|
synth_device watchdog {
|
294 |
|
|
sound /usr/share/emacs/site-lisp/emacspeak/sounds/default-8k/alarm.au
|
295 |
|
|
…
|
296 |
|
|
}
|
297 |
|
|
|
298 |
|
|
|
299 |
|
|
Sound facilities are not built into the I/O auxiliary itself, instead
|
300 |
|
|
an external program is used. The default player is
|
301 |
|
|
play, a front-end to the
|
302 |
|
|
sox application shipped with some Linux
|
303 |
|
|
distributions. If another player should be used then this can be
|
304 |
|
|
specified in the target definition file:
|
305 |
|
|
|
306 |
|
|
|
307 |
|
|
synth_device watchdog {
|
308 |
|
|
…
|
309 |
|
|
sound_player my_sound_player
|
310 |
|
|
|
311 |
|
|
|
312 |
|
|
The specified program will be run in the background with a single
|
313 |
|
|
argument, the sound file.
|
314 |
|
|
|
315 |
|
|
|
316 |
|
|
|
317 |
|
|
Command Line Arguments
|
318 |
|
|
|
319 |
|
|
The watchdog support does not use any command line arguments. All
|
320 |
|
|
configuration is handled through the target definition file.
|
321 |
|
|
|
322 |
|
|
|
323 |
|
|
|
324 |
|
|
Hooks
|
325 |
|
|
|
326 |
|
|
The watchdog support does not provide any hooks for use by other
|
327 |
|
|
scripts. There is rarely any need for customizing the system's
|
328 |
|
|
behaviour when a watchdog triggers because those should be rare
|
329 |
|
|
events, even during application development.
|
330 |
|
|
|
331 |
|
|
|
332 |
|
|
|
333 |
|
|
Additional Tcl Procedures
|
334 |
|
|
|
335 |
|
|
The watchdog support does not provide any additional Tcl procedures or
|
336 |
|
|
variables for use by other scripts.
|
337 |
|
|
|
338 |
|
|
|
339 |
|
|
|
340 |
|
|
|
341 |
|
|
|
342 |
|
|
|