OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [io/] [watchdog/] [current/] [tests/] [watchdog2.cxx] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//        watchdog2.cxx
4
//
5
//        Watchdog 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 Free Software Foundation, 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      
16
// version.                                                                 
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT      
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
21
// for more details.                                                        
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
26
//
27
// As a special exception, if other files instantiate templates or use      
28
// macros or inline functions from this file, or you compile this file      
29
// and link it with other works to produce a work based on this file,       
30
// this file does not by itself cause the resulting work to be covered by   
31
// the GNU General Public License. However the source code for this file    
32
// must still be made available in accordance with section (3) of the GNU   
33
// General Public License v2.                                               
34
//
35
// This exception does not invalidate any other reasons why a work based    
36
// on this file might be covered by the GNU General Public License.         
37
// -------------------------------------------                              
38
// ####ECOSGPLCOPYRIGHTEND####                                              
39
//==========================================================================
40
//#####DESCRIPTIONBEGIN####
41
//
42
// Author(s):     nickg
43
// Contributors:  nickg, jskov
44
// Date:          1998-07-20
45
// Description:   Tests the watchdog driver.
46
//                This test tries to make sure the watchdog does not trigger
47
//                early. On boards where the watchdog performs a reset on
48
//                timeout, there will be no FAIL message - but it should
49
//                PASS even on those boards when the driver implementation
50
//                is correct.
51
//
52
//####DESCRIPTIONEND####
53
// -------------------------------------------------------------------------
54
 
55
#include <pkgconf/kernel.h>
56
 
57
#include <cyg/kernel/thread.hxx>
58
#include <cyg/kernel/thread.inl>
59
#include <cyg/kernel/sched.hxx>
60
#include <cyg/kernel/mutex.hxx>
61
#include <cyg/kernel/sema.hxx>
62
#include <cyg/kernel/clock.hxx>
63
 
64
#include <cyg/kernel/diag.h>
65
 
66
#include <cyg/io/watchdog.hxx>
67
 
68
#include <cyg/infra/testcase.h>
69
#include <cyg/infra/diag.h>
70
 
71
#if defined(CYGFUN_KERNEL_THREADS_TIMER) && \
72
    defined(CYGVAR_KERNEL_COUNTERS_CLOCK)
73
 
74
#include <cyg/kernel/sched.inl>
75
 
76
// -------------------------------------------------------------------------
77
// Data for the test
78
 
79
#ifdef CYGNUM_HAL_STACK_SIZE_TYPICAL
80
#define STACKSIZE CYGNUM_HAL_STACK_SIZE_TYPICAL
81
#else
82
#define STACKSIZE       (2*1024)        // size of thread stack
83
#endif
84
 
85
char thread_stack[STACKSIZE];
86
 
87
inline void *operator new(size_t size, void *ptr) { return ptr; };
88
 
89
// array of threads.
90
char thread[sizeof(Cyg_Thread)];
91
 
92
Cyg_Thread *th;
93
 
94
//cyg_tick_count one_sec;
95
cyg_tick_count watchdog_delay;
96
volatile bool watchdog_fired;
97
volatile cyg_tick_count watchdog_time;
98
 
99
#define WATCHDOG_CYCLES_PER_LOOP_HW     7
100
#define WATCHDOG_CYCLES_PER_LOOP_SIM    2
101
#define WATCHDOG_TICKS_TILL_TIMEOUT     10
102
 
103
// -------------------------------------------------------------------------
104
// Action functions:
105
 
106
#ifdef CYGINT_WATCHDOG_RESETS_ON_TIMEOUT
107
void watchdog_action1( CYG_ADDRWORD data )
108
{
109
    watchdog_fired = true;
110
    watchdog_time = Cyg_Clock::real_time_clock->current_value();
111
}
112
#endif
113
 
114
// -------------------------------------------------------------------------
115
// Thread body
116
 
117
void watchdog_thread( CYG_ADDRWORD id )
118
{
119
    cyg_tick_count watchdog_start_time;
120
    cyg_tick_count thread_start_time, thread_end_time;
121
    cyg_ucount8 watchdog_cycles_per_loop;
122
 
123
    if (cyg_test_is_simulator) {
124
        watchdog_cycles_per_loop = WATCHDOG_CYCLES_PER_LOOP_SIM;
125
    } else {
126
        watchdog_cycles_per_loop = WATCHDOG_CYCLES_PER_LOOP_HW;
127
    }
128
 
129
    CYG_TEST_INFO("Testing that watchdog does not fire early");
130
 
131
    watchdog_fired = false;
132
    Cyg_Watchdog::watchdog.start();
133
 
134
#ifdef CYGINT_WATCHDOG_RESETS_ON_TIMEOUT
135
    // First test that the watchdog does not trigger when being reset.
136
    Cyg_Watchdog_Action wdaction( watchdog_action1, 0 );
137
    wdaction.install();
138
#endif
139
    Cyg_Watchdog::watchdog.reset();
140
 
141
    watchdog_start_time = Cyg_Clock::real_time_clock->current_value();
142
    watchdog_fired = false;
143
 
144
    for( cyg_ucount8 i = 0; i < watchdog_cycles_per_loop; i++ ) {
145
        thread_start_time = Cyg_Clock::real_time_clock->current_value();
146
        th->delay( watchdog_delay-2 );
147
        Cyg_Watchdog::watchdog.reset();
148
        if (watchdog_fired) {
149
            thread_end_time = Cyg_Clock::real_time_clock->current_value();
150
            diag_printf("Watchdog fired prematurely after %d ticks\n",
151
                        (int)(watchdog_time - watchdog_start_time));
152
            diag_printf("  Thread slept for %d ticks, loop #%d\n",
153
                        (int)(thread_end_time - thread_start_time), i);
154
            CYG_TEST_FAIL_FINISH("Watchdog triggered unexpectedly");
155
            break;
156
        } else {
157
            // No printing - delays are fatal!
158
            // CYG_TEST_STILL_ALIVE(i, "Resetting watchdog...");
159
            Cyg_Watchdog::watchdog.reset();
160
            watchdog_fired = false;
161
            watchdog_start_time = Cyg_Clock::real_time_clock->current_value();
162
        }
163
    }
164
 
165
    CYG_TEST_PASS_FINISH("Watchdog OK");
166
}
167
 
168
// -------------------------------------------------------------------------
169
 
170
 
171
externC void
172
cyg_start( void )
173
{
174
    CYG_TEST_INIT();
175
 
176
#if !defined(CYGIMP_WATCHDOG_EMULATE) && defined(CYGPKG_HAL_MN10300_STDEVAL1)
177
    // Workaround for PR 17974
178
    if( cyg_test_is_simulator )
179
        CYG_TEST_NA("Watchdog device not implemented in MN10300 simulator.");
180
#endif
181
 
182
 
183
    Cyg_Clock::cyg_resolution res = Cyg_Clock::real_time_clock->get_resolution();
184
 
185
    cyg_uint64 wres = Cyg_Watchdog::watchdog.get_resolution();
186
 
187
    // Calculate how many clock ticks there are in a watchdog cycle.
188
 
189
    watchdog_delay = ((cyg_tick_count)wres * (cyg_tick_count)res.divisor );
190
    watchdog_delay /= res.dividend;
191
 
192
    th = new((void *)&thread) Cyg_Thread(CYG_SCHED_DEFAULT_INFO,
193
                                         watchdog_thread,
194
                                         0,
195
                                         "watchdog_thread",
196
                                         (CYG_ADDRESS)thread_stack,
197
                                         STACKSIZE
198
        );
199
 
200
    th->resume();
201
 
202
    // Get the world going
203
    Cyg_Scheduler::scheduler.start();
204
 
205
}
206
 
207
#else // if defined(CYGFUN_KERNEL_THREADS_TIMER) etc...
208
 
209
externC void
210
cyg_start( void )
211
{
212
    CYG_TEST_INIT();
213
    CYG_TEST_NA("Kernel real-time clock/threads timer disabled");
214
}
215
 
216
#endif // if defined(CYGFUN_KERNEL_THREADS_TIMER) etc...
217
 
218
// -------------------------------------------------------------------------
219
// EOF watchdog.cxx

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.