comparison packages/io/watchdog/current/tests/watchdog_reset.cxx @ 94:4642a6d35749 ecos-sw-2000-06-02

Merge from eCos master repository on 2000-06-02-07:47:04-BST
author jlarmour
date Fri, 02 Jun 2000 17:35:00 +0000
parents
children e0c0827131d1
comparison
equal deleted inserted replaced
93:8c2901fd1dc1 94:4642a6d35749
1 //==========================================================================
2 //
3 // watchdog_reset.cxx
4 //
5 // Watchdog reset test
6 //
7 //==========================================================================
8 //####COPYRIGHTBEGIN####
9 //
10 // -------------------------------------------
11 // The contents of this file are subject to the Red Hat eCos Public License
12 // Version 1.1 (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://www.redhat.com/
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 Configurable Operating System,
22 // released September 30, 1998.
23 //
24 // The Initial Developer of the Original Code is Red Hat.
25 // Portions created by Red Hat are
26 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
27 // All Rights Reserved.
28 // -------------------------------------------
29 //
30 //####COPYRIGHTEND####
31 //==========================================================================
32 //#####DESCRIPTIONBEGIN####
33 //
34 // Author(s): jskov (based on watchdog.cxx)
35 // Contributors: jskov, nickg
36 // Date: 1999-08-27
37 // Description: Tests that the watchdog timer resets the board.
38 // This test needs to be run by an operator - automatic
39 // testing not possible.
40 //####DESCRIPTIONEND####
41 // -------------------------------------------------------------------------
42
43 #include <pkgconf/system.h>
44
45 #include <cyg/infra/testcase.h>
46 #include <cyg/infra/diag.h>
47
48 // Package requirements
49 #if defined(CYGPKG_KERNEL)
50
51 #include <pkgconf/kernel.h>
52
53 // Package option requirements
54 #if defined(CYGFUN_KERNEL_THREADS_TIMER) && \
55 defined(CYGVAR_KERNEL_COUNTERS_CLOCK)
56
57
58 #include <cyg/kernel/thread.inl>
59
60 #include <cyg/hal/hal_cache.h>
61
62 #include <cyg/io/watchdog.hxx> // watchdog API
63
64
65 // -------------------------------------------------------------------------
66 // Data for the test
67
68 #ifdef CYGNUM_HAL_STACK_SIZE_TYPICAL
69 #define STACKSIZE CYGNUM_HAL_STACK_SIZE_TYPICAL
70 #else
71 #define STACKSIZE (2*1024) // size of thread stack
72 #endif
73
74 char thread_stack[STACKSIZE];
75
76 inline void *operator new(size_t size, void *ptr) { return ptr; };
77
78 // array of threads.
79 char thread[sizeof(Cyg_Thread)];
80
81 Cyg_Thread *th;
82
83 //cyg_tick_count one_sec;
84 cyg_tick_count watchdog_delay;
85
86 // -------------------------------------------------------------------------
87 // Thread body
88
89 volatile int watchdog_accuracy = 50;
90
91 void watchdog_thread( CYG_ADDRWORD id )
92 {
93 diag_printf("Test of watchdog timer accuracy. Expect the test to run\n"
94 "for at least 10 times the watchdog timeout time. After\n"
95 "that time you may have to reset the board manually and/or\n"
96 "restart GDB which tends to get a little confused.\n");
97 diag_printf("When you get contact with the board again, read the value\n"
98 "in watchdog_accuracy - it should be close to 100 if the\n"
99 "watchdog timer is accurate.\n");
100
101 // Disable data cache so the variable in memory gets updated.
102 HAL_DCACHE_SYNC();
103 HAL_DCACHE_DISABLE();
104
105 Cyg_Watchdog::watchdog.start();
106 Cyg_Watchdog::watchdog.reset();
107
108 while (watchdog_accuracy < 400) {
109 Cyg_Watchdog::watchdog.reset();
110 th->delay( watchdog_delay*watchdog_accuracy/100 );
111 watchdog_accuracy += 5;
112 }
113
114 CYG_TEST_FAIL_FINISH("Watchdog failed to reset board. "
115 "Timer value is off by at least a factor of 4!");
116 }
117
118 // -------------------------------------------------------------------------
119
120
121 externC void
122 cyg_start( void )
123 {
124 CYG_TEST_INIT();
125
126 #if !defined(CYGIMP_WATCHDOG_EMULATE) && defined(CYGPKG_HAL_MN10300_STDEVAL1)
127 // Workaround for PR 17974
128 if( cyg_test_is_simulator )
129 CYG_TEST_NA("Watchdog device not implemented in MN10300 simulator.");
130 #endif
131
132
133 Cyg_Clock::cyg_resolution res = Cyg_Clock::real_time_clock->get_resolution();
134
135 cyg_uint64 wres = Cyg_Watchdog::watchdog.get_resolution();
136
137 // Calculate how many clock ticks there are in a watchdog cycle.
138
139 watchdog_delay = ((cyg_tick_count)wres * (cyg_tick_count)res.divisor );
140 watchdog_delay /= res.dividend;
141
142 th = new((void *)&thread) Cyg_Thread(CYG_SCHED_DEFAULT_INFO,
143 watchdog_thread,
144 0,
145 "watchdog_thread",
146 (CYG_ADDRESS)thread_stack,
147 STACKSIZE
148 );
149
150 th->resume();
151
152 // Get the world going
153 Cyg_Scheduler::scheduler.start();
154
155 }
156
157 #else // CYGFUN_KERNEL_THREADS_TIMER etc...
158 #define N_A_MSG "Needs kernel RTC/threads timer"
159 #endif
160
161 #else // CYGPKG_KERNEL
162 #define N_A_MSG "Needs Kernel"
163 #endif
164
165 #ifdef N_A_MSG
166 void
167 cyg_start( void )
168 {
169 CYG_TEST_INIT();
170 CYG_TEST_NA( N_A_MSG);
171 }
172 #endif // N_A_MSG
173
174 // -------------------------------------------------------------------------
175 // EOF watchdog_reset.cxx