T
Ted
Guest
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
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