What's the format of multidimensional data file for $readmem

P

Peng Yu

Guest
Hi,
Do somebody know what's the format of multidimensional data file for $readmemh?
For example, I have a memory
reg [1:0] mem [0:2][0:3];
How to write the file for the initialization of the memory.
$readmemh("mem.data", mem);
Best wishes,
Peng
 
yupeng_@hotmail.com (Peng Yu) wrote in message news:<d7b3726c.0307271553.18c57a12@posting.google.com>...

Do somebody know what's the format of multidimensional data file for $readmemh?
For example, I have a memory
reg [1:0] mem [0:2][0:3];
How to write the file for the initialization of the memory.
$readmemh("mem.data", mem);
There is no such format. $readmem was defined to read memories,
which are 1-dimensional arrays. It is not defined to read the
multi-dimensional arrays that were added in Verilog-2001. If
you want to use $readmem, then you will have to flatten your
array into a 1-dimensional array.

If you want to use multi-dimensional arrays, then you cannot
use $readmem to read values into them. However, Verilog-2001
also added general file reading capabilities to the language.
This allows you to write your own Verilog code to read data
files into your multi-dimensional arrays. For example, you
could write

integer i,j,fd,rv;

initial
begin
fd = $fopen( "mem.data", "r");
for (i = 0; i < 4; i = i + 1)
for (j = 0; j < 3; j = j + 1)
rv = $fscanf(fd, "%h", mem[j]);
end

Your code determines what order the elements will be read
and what format the input data must be in. If you wanted
to add more complex capabilities like embedding addresses
in the file, you could do so, but you would have to write
the Verilog code to parse and interpret the contents of
the file for yourself.

If your simulator supports Verilog-2001 multi-dimensional
arrays but does not support Verilog-2001 file I/O routines,
then you have a problem. I suppose you could write VPI to
do the job, assuming that your simulator supports VPI and
VPI access to multi-dimensional arrays.
 
integer i,j,fd,rv;

initial
begin
fd = $fopen( "mem.data", "r");
for (i = 0; i < 4; i = i + 1)
for (j = 0; j < 3; j = j + 1)
rv = $fscanf(fd, "%h", mem[j]);/* #1 rv = $fscanf(fd, "%h", mem[j]);*/
end
Do I need to add some delay to the line with comment? Otherwise, it doesn't work.

Peng
 
yupeng_@hotmail.com (Peng Yu) wrote in message news:<d7b3726c.0307292207.f229a17@posting.google.com>...
rv = $fscanf(fd, "%h", mem[j]);/* #1 rv = $fscanf(fd, "%h", mem[j]);*/
end
Do I need to add some delay to the line with comment? Otherwise, it doesn't work.

There is no reason to add a delay to the line. Presumably you want the
entire memory initialized at once at the start of the simulation, not
one location at a time. For a large memory, the later locations in the
memory wouldn't get initialized until a long time into the simulation
if you added a delay between initializing each location.

If it isn't working without a delay, then your simulator is broken.
 

Welcome to EDABoard.com

Sponsor

Back
Top