FPGA Central - World's 1st FPGA / CPLD Portal

FPGA Central

World's 1st FPGA Portal

 

Go Back   FPGA Groups > NewsGroup > Verilog

Verilog comp.lang.verilog newsgroup / usenet

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-09-2005, 09:13 AM
Guest
 
Posts: n/a
Default Reading files in multiple instances of a ROM model

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

Reply With Quote
  #2 (permalink)  
Old 06-09-2005, 02:26 PM
Kim Enkovaara
Guest
 
Posts: n/a
Default Re: Reading files in multiple instances of a ROM model

[email protected] wrote:

> 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...


I have not figured out standard way to do this. But in some similators
this is possible to do.

If you are using Modelsim this is easy. Just put the parameter inside
the ROM model. And then from the vsim commandline you can use -G parameter
i.e. '-G/path/to/my/instance/FILENAME="file_1.dat"'

One way is to assign each ROM a unique name in the compiled code, and then play
with symbolic links in the filesystem (assuming that you are using unix).

--Kim
Reply With Quote
  #3 (permalink)  
Old 06-09-2005, 03:21 PM
Chris Briggs
Guest
 
Posts: n/a
Default Re: Reading files in multiple instances of a ROM model

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


[email protected] 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


Reply With Quote
  #4 (permalink)  
Old 06-09-2005, 10:14 PM
Guest
 
Posts: n/a
Default Re: Reading files in multiple instances of a ROM model

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.

Reply With Quote
  #5 (permalink)  
Old 06-10-2005, 04:00 PM
raul
Guest
 
Posts: n/a
Default Re: Reading files in multiple instances of a ROM model

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

Reply With Quote
  #6 (permalink)  
Old 06-13-2005, 08:04 AM
marcas
Guest
 
Posts: n/a
Default Re: Reading files in multiple instances of a ROM model

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

Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simvision doesn't allow multiple instances? That's really annoying. Fat Cat Verilog 0 12-20-2004 08:40 AM
spectre model files for use in verilog ams Vineet Verilog 0 02-27-2004 04:36 PM
Multiple Mux instances by parameter. Roy Verilog 2 10-21-2003 06:30 PM
multiple task 'instances' Steven Sharp Verilog 2 07-24-2003 01:12 AM
multiple task 'instances' Eric Peterson Verilog 0 07-21-2003 05:48 PM


All times are GMT +1. The time now is 06:22 PM.


Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
Copyright 2008 @ FPGA Central. All rights reserved