Opening and closing a file in a testbench

N

Nemesis

Hi all,
I'm writing a testbench for a project, I need to read the input data
from
a file. I'd need to repeat the same sequence more than once.
At the moment I use a process like this

read_file : process
file data: TEXT open READ_MODE is "filename";
....
begin
while (count < len1) loop
wait until falling_edge(WR_CLOCK);
SIGNAL <= std_logic_vector(to_signed(0,24));
end loop;
while not endfile(data) loop
wait until falling_edge(WR_CLOCK);
-- read reference file
readline(data, input_line);
read(input_line, int_text);
SIGNAL <= std_logic_vector(to_signed(int_text,24));
end loop;
while (count < len2) loop
wait until falling_edge(WR_CLOCK);
SIGNAL <= std_logic_vector(to_signed(0,24));
end loop;
end process

This process lasts less than the total testbench time, so it restarts 2
or 3 times, but the file is opened only the first time it runs.
I read in past articles that I can:
1) manually open/close the file,
but modelsim does not recognize file_open/file_close commands
2) create a procedure to read the file
but I don't know how to integrate this procedure with my process

Any hints?
 
B

bknpk

בת×ריך ×™×•× ×—×ž×™×©×™, 6 ב×וקטובר 2005 19:34:37 UTC+2, מ×ת Mike Treseler:

Here is a very simple example to read a file:

....
process
file fp : text;

variable line_content : string(1 to 4);
variable line_num : line;
variable j : integer := 0;
variable char : character:='0';
begin
--0001
--0010
file_open(fp,"stim.txt", READ_MODE);
while not endfile(fp) loop
readline (fp, line_num);
READ (line_num, line_content);
for j in 1 to 4 loop
char := line_content(j);
if(char = '0') then
bin_value(4-j) <= '0';
else
bin_value(4-j) <= '1';
end if;
end loop;
wait for 10 ns; --after reading each line wait for 10ns.
end loop;
file_close(fp); --after reading all the lines close the file.
wait for 10 ns;
assert false report "end of test" severity error;
end process;
....
taken from bknpk vhdl
http://bknpk.no-ip.biz/my_web/MiscellaneousHW/vhdl_read_text_file.html
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top