1 |
27 |
unneback |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// watchdog_reset.cxx
|
4 |
|
|
//
|
5 |
|
|
// Watchdog reset test
|
6 |
|
|
//
|
7 |
|
|
//==========================================================================
|
8 |
|
|
//####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
// -------------------------------------------
|
10 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
|
12 |
|
|
//
|
13 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
14 |
|
|
// the terms of the GNU General Public License as published by the Free
|
15 |
|
|
// Software Foundation; either version 2 or (at your option) any later version.
|
16 |
|
|
//
|
17 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
|
18 |
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
19 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
20 |
|
|
// for more details.
|
21 |
|
|
//
|
22 |
|
|
// You should have received a copy of the GNU General Public License along
|
23 |
|
|
// with eCos; if not, write to the Free Software Foundation, Inc.,
|
24 |
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
25 |
|
|
//
|
26 |
|
|
// As a special exception, if other files instantiate templates or use macros
|
27 |
|
|
// or inline functions from this file, or you compile this file and link it
|
28 |
|
|
// with other works to produce a work based on this file, this file does not
|
29 |
|
|
// by itself cause the resulting work to be covered by the GNU General Public
|
30 |
|
|
// License. However the source code for this file must still be made available
|
31 |
|
|
// in accordance with section (3) of the GNU General Public License.
|
32 |
|
|
//
|
33 |
|
|
// This exception does not invalidate any other reasons why a work based on
|
34 |
|
|
// this file might be covered by the GNU General Public License.
|
35 |
|
|
//
|
36 |
|
|
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
|
37 |
|
|
// at http://sources.redhat.com/ecos/ecos-license/
|
38 |
|
|
// -------------------------------------------
|
39 |
|
|
//####ECOSGPLCOPYRIGHTEND####
|
40 |
|
|
//==========================================================================
|
41 |
|
|
//#####DESCRIPTIONBEGIN####
|
42 |
|
|
//
|
43 |
|
|
// Author(s): jskov (based on watchdog.cxx)
|
44 |
|
|
// Contributors: jskov, nickg
|
45 |
|
|
// Date: 1999-08-27
|
46 |
|
|
// Description: Tests that the watchdog timer resets the board.
|
47 |
|
|
// This test needs to be run by an operator - automatic
|
48 |
|
|
// testing not possible.
|
49 |
|
|
//####DESCRIPTIONEND####
|
50 |
|
|
// -------------------------------------------------------------------------
|
51 |
|
|
|
52 |
|
|
#include <pkgconf/system.h>
|
53 |
|
|
|
54 |
|
|
#include <cyg/infra/testcase.h>
|
55 |
|
|
#include <cyg/infra/diag.h>
|
56 |
|
|
|
57 |
|
|
// Package requirements
|
58 |
|
|
#if defined(CYGPKG_KERNEL)
|
59 |
|
|
|
60 |
|
|
#include <pkgconf/kernel.h>
|
61 |
|
|
|
62 |
|
|
// Package option requirements
|
63 |
|
|
#if defined(CYGFUN_KERNEL_THREADS_TIMER) && \
|
64 |
|
|
defined(CYGVAR_KERNEL_COUNTERS_CLOCK)
|
65 |
|
|
|
66 |
|
|
|
67 |
|
|
#include <cyg/kernel/thread.inl>
|
68 |
|
|
|
69 |
|
|
#include <cyg/hal/hal_cache.h>
|
70 |
|
|
|
71 |
|
|
#include <cyg/io/watchdog.hxx> // watchdog API
|
72 |
|
|
|
73 |
|
|
|
74 |
|
|
// -------------------------------------------------------------------------
|
75 |
|
|
// Data for the test
|
76 |
|
|
|
77 |
|
|
#ifdef CYGNUM_HAL_STACK_SIZE_TYPICAL
|
78 |
|
|
#define STACKSIZE CYGNUM_HAL_STACK_SIZE_TYPICAL
|
79 |
|
|
#else
|
80 |
|
|
#define STACKSIZE (2*1024) // size of thread stack
|
81 |
|
|
#endif
|
82 |
|
|
|
83 |
|
|
char thread_stack[STACKSIZE];
|
84 |
|
|
|
85 |
|
|
inline void *operator new(size_t size, void *ptr) { return ptr; };
|
86 |
|
|
|
87 |
|
|
// array of threads.
|
88 |
|
|
char thread[sizeof(Cyg_Thread)];
|
89 |
|
|
|
90 |
|
|
Cyg_Thread *th;
|
91 |
|
|
|
92 |
|
|
//cyg_tick_count one_sec;
|
93 |
|
|
cyg_tick_count watchdog_delay;
|
94 |
|
|
|
95 |
|
|
// -------------------------------------------------------------------------
|
96 |
|
|
// Thread body
|
97 |
|
|
|
98 |
|
|
volatile int watchdog_accuracy = 50;
|
99 |
|
|
|
100 |
|
|
void watchdog_thread( CYG_ADDRWORD id )
|
101 |
|
|
{
|
102 |
|
|
diag_printf("Test of watchdog timer accuracy. Expect the test to run\n"
|
103 |
|
|
"for at least 10 times the watchdog timeout time. After\n"
|
104 |
|
|
"that time you may have to reset the board manually and/or\n"
|
105 |
|
|
"restart GDB which tends to get a little confused.\n");
|
106 |
|
|
diag_printf("When you get contact with the board again, read the value\n"
|
107 |
|
|
"in watchdog_accuracy - it should be close to 100 if the\n"
|
108 |
|
|
"watchdog timer is accurate.\n");
|
109 |
|
|
|
110 |
|
|
// Disable data cache so the variable in memory gets updated.
|
111 |
|
|
HAL_DCACHE_SYNC();
|
112 |
|
|
HAL_DCACHE_DISABLE();
|
113 |
|
|
|
114 |
|
|
Cyg_Watchdog::watchdog.start();
|
115 |
|
|
Cyg_Watchdog::watchdog.reset();
|
116 |
|
|
|
117 |
|
|
while (watchdog_accuracy < 400) {
|
118 |
|
|
Cyg_Watchdog::watchdog.reset();
|
119 |
|
|
th->delay( watchdog_delay*watchdog_accuracy/100 );
|
120 |
|
|
watchdog_accuracy += 5;
|
121 |
|
|
}
|
122 |
|
|
|
123 |
|
|
CYG_TEST_FAIL_FINISH("Watchdog failed to reset board. "
|
124 |
|
|
"Timer value is off by at least a factor of 4!");
|
125 |
|
|
}
|
126 |
|
|
|
127 |
|
|
// -------------------------------------------------------------------------
|
128 |
|
|
|
129 |
|
|
|
130 |
|
|
externC void
|
131 |
|
|
cyg_start( void )
|
132 |
|
|
{
|
133 |
|
|
CYG_TEST_INIT();
|
134 |
|
|
|
135 |
|
|
#if !defined(CYGIMP_WATCHDOG_EMULATE) && defined(CYGPKG_HAL_MN10300_STDEVAL1)
|
136 |
|
|
// Workaround for PR 17974
|
137 |
|
|
if( cyg_test_is_simulator )
|
138 |
|
|
CYG_TEST_NA("Watchdog device not implemented in MN10300 simulator.");
|
139 |
|
|
#endif
|
140 |
|
|
|
141 |
|
|
|
142 |
|
|
Cyg_Clock::cyg_resolution res = Cyg_Clock::real_time_clock->get_resolution();
|
143 |
|
|
|
144 |
|
|
cyg_uint64 wres = Cyg_Watchdog::watchdog.get_resolution();
|
145 |
|
|
|
146 |
|
|
// Calculate how many clock ticks there are in a watchdog cycle.
|
147 |
|
|
|
148 |
|
|
watchdog_delay = ((cyg_tick_count)wres * (cyg_tick_count)res.divisor );
|
149 |
|
|
watchdog_delay /= res.dividend;
|
150 |
|
|
|
151 |
|
|
th = new((void *)&thread) Cyg_Thread(CYG_SCHED_DEFAULT_INFO,
|
152 |
|
|
watchdog_thread,
|
153 |
|
|
0,
|
154 |
|
|
"watchdog_thread",
|
155 |
|
|
(CYG_ADDRESS)thread_stack,
|
156 |
|
|
STACKSIZE
|
157 |
|
|
);
|
158 |
|
|
|
159 |
|
|
th->resume();
|
160 |
|
|
|
161 |
|
|
// Get the world going
|
162 |
|
|
Cyg_Scheduler::scheduler.start();
|
163 |
|
|
|
164 |
|
|
}
|
165 |
|
|
|
166 |
|
|
#else // CYGFUN_KERNEL_THREADS_TIMER etc...
|
167 |
|
|
#define N_A_MSG "Needs kernel RTC/threads timer"
|
168 |
|
|
#endif
|
169 |
|
|
|
170 |
|
|
#else // CYGPKG_KERNEL
|
171 |
|
|
#define N_A_MSG "Needs Kernel"
|
172 |
|
|
#endif
|
173 |
|
|
|
174 |
|
|
#ifdef N_A_MSG
|
175 |
|
|
void
|
176 |
|
|
cyg_start( void )
|
177 |
|
|
{
|
178 |
|
|
CYG_TEST_INIT();
|
179 |
|
|
CYG_TEST_NA( N_A_MSG);
|
180 |
|
|
}
|
181 |
|
|
#endif // N_A_MSG
|
182 |
|
|
|
183 |
|
|
// -------------------------------------------------------------------------
|
184 |
|
|
// EOF watchdog_reset.cxx
|