Variable Input file length

T

Ted

I have a test bench in which the input stimulus file length is unknown.
I would like to read the file in to my test bench and loop through
each element of the stimulus every clock. The only problem is the the
upper limit of the loop is unknown. I created the following to find
the file length (number of elements) and use that length as the upper
limit of a loop used to read the file into an array which is based off
of that length. Here is the code I created (shortened for posting) but
it doesn't work in Model Sim:

..
..
..
signal ind : integer range 1 to 16777216;

--
************************************************************************************
-- Determine length of input file
--
************************************************************************************
filelength : process

variable index : integer := 0;
variable linein : line;
variable test : integer;
file f2 : text open READ_MODE is "adc.txt";

begin

while not (endfile(f2)) loop
readline(f2,linein);
read(linein,test);
index := index + 1;
end loop;

ind <= index;
wait;

end process;
--
************************************************************************************
-- stimuli process
--
************************************************************************************
stim_proc : process

file f2 : text open READ_MODE is "adc.txt";

type arradc is array(0 to ind) of integer;

variable lineout2 : line;
variable adc : arradc;
variable pixel : integer := 0;
variable lower : integer := 0;
variable upper : integer := 3430;
variable linein2 : line;

begin

start_read <= '0';

--
**********************************************************************************
-- read data file
--
**********************************************************************************
i := adc'high;
for i in 0 to adc'high loop
readline(f2,linein2);
read(linein2,adc(i));
end loop;
..
..
..
..
..

I thought it would be pretty straight forward to use the signal "ind"
to set the size of the array type, arradc, and create a variable, adc,
to read the file elements into of type arradc. I keep getting the
following message ...

# ** Fatal: (vsim-3734) Index value 2 is out of range 0 to 1 (null
array).
Makes sense because that is the low limit of the range of the signal
ind.

Basically, what I want to do is determine how long the file is and use
that number to create a type that I can use to create a variable to
read the stimulus into...

Any ideas on how I can do this? Thanks.

Ted
 
P

Paul Uiterlinden

Ted said:
I have a test bench in which the input stimulus file length is
unknown.
I would like to read the file in to my test bench and loop through
each element of the stimulus every clock. The only problem is the
the
upper limit of the loop is unknown. I created the following to find
the file length (number of elements) and use that length as the
upper limit of a loop used to read the file into an array which is
based off of that length.

You cannot do that. The upper and lower limits in an array (type)
declaration must be static. The value of a signal is not static.

If you absolutely must store the contents of the file and have that
accessible in your testbench, you must create a linked list. It
consist of dynamically allocated objects, by using access types and
the NEW operator. See for example:
http://www.emba.uvm.edu/~jswift/uvm_class/notes/access.html

Another way would just to create an array that is large enough to hold
the largest expected file. But that is rightout ugly.

But why reading in the file first and then use the contents? If you
just need a new vector each clock, why not read a line each clock and
use that vector?

Yet another approach: don't use a file at all. Declare a constant
array with your vectors.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top