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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [sparclite/] [sleb/] [current/] [tests/] [slebtime.cxx] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
/*=================================================================
2
//
3
//        slebtime.cxx
4
//
5
//        SPARClite HAL timing tests
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):     dsm
43
// Contributors:    dsm, nickg
44
// Date:          1998-06-18
45
//####DESCRIPTIONEND####
46
*/
47
 
48
#include <pkgconf/system.h>
49
#include <pkgconf/hal.h>
50
 
51
#include <cyg/infra/cyg_type.h>
52
#include <cyg/infra/cyg_ass.h>
53
#include <cyg/infra/testcase.h>
54
 
55
#ifdef CYGPKG_KERNEL
56
 
57
#include <pkgconf/kernel.h>
58
 
59
#ifdef CYGVAR_KERNEL_COUNTERS_CLOCK
60
 
61
#include <cyg/hal/hal_arch.h>
62
#include <cyg/hal/hal_intr.h>
63
#include <cyg/hal/hal_diag.h>
64
#include <cyg/hal/hal_clock.h>
65
 
66
#include <pkgconf/infra.h>
67
 
68
#include <cyg/infra/diag.h>
69
 
70
#include <cyg/kernel/thread.hxx>
71
#include <cyg/kernel/thread.inl>
72
#include <cyg/kernel/sched.hxx>
73
#include <cyg/kernel/sched.inl>
74
 
75
// -------------------------------------------------------------------------
76
 
77
static void entry1( CYG_ADDRWORD arg )
78
{
79
    int i;
80
    char *s = "tick 00";
81
    extern Cyg_Thread thread2;
82
    CYG_TEST_INFO( "Starting measured seconds..." );
83
    for ( i = 0; i < 20 ; i++ ) {
84
        Cyg_Thread::self()->delay( 100 ); // units should be centiSeconds
85
        if ( '9' == s[ 6 ]++ ) {
86
            s[ 6 ] = '0';
87
            s[ 5 ] ++;
88
        }
89
        CYG_TEST_INFO( s );
90
    }
91
    CYG_TEST_PASS( "Done measured seconds..." );
92
    thread2.resume();
93
}
94
 
95
static void entry2( CYG_ADDRWORD arg )
96
{
97
#define LOOPS 30
98
    int i, t1, t2, a;
99
    int loops[ LOOPS ] = { 0,0,0,0,0 , 0,0,0,0,0 ,
100
                           0,0,0,0,0 , 0,0,0,0,0 ,
101
                           0,0,0,0,0 , 0,0,0,0,0 };
102
 
103
    char s[] = "0 count 00 loops 00000";
104
 
105
    for ( a = 0; a < 10; a++, (*s)++ ) {
106
        CYG_TEST_INFO( "------------------------------------------" );
107
        HAL_CLOCK_READ( &t1 );
108
        do {
109
            t2 = t1;
110
            HAL_CLOCK_READ( &t1 );
111
        } while ( t1 >= t2 );
112
 
113
        for ( i = 0; i < LOOPS; i++ ) {
114
            register int z = 0;
115
            while ( t1 <= i ) {
116
                z++;
117
                HAL_CLOCK_READ( &t1 );
118
            }
119
            loops[ i ] = z;
120
        }
121
 
122
        s[9] = '0';
123
        s[8] = '0';
124
        for ( i = 0; i < LOOPS; i++ ) {
125
            s[ sizeof( s ) - 2 ] = '0' + loops[ i ] / 1       % 10;
126
            s[ sizeof( s ) - 3 ] = '0' + loops[ i ] / 10      % 10;
127
            s[ sizeof( s ) - 4 ] = '0' + loops[ i ] / 100     % 10;
128
            s[ sizeof( s ) - 5 ] = '0' + loops[ i ] / 1000    % 10;
129
            s[ sizeof( s ) - 6 ] = '0' + loops[ i ] / 10000   % 10;
130
            CYG_TEST_INFO( s );
131
            if ( '9' == s[9]++ ) {
132
                s[9] = '0';
133
                s[8]++;
134
            }
135
        }
136
    }
137
    CYG_TEST_PASS( "Counted loops per timer tick" );
138
    CYG_TEST_EXIT( "All done" );
139
}
140
 
141
// -------------------------------------------------------------------------
142
 
143
static char stack1[ CYGNUM_HAL_STACK_SIZE_TYPICAL ];
144
static char stack2[ CYGNUM_HAL_STACK_SIZE_TYPICAL ];
145
 
146
static Cyg_Thread thread1     CYG_INIT_PRIORITY( APPLICATION )
147
 = Cyg_Thread( 2u, entry1, 0u, "timed minute thread",
148
               (CYG_ADDRWORD)stack1,
149
               (CYG_ADDRWORD)CYGNUM_HAL_STACK_SIZE_TYPICAL );
150
 
151
static Cyg_Thread thread2     CYG_INIT_PRIORITY( APPLICATION )
152
 = Cyg_Thread( 4u, entry2, 0u, "uS clock loops timing thread",
153
               (CYG_ADDRWORD)stack2,
154
               (CYG_ADDRWORD)CYGNUM_HAL_STACK_SIZE_TYPICAL );
155
 
156
// -------------------------------------------------------------------------
157
 
158
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
159
externC void
160
cyg_hal_invoke_constructors();
161
#endif
162
 
163
externC void
164
cyg_user_start( void )
165
{
166
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
167
    cyg_hal_invoke_constructors();
168
#endif
169
    CYG_TEST_INIT();
170
    CYG_TEST_INFO( "cyg_user_start()" );
171
    thread1.resume();
172
}
173
 
174
// -------------------------------------------------------------------------
175
 
176
#else  // ! CYGVAR_KERNEL_COUNTERS_CLOCK
177
#define N_A_MSG "no kernel clock"
178
#endif // CYGVAR_KERNEL_COUNTERS_CLOCK
179
#else  // ! CYGPKG_KERNEL
180
#define N_A_MSG "no kernel"
181
#endif // CYGPKG_KERNEL
182
 
183
#ifdef N_A_MSG
184
externC void
185
cyg_start( void )
186
{
187
    CYG_TEST_INIT();
188
    CYG_TEST_NA( N_A_MSG );
189
}
190
#endif // N_A_MSG defined ie. we are N/A.
191
 
192
/* EOF slebtime.cxx */

powered by: WebSVN 2.1.0

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