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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [io/] [wallclock/] [current/] [tests/] [wallclock.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
//        wallclock.cxx
4
//
5
//        WallClock 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, 2003 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
44
// Date:          1998-07-20
45
// Description:   Tests the Kernel Wall Clock
46
//                This test exercises the WallClock class and checks that it
47
//                keeps time correctly.
48
//####DESCRIPTIONEND####
49
// -------------------------------------------------------------------------
50
 
51
#include <pkgconf/hal.h>
52
#include <pkgconf/kernel.h>
53
 
54
#include <cyg/kernel/thread.hxx>
55
#include <cyg/kernel/thread.inl>
56
#include <cyg/kernel/sched.hxx>
57
#include <cyg/kernel/mutex.hxx>
58
#include <cyg/kernel/sema.hxx>
59
#include <cyg/kernel/clock.hxx>
60
 
61
#include <cyg/kernel/diag.h>
62
 
63
#include <cyg/io/wallclock.hxx>         // The WallClock API
64
 
65
#include <cyg/infra/testcase.h>
66
 
67
#if defined(CYGFUN_KERNEL_THREADS_TIMER) && \
68
    defined(CYGVAR_KERNEL_COUNTERS_CLOCK)
69
 
70
#include <cyg/kernel/sched.inl>
71
 
72
// -------------------------------------------------------------------------
73
// Data for the test
74
 
75
#ifdef CYGNUM_HAL_STACK_SIZE_TYPICAL
76
#define STACKSIZE CYGNUM_HAL_STACK_SIZE_TYPICAL
77
#else
78
#define STACKSIZE       (2*1024)        // size of thread stack
79
#endif
80
 
81
char thread_stack[STACKSIZE];
82
 
83
inline void *operator new(size_t size, void *ptr) { return ptr; };
84
 
85
// array of threads.
86
char thread[sizeof(Cyg_Thread)];
87
 
88
Cyg_Thread *th;
89
 
90
// MN10300 sim takes 1min15secs to do one loop on 300MHz PII.
91
#define LOOPS_SIM       2
92
#define LOOPS_HW        10
93
 
94
cyg_int32 loops = LOOPS_HW;
95
cyg_tick_count one_sec;
96
 
97
// -------------------------------------------------------------------------
98
// Thread body
99
 
100
 
101
void wallclock_thread( CYG_ADDRWORD id )
102
{
103
    cyg_uint32 base;
104
    cyg_uint32 wtime;
105
    cyg_tick_count ticks;
106
    cyg_bool ok = true;
107
 
108
    CYG_TEST_INFO("Testing accuracy of wallclock (10 seconds silence)");
109
 
110
    // Check clock only every other second since the call itself may
111
    // take about a second.
112
 
113
    // Start by synchronizing to next wallclock increment, then wait for
114
    // a bit to get away from the exact time of the increment (or minor
115
    // inaccuracies in the HW clock will cause failures).
116
    wtime = Cyg_WallClock::wallclock->get_current_time();
117
    do {
118
        base = Cyg_WallClock::wallclock->get_current_time();
119
    } while (base == wtime);
120
    th->delay( one_sec/10 );
121
 
122
    for( int i = 0; i < loops; i += 2 )
123
    {
124
        // Make a note of the time
125
        ticks = Cyg_Clock::real_time_clock->current_value();
126
 
127
        wtime = Cyg_WallClock::wallclock->get_current_time();
128
        if(wtime != base+i)
129
        {
130
            diag_printf("offset %d, read %d, expected %d\n", i, wtime, base+i);
131
            ok = false;
132
        }
133
 
134
        // then calculate how much the above took so the delay
135
        // below can be made accurate.
136
        ticks = Cyg_Clock::real_time_clock->current_value() - ticks;
137
 
138
        th->delay( 2*one_sec - ticks );
139
    }
140
 
141
    if ( ! cyg_test_is_simulator ) {
142
        CYG_TEST_INFO("Tick output. Two seconds between each output.");
143
 
144
        // Start by synchronizing to next wallclock increment, then
145
        // wait for a bit to get away from the exact time of the
146
        // increment (or minor inaccuracies in the HW clock will cause
147
        // failures).
148
        wtime = Cyg_WallClock::wallclock->get_current_time();
149
        do {
150
            base = Cyg_WallClock::wallclock->get_current_time();
151
        } while (base == wtime);
152
        th->delay( one_sec/10 );
153
 
154
        for( int i = 0; i < loops; i += 2 )
155
        {
156
            // Make a note of the time
157
            ticks = Cyg_Clock::real_time_clock->current_value();
158
 
159
            wtime = Cyg_WallClock::wallclock->get_current_time();
160
            if(wtime != base+i)
161
            {
162
                diag_printf("wallclock drift: saw %d expected %d\n",
163
                            wtime, base+i);
164
            }
165
            CYG_TEST_STILL_ALIVE(i, "2xtick...");
166
 
167
            // then calculate how much the above took so the delay
168
            // below can be made accurate.
169
            ticks = Cyg_Clock::real_time_clock->current_value() - ticks;
170
 
171
            th->delay( 2*one_sec - ticks );
172
        }
173
    }
174
 
175
    if (ok)
176
        CYG_TEST_PASS_FINISH("Wallclock OK");
177
    else
178
        CYG_TEST_FAIL_FINISH( "Clock out of sync" );
179
 
180
}
181
 
182
// -------------------------------------------------------------------------
183
 
184
 
185
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
186
externC void
187
cyg_hal_invoke_constructors();
188
#endif
189
 
190
externC void
191
cyg_start( void )
192
{
193
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
194
    cyg_hal_invoke_constructors();
195
#endif
196
    CYG_TEST_INIT();
197
 
198
    // Dont run this test if we are in a simulator, it just takes far too long.
199
    if( cyg_test_is_simulator )
200
        CYG_TEST_NA("Wallclock test takes too long in simulators");
201
 
202
    CYG_TEST_INFO("Starting wallclock test");
203
 
204
    Cyg_Clock::cyg_resolution res = Cyg_Clock::real_time_clock->get_resolution();
205
 
206
    one_sec = ( res.divisor * 1000000000LL ) / res.dividend ;
207
 
208
    th = new((void *)&thread) Cyg_Thread(CYG_SCHED_DEFAULT_INFO,
209
                                         wallclock_thread,
210
                                         0,
211
                                         "wallclock_thread",
212
                                         (CYG_ADDRESS)thread_stack,
213
                                         STACKSIZE
214
        );
215
 
216
    th->resume();
217
 
218
    // Get the world going
219
    Cyg_Scheduler::scheduler.start();
220
 
221
}
222
 
223
#else // if defined(CYGFUN_KERNEL_THREADS_TIMER) etc...
224
 
225
externC void
226
cyg_start( void )
227
{
228
    CYG_TEST_INIT();
229
    CYG_TEST_NA("Kernel real-time clock/threads timer disabled");
230
}
231
 
232
#endif // if defined(CYGFUN_KERNEL_THREADS_TIMER) etc...
233
 
234
// -------------------------------------------------------------------------
235
// EOF wallclock.cxx

powered by: WebSVN 2.1.0

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