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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [common/] [current/] [tests/] [cache.c] - Blame information for rev 867

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

Line No. Rev Author Line
1 786 skrzyp
/*=================================================================
2
//
3
//        cache.c
4
//
5
//        HAL Cache timing 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):     dsm
43
// Contributors:    dsm, nickg
44
// Date:          1998-06-18
45
//####DESCRIPTIONEND####
46
*/
47
 
48
#include <pkgconf/hal.h>
49
 
50
#include <cyg/infra/testcase.h>
51
 
52
#include <cyg/hal/hal_cache.h>
53
#include <cyg/hal/hal_intr.h>
54
#include <cyg/infra/diag.h>
55
 
56
#if defined(HAL_DCACHE_SIZE) && HAL_DCACHE_SIZE != 0
57
 
58
// -------------------------------------------------------------------------
59
// If the HAL does not supply this, we supply our own version
60
 
61
#ifndef HAL_DCACHE_PURGE_ALL
62
 
63
#ifdef HAL_DCACHE_SYNC
64
 
65
# define HAL_DCACHE_PURGE_ALL() HAL_DCACHE_SYNC()
66
 
67
#else
68
 
69
static cyg_uint8 dca[HAL_DCACHE_SIZE + HAL_DCACHE_LINE_SIZE*2];
70
 
71
#define HAL_DCACHE_PURGE_ALL()                                          \
72
CYG_MACRO_START                                                         \
73
    volatile cyg_uint8 *addr = &dca[HAL_DCACHE_LINE_SIZE];              \
74
    volatile cyg_uint8 tmp = 0;                                         \
75
    int i;                                                              \
76
    for( i = 0; i < HAL_DCACHE_SIZE; i += HAL_DCACHE_LINE_SIZE )        \
77
    {                                                                   \
78
        tmp = addr[i];                                                  \
79
    }                                                                   \
80
CYG_MACRO_END
81
 
82
#endif // HAL_DCACHE_SYNC
83
 
84
#endif // HAL_DCACHE_PURGE_ALL
85
 
86
// -------------------------------------------------------------------------
87
 
88
#ifndef MAX_STRIDE
89
#define MAX_STRIDE 64
90
#endif
91
 
92
volatile char m[(HAL_DCACHE_SIZE/HAL_DCACHE_LINE_SIZE)*MAX_STRIDE];
93
 
94
// -------------------------------------------------------------------------
95
 
96
static void time0(register cyg_uint32 stride)
97
{
98
    register cyg_uint32 j,k;
99
    register char c;
100
 
101
    diag_printf("stride=%d\n", stride);
102
 
103
    k = 0;
104
    if ( cyg_test_is_simulator )
105
        k = 3960;
106
 
107
    for(; k<4000;k++) {
108
        for(j=0; j<(HAL_DCACHE_SIZE/HAL_DCACHE_LINE_SIZE); j++) {
109
            c=m[stride*j];
110
        }
111
    }
112
}
113
 
114
// -------------------------------------------------------------------------
115
 
116
void time1(void)
117
{
118
    cyg_uint32 i;
119
 
120
    for(i=1; i<=MAX_STRIDE; i+=i) {
121
        time0(i);
122
    }
123
}
124
 
125
// -------------------------------------------------------------------------
126
// This test could be improved by counting number of passes possible 
127
// in a given number of ticks.
128
 
129
static void entry0( void )
130
{
131
    register CYG_INTERRUPT_STATE oldints;
132
 
133
#ifdef HAL_CACHE_UNIFIED
134
 
135
    HAL_DISABLE_INTERRUPTS(oldints);
136
    HAL_DCACHE_PURGE_ALL();             // rely on above definition
137
    HAL_UCACHE_INVALIDATE_ALL();
138
    HAL_UCACHE_DISABLE();
139
    HAL_RESTORE_INTERRUPTS(oldints);
140
    CYG_TEST_INFO("Cache off");
141
    time1();
142
 
143
    HAL_DISABLE_INTERRUPTS(oldints);
144
    HAL_DCACHE_PURGE_ALL();             // rely on above definition
145
    HAL_UCACHE_INVALIDATE_ALL();
146
    HAL_UCACHE_ENABLE();
147
    HAL_RESTORE_INTERRUPTS(oldints);
148
    CYG_TEST_INFO("Cache on");
149
    time1();
150
 
151
#else // HAL_CACHE_UNIFIED
152
 
153
    HAL_DISABLE_INTERRUPTS(oldints);
154
    HAL_DCACHE_PURGE_ALL();
155
    HAL_ICACHE_INVALIDATE_ALL();
156
    HAL_DCACHE_INVALIDATE_ALL();
157
    HAL_ICACHE_DISABLE();
158
    HAL_DCACHE_DISABLE();
159
    HAL_RESTORE_INTERRUPTS(oldints);
160
    CYG_TEST_INFO("Dcache off Icache off");
161
    time1();
162
 
163
    HAL_DISABLE_INTERRUPTS(oldints);
164
    HAL_DCACHE_PURGE_ALL();
165
    HAL_ICACHE_INVALIDATE_ALL();
166
    HAL_DCACHE_INVALIDATE_ALL();
167
    HAL_ICACHE_DISABLE();
168
    HAL_DCACHE_ENABLE();
169
    HAL_RESTORE_INTERRUPTS(oldints);
170
    CYG_TEST_INFO("Dcache on  Icache off");
171
    time1();
172
 
173
    HAL_DISABLE_INTERRUPTS(oldints);
174
    HAL_DCACHE_PURGE_ALL();
175
    HAL_ICACHE_INVALIDATE_ALL();
176
    HAL_DCACHE_INVALIDATE_ALL();
177
    HAL_ICACHE_ENABLE();
178
    HAL_DCACHE_DISABLE();
179
    HAL_RESTORE_INTERRUPTS(oldints);
180
    CYG_TEST_INFO("Dcache off Icache on");
181
    time1();
182
 
183
    HAL_DISABLE_INTERRUPTS(oldints);
184
    HAL_DCACHE_PURGE_ALL();
185
    HAL_ICACHE_INVALIDATE_ALL();
186
    HAL_DCACHE_INVALIDATE_ALL();
187
    HAL_ICACHE_ENABLE();
188
    HAL_DCACHE_ENABLE();
189
    HAL_RESTORE_INTERRUPTS(oldints);
190
    CYG_TEST_INFO("Dcache on  Icache on");
191
    time1();
192
 
193
    HAL_DISABLE_INTERRUPTS(oldints);
194
    HAL_DCACHE_PURGE_ALL();
195
    HAL_ICACHE_INVALIDATE_ALL();
196
    HAL_DCACHE_INVALIDATE_ALL();
197
    HAL_ICACHE_DISABLE();
198
    HAL_DCACHE_DISABLE();
199
    HAL_RESTORE_INTERRUPTS(oldints);
200
    CYG_TEST_INFO("Dcache off Icache off");
201
    time1();
202
 
203
#endif // HAL_CACHE_UNIFIED
204
 
205
    CYG_TEST_PASS_FINISH("End of test");
206
}
207
 
208
// -------------------------------------------------------------------------
209
 
210
void cache_main( void )
211
{
212
    CYG_TEST_INIT();
213
 
214
    entry0();
215
 
216
}
217
 
218
// -------------------------------------------------------------------------
219
 
220
externC void
221
cyg_start( void )
222
{
223
    cache_main();
224
}
225
 
226
#else // HAL_DCACHE_SIZE
227
#define N_A_MSG "No cache"
228
#endif // HAL_DCACHE_SIZE
229
 
230
#ifdef N_A_MSG
231
externC void
232
cyg_start( void )
233
{
234
    CYG_TEST_INIT();
235
    CYG_TEST_NA( N_A_MSG );
236
}
237
#endif // N_A_MSG
238
 
239
// -------------------------------------------------------------------------
240
/* EOF cache.c */

powered by: WebSVN 2.1.0

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