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

Subversion Repositories openrisc

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

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

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
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 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):     jskov (based on watchdog.cxx)
43
// Contributors:  jskov, nickg
44
// Date:          1999-08-27
45
// Description:   Tests that the watchdog timer resets the board.
46
//                This test needs to be run by an operator - automatic
47
//                testing not possible.
48
//####DESCRIPTIONEND####
49
// -------------------------------------------------------------------------
50
 
51
#include <pkgconf/system.h>
52
 
53
#include <cyg/infra/testcase.h>
54
#include <cyg/infra/diag.h>
55
 
56
// Package requirements
57
#if defined(CYGPKG_KERNEL)
58
 
59
#include <pkgconf/kernel.h>
60
 
61
// Package option requirements
62
#if defined(CYGFUN_KERNEL_THREADS_TIMER) && \
63
    defined(CYGVAR_KERNEL_COUNTERS_CLOCK)
64
 
65
 
66
#include <cyg/kernel/thread.inl>
67
 
68
#include <cyg/hal/hal_cache.h>
69
 
70
#include <cyg/io/watchdog.hxx>          // watchdog API
71
 
72
 
73
// -------------------------------------------------------------------------
74
// Data for the test
75
 
76
#ifdef CYGNUM_HAL_STACK_SIZE_TYPICAL
77
#define STACKSIZE CYGNUM_HAL_STACK_SIZE_TYPICAL
78
#else
79
#define STACKSIZE       (2*1024)        // size of thread stack
80
#endif
81
 
82
char thread_stack[STACKSIZE];
83
 
84
inline void *operator new(size_t size, void *ptr) { return ptr; };
85
 
86
// array of threads.
87
char thread[sizeof(Cyg_Thread)];
88
 
89
Cyg_Thread *th;
90
 
91
//cyg_tick_count one_sec;
92
cyg_tick_count watchdog_delay;
93
 
94
// -------------------------------------------------------------------------
95
// Thread body
96
 
97
volatile int watchdog_accuracy = 50;
98
 
99
void watchdog_thread( CYG_ADDRWORD id )
100
{
101
    diag_printf("Test of watchdog timer accuracy. Expect the test to run\n"
102
                "for at least 10 times the watchdog timeout time. After\n"
103
                "that time you may have to reset the board manually and/or\n"
104
                "restart GDB which tends to get a little confused.\n");
105
    diag_printf("When you get contact with the board again, read the value\n"
106
                "in watchdog_accuracy - it should be close to 100 if the\n"
107
                "watchdog timer is accurate.\n");
108
 
109
    // Disable data cache so the variable in memory gets updated.
110
    HAL_DCACHE_SYNC();
111
    HAL_DCACHE_DISABLE();
112
 
113
    Cyg_Watchdog::watchdog.start();
114
    Cyg_Watchdog::watchdog.reset();
115
 
116
    while (watchdog_accuracy < 400) {
117
        Cyg_Watchdog::watchdog.reset();
118
        th->delay( watchdog_delay*watchdog_accuracy/100 );
119
        watchdog_accuracy += 5;
120
    }
121
 
122
    CYG_TEST_FAIL_FINISH("Watchdog failed to reset board. "
123
                         "Timer value is off by at least a factor of 4!");
124
}
125
 
126
// -------------------------------------------------------------------------
127
 
128
 
129
externC void
130
cyg_start( void )
131
{
132
    CYG_TEST_INIT();
133
 
134
#if !defined(CYGIMP_WATCHDOG_EMULATE) && defined(CYGPKG_HAL_MN10300_STDEVAL1)
135
    // Workaround for PR 17974
136
    if( cyg_test_is_simulator )
137
        CYG_TEST_NA("Watchdog device not implemented in MN10300 simulator.");
138
#endif
139
 
140
 
141
    Cyg_Clock::cyg_resolution res = Cyg_Clock::real_time_clock->get_resolution();
142
 
143
    cyg_uint64 wres = Cyg_Watchdog::watchdog.get_resolution();
144
 
145
    // Calculate how many clock ticks there are in a watchdog cycle.
146
 
147
    watchdog_delay = ((cyg_tick_count)wres * (cyg_tick_count)res.divisor );
148
    watchdog_delay /= res.dividend;
149
 
150
    th = new((void *)&thread) Cyg_Thread(CYG_SCHED_DEFAULT_INFO,
151
                                         watchdog_thread,
152
                                         0,
153
                                         "watchdog_thread",
154
                                         (CYG_ADDRESS)thread_stack,
155
                                         STACKSIZE
156
        );
157
 
158
    th->resume();
159
 
160
    // Get the world going
161
    Cyg_Scheduler::scheduler.start();
162
 
163
}
164
 
165
#else // CYGFUN_KERNEL_THREADS_TIMER etc...
166
#define N_A_MSG "Needs kernel RTC/threads timer"
167
#endif
168
 
169
#else // CYGPKG_KERNEL
170
#define N_A_MSG "Needs Kernel"
171
#endif
172
 
173
#ifdef N_A_MSG
174
void
175
cyg_start( void )
176
{
177
    CYG_TEST_INIT();
178
    CYG_TEST_NA( N_A_MSG);
179
}
180
#endif // N_A_MSG
181
 
182
// -------------------------------------------------------------------------
183
// EOF watchdog_reset.cxx

powered by: WebSVN 2.1.0

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