Digital Signal Processing Reference
In-Depth Information
16.13 Testing SRAM
To test the SRAM, you will write a large number of values to memory and then
read back from the same memory locations to verify that the contents of
memory are what you expect. Since SRAM is currently being used for program
and data memory, accessing SRAM is straight-forward. Any array that is
created in a function will be stored in data memory (e.g., in SRAM). The code
for
test_sram
is shown in Figure 16.16. You will notice that this code expects
the constant value
SRAM_MAX_WORDS
to be defined. Add a definition for
this constant to your
rpds_de_test.h
header file and set it equal to
8000
.
This test routine assumes that there is not a data cache memory present in the
Nios II system. If data cache is present, then declaring an array in a function
like
test_sram
would not ensure SRAM writes, because the data cache memory
could be used as a temporary buffer. Since this function is very short and the
array's scope is internal to the function, it is highly likely that the array data
would never be written to SRAM. To avoid these potential issues, the reference
hardware design used in this tutorial does
not
include data cache.
T
HERE ARE SEVERAL WAYS TO BYPASS DATA CACHE IN THE
N
IOS
II
PROCESSOR
.
(1)
CREATE A
BUFFER THAT IS LARGER THAN THE DATA CACHE TO FORCE AT LEAST SOME
SRAM
ACCESSES
.
(2)
USE SPECIAL MEMORY ACCESS INSTRUCTIONS
(
SUCH AS
LWIO
AND
SWIO)
IN THE
N
IOS
II
INSTRUCTION SET THAT BYPASS DATA CACHE AND FORCE A MEMORY ACCESS
.
alt_u32 test_sram( void )
{
alt_u32 i, val;
alt_u32 errors = 0;
alt_u32 buffer[SRAM_MAX_WORDS];
/* Write data to SRAM */
for( i = 0; i < SRAM_MAX_WORDS; i++ ) {
buffer[i] = i + 1000;
}
/* Check output from SRAM */
for( i = 0; i < SRAM_MAX_WORDS; i++ ) {
if( buffer[i] != (i+1000) )
errors++;
}
return( errors );
}
Figure 16.16
This is the code to test the SRAM memory device.