Reading files in multiple instances of a ROM model

Guest
Hi there!

I have a ROM model, and I use $readmemh to read its memory file.

I have multiple instances of this ROM, and I want each to read in a
different memory file.

I know I can do this statically (at compile time) using parameters as
follows:

parameter FILE_1 = "file_1.dat";
parameter FILE_2 = "file_2.dat";

rom #(FILE_1) rom_1( ... );
rom #(FILE_2) rom_2( ... );

Is there a standard way to do this dynamically (ie, at run time),
without having to re-compile/elaborate? I've tried a few things, but
none has been satifactory...

thanks in advance!
marcas
 
If you have to pass it in to the ROM model as a parameter, I don't
think there's a way to change it at simulation time since parameters
are processed during compile/elaboration.

One solution is to use fixed filenames and link them to your target
files in your run script.

e.g.,
rm -f file_1.dat file_2.dat
ln -s rom_file_1a.dat file_1.dat
ln -s rom_file_2a.dat file_2.dat
vcs|ncverilog|vsim|whatever ...

And the choice of rom_file_1a.dat or rom_file_1b.dat or
whatever_rom_file.dat would be made earlier in your script, probably
based on the test you're running, or command line options, or whatever.

-cb


marcas@ireland.com wrote:
Hi there!

I have a ROM model, and I use $readmemh to read its memory file.

I have multiple instances of this ROM, and I want each to read in a
different memory file.

I know I can do this statically (at compile time) using parameters as
follows:

parameter FILE_1 = "file_1.dat";
parameter FILE_2 = "file_2.dat";

rom #(FILE_1) rom_1( ... );
rom #(FILE_2) rom_2( ... );

Is there a standard way to do this dynamically (ie, at run time),
without having to re-compile/elaborate? I've tried a few things, but
none has been satifactory...

thanks in advance!
marcas
 
You have two different issues here. The first is how to get a model to
get this filename information from somewhere at run-time, i.e. from
somewhere outside the source code of the design. The second is how to
get two different instances of the module to do this differently in
some way so that they don't both get the same answer and read the same
file.

For the first issue, the available mechanisms depend on what version of
the language your tools support. In Verilog-1995, there are few
mechanisms for reading in information from outside. There is the
$test$plusargs system function, which will check the run-time command
line options, but only gives you a "yes or no" answer. That only works
for choosing between several hardwired-in filenames. There is
$readmem, which could be used to read in a filename, but you would have
to take the ASCII codes for the filename characters and put their hex
values into the $readmem file, which is ugly. You could also use the
simulator user interface to deposit a value into a variable
interactively before starting the simulation.

In Verilog-2001, you have the $value$plusargs system function, which
can get a value (such as a string) from the run-time command line
options. You also have $fscanf, which can read a string from a file or
standard input.

The second issue is how to make this behave differently for different
instances. I can see two possible approaches. One is to have
parameter values that you set differently for each instance. Then you
can use these parameter values to control how the filename is obtained.
For example, the parameter value could be the filename of a text file
to read the actual data filename out of, or the plusarg to get the
filename from by using $value$plusargs. The other way to distinguish
the instances is by their full hierarchical path. If you are
depositing a value interactively, you would use these paths to deposit
different values into the filename variable in each instance. The
instance can also obtain this name by using the %m format descriptor.
For example, it can print out the instance path with $display("%m") as
a prompt before reading the filename interactively from standard input.
Or it could print the name into a string with $swrite, and use that
information to figure out where to get its input from.
 
Hi,

What I do is have a case statement that uses a run-time value to pick
up one of several names for input/output files. The module that does
the reading/writing has an input port with the selection and the case
statement that chooses one of multiple files depending on the
selection.

Finally I also have a combination of just reading:

file1.txt for memory1
file2.txt for memory2

while in the operating system, during the test run, I copy the desired
files to file1.txt and file2.txt before they are opened.

RAUL
 
Hi lads and lassies,
thanks for all yer input. When I come full circle on this again, I'll
take it all on board, and try to remember to report back.

Just one thought - I suppose opening a port into the model for the file
name is right out?
marcas
 

Welcome to EDABoard.com

Sponsor

Back
Top