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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [io/] [watchdog/] [v2_0/] [tests/] [watchdog2.cxx] - Blame information for rev 27

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//==========================================================================
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 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):     nickg
44
// Contributors:  nickg, jskov
45
// Date:          1998-07-20
46
// Description:   Tests the watchdog driver.
47
//                This test tries to make sure the watchdog does not trigger
48
//                early. On boards where the watchdog performs a reset on
49
//                timeout, there will be no FAIL message - but it should
50
//                PASS even on those boards when the driver implementation
51
//                is correct.
52
//
53
//####DESCRIPTIONEND####
54
// -------------------------------------------------------------------------
55
 
56
#include <pkgconf/kernel.h>
57
 
58
#include <cyg/kernel/thread.hxx>
59
#include <cyg/kernel/thread.inl>
60
#include <cyg/kernel/sched.hxx>
61
#include <cyg/kernel/mutex.hxx>
62
#include <cyg/kernel/sema.hxx>
63
#include <cyg/kernel/clock.hxx>
64
 
65
#include <cyg/kernel/diag.h>
66
 
67
#include <cyg/io/watchdog.hxx>
68
 
69
#include <cyg/infra/testcase.h>
70
#include <cyg/infra/diag.h>
71
 
72
#if defined(CYGFUN_KERNEL_THREADS_TIMER) && \
73
    defined(CYGVAR_KERNEL_COUNTERS_CLOCK)
74
 
75
#include <cyg/kernel/sched.inl>
76
 
77
// -------------------------------------------------------------------------
78
// Data for the test
79
 
80
#ifdef CYGNUM_HAL_STACK_SIZE_TYPICAL
81
#define STACKSIZE CYGNUM_HAL_STACK_SIZE_TYPICAL
82
#else
83
#define STACKSIZE       (2*1024)        // size of thread stack
84
#endif
85
 
86
char thread_stack[STACKSIZE];
87
 
88
inline void *operator new(size_t size, void *ptr) { return ptr; };
89
 
90
// array of threads.
91
char thread[sizeof(Cyg_Thread)];
92
 
93
Cyg_Thread *th;
94
 
95
//cyg_tick_count one_sec;
96
cyg_tick_count watchdog_delay;
97
volatile bool watchdog_fired;
98
volatile cyg_tick_count watchdog_time;
99
 
100
#define WATCHDOG_CYCLES_PER_LOOP_HW     7
101
#define WATCHDOG_CYCLES_PER_LOOP_SIM    2
102
#define WATCHDOG_TICKS_TILL_TIMEOUT     10
103
 
104
// -------------------------------------------------------------------------
105
// Action functions:
106
 
107
#ifdef CYGINT_WATCHDOG_RESETS_ON_TIMEOUT
108
void watchdog_action1( CYG_ADDRWORD data )
109
{
110
    watchdog_fired = true;
111
    watchdog_time = Cyg_Clock::real_time_clock->current_value();
112
}
113
#endif
114
 
115
// -------------------------------------------------------------------------
116
// Thread body
117
 
118
void watchdog_thread( CYG_ADDRWORD id )
119
{
120
    cyg_tick_count watchdog_start_time;
121
    cyg_tick_count thread_start_time, thread_end_time;
122
    cyg_ucount8 watchdog_cycles_per_loop;
123
 
124
    if (cyg_test_is_simulator) {
125
        watchdog_cycles_per_loop = WATCHDOG_CYCLES_PER_LOOP_SIM;
126
    } else {
127
        watchdog_cycles_per_loop = WATCHDOG_CYCLES_PER_LOOP_HW;
128
    }
129
 
130
    CYG_TEST_INFO("Testing that watchdog does not fire early");
131
 
132
    watchdog_fired = false;
133
    Cyg_Watchdog::watchdog.start();
134
 
135
#ifdef CYGINT_WATCHDOG_RESETS_ON_TIMEOUT
136
    // First test that the watchdog does not trigger when being reset.
137
    Cyg_Watchdog_Action wdaction( watchdog_action1, 0 );
138
    wdaction.install();
139
#endif
140
    Cyg_Watchdog::watchdog.reset();
141
 
142
    watchdog_start_time = Cyg_Clock::real_time_clock->current_value();
143
    watchdog_fired = false;
144
 
145
    for( cyg_ucount8 i = 0; i < watchdog_cycles_per_loop; i++ ) {
146
        thread_start_time = Cyg_Clock::real_time_clock->current_value();
147
        th->delay( watchdog_delay-2 );
148
        Cyg_Watchdog::watchdog.reset();
149
        if (watchdog_fired) {
150
            thread_end_time = Cyg_Clock::real_time_clock->current_value();
151
            diag_printf("Watchdog fired prematurely after %d ticks\n",
152
                        (int)(watchdog_time - watchdog_start_time));
153
            diag_printf("  Thread slept for %d ticks, loop #%d\n",
154
                        (int)(thread_end_time - thread_start_time), i);
155
            CYG_TEST_FAIL_FINISH("Watchdog triggered unexpectedly");
156
            break;
157
        } else {
158
            // No printing - delays are fatal!
159
            // CYG_TEST_STILL_ALIVE(i, "Resetting watchdog...");
160
            Cyg_Watchdog::watchdog.reset();
161
            watchdog_fired = false;
162
            watchdog_start_time = Cyg_Clock::real_time_clock->current_value();
163
        }
164
    }
165
 
166
    CYG_TEST_PASS_FINISH("Watchdog OK");
167
}
168
 
169
// -------------------------------------------------------------------------
170
 
171
 
172
externC void
173
cyg_start( void )
174
{
175
    CYG_TEST_INIT();
176
 
177
#if !defined(CYGIMP_WATCHDOG_EMULATE) && defined(CYGPKG_HAL_MN10300_STDEVAL1)
178
    // Workaround for PR 17974
179
    if( cyg_test_is_simulator )
180
        CYG_TEST_NA("Watchdog device not implemented in MN10300 simulator.");
181
#endif
182
 
183
 
184
    Cyg_Clock::cyg_resolution res = Cyg_Clock::real_time_clock->get_resolution();
185
 
186
    cyg_uint64 wres = Cyg_Watchdog::watchdog.get_resolution();
187
 
188
    // Calculate how many clock ticks there are in a watchdog cycle.
189
 
190
    watchdog_delay = ((cyg_tick_count)wres * (cyg_tick_count)res.divisor );
191
    watchdog_delay /= res.dividend;
192
 
193
    th = new((void *)&thread) Cyg_Thread(CYG_SCHED_DEFAULT_INFO,
194
                                         watchdog_thread,
195
                                         0,
196
                                         "watchdog_thread",
197
                                         (CYG_ADDRESS)thread_stack,
198
                                         STACKSIZE
199
        );
200
 
201
    th->resume();
202
 
203
    // Get the world going
204
    Cyg_Scheduler::scheduler.start();
205
 
206
}
207
 
208
#else // if defined(CYGFUN_KERNEL_THREADS_TIMER) etc...
209
 
210
externC void
211
cyg_start( void )
212
{
213
    CYG_TEST_INIT();
214
    CYG_TEST_NA("Kernel real-time clock/threads timer disabled");
215
}
216
 
217
#endif // if defined(CYGFUN_KERNEL_THREADS_TIMER) etc...
218
 
219
// -------------------------------------------------------------------------
220
// EOF watchdog.cxx

powered by: WebSVN 2.1.0

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