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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [common/] [v2_0/] [tests/] [cache.c] - Blame information for rev 174

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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