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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [io/] [wallclock/] [v2_0/] [tests/] [wallclock.cxx] - Blame information for rev 584

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

Line No. Rev Author Line
1 27 unneback
//==========================================================================
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 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
45
// Date:          1998-07-20
46
// Description:   Tests the Kernel Wall Clock
47
//                This test exercises the WallClock class and checks that it
48
//                keeps time correctly.
49
//####DESCRIPTIONEND####
50
// -------------------------------------------------------------------------
51
 
52
#include <pkgconf/hal.h>
53
#include <pkgconf/kernel.h>
54
 
55
#include <cyg/kernel/thread.hxx>
56
#include <cyg/kernel/thread.inl>
57
#include <cyg/kernel/sched.hxx>
58
#include <cyg/kernel/mutex.hxx>
59
#include <cyg/kernel/sema.hxx>
60
#include <cyg/kernel/clock.hxx>
61
 
62
#include <cyg/kernel/diag.h>
63
 
64
#include <cyg/io/wallclock.hxx>         // The WallClock API
65
 
66
#include <cyg/infra/testcase.h>
67
 
68
#if defined(CYGFUN_KERNEL_THREADS_TIMER) && \
69
    defined(CYGVAR_KERNEL_COUNTERS_CLOCK)
70
 
71
#include <cyg/kernel/sched.inl>
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
// MN10300 sim takes 1min15secs to do one loop on 300MHz PII.
92
#define LOOPS_SIM       2
93
#define LOOPS_HW        10
94
 
95
cyg_int32 loops = LOOPS_HW;
96
cyg_tick_count one_sec;
97
 
98
// -------------------------------------------------------------------------
99
// Thread body
100
 
101
 
102
void wallclock_thread( CYG_ADDRWORD id )
103
{
104
    cyg_uint32 base;
105
    cyg_uint32 wtime;
106
    cyg_tick_count ticks;
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
            CYG_TEST_FAIL_FINISH( "Clock out of sync" );
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
    CYG_TEST_PASS_FINISH("Wallclock OK");
176
 
177
}
178
 
179
// -------------------------------------------------------------------------
180
 
181
 
182
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
183
externC void
184
cyg_hal_invoke_constructors();
185
#endif
186
 
187
externC void
188
cyg_start( void )
189
{
190
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
191
    cyg_hal_invoke_constructors();
192
#endif
193
    CYG_TEST_INIT();
194
 
195
    // Dont run this test if we are in a simulator, it just takes far too long.
196
    if( cyg_test_is_simulator )
197
        CYG_TEST_NA("Wallclock test takes too long in simulators");
198
 
199
    CYG_TEST_INFO("Starting wallclock test");
200
 
201
    Cyg_Clock::cyg_resolution res = Cyg_Clock::real_time_clock->get_resolution();
202
 
203
    one_sec = ( res.divisor * 1000000000LL ) / res.dividend ;
204
 
205
    th = new((void *)&thread) Cyg_Thread(CYG_SCHED_DEFAULT_INFO,
206
                                         wallclock_thread,
207
                                         0,
208
                                         "wallclock_thread",
209
                                         (CYG_ADDRESS)thread_stack,
210
                                         STACKSIZE
211
        );
212
 
213
    th->resume();
214
 
215
    // Get the world going
216
    Cyg_Scheduler::scheduler.start();
217
 
218
}
219
 
220
#else // if defined(CYGFUN_KERNEL_THREADS_TIMER) etc...
221
 
222
externC void
223
cyg_start( void )
224
{
225
    CYG_TEST_INIT();
226
    CYG_TEST_NA("Kernel real-time clock/threads timer disabled");
227
}
228
 
229
#endif // if defined(CYGFUN_KERNEL_THREADS_TIMER) etc...
230
 
231
// -------------------------------------------------------------------------
232
// EOF wallclock.cxx

powered by: WebSVN 2.1.0

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