Altera_Forum
Honored Contributor
12 years agoVHDL textio hread problem
Hi,
I am trying to create a component which will behave like a ROM in simulation. I would like it to take an input text file. I am trying to use the textio functionality. The component will have an address input and a rd input. It will have a rddata output. When rd is set high I want to read the data from the text file at the line set by address and make rddata the value read. e.g. prog_file.txt : 01 02 a1 a2 If address=X"03" and rising edge on rd. rddata should equal a1. Here is what I have so far:LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.numeric_std.all;
USE ieee.std_logic_textio.all;
LIBRARY STD;
USE STD.textio.all;
LIBRARY work;
ENTITY test_program_file_io IS
GENERIC
(
filename : string = prog_file.txt;
data_width : integer = 8;
addr_width : integer = 15
);
PORT
(
address : IN std_logic_vector(addr_width-1 DOWNTO 0);
rd : IN std_logic;
rddata : OUT std_logic_vector(data_width-1 DOWNTO 0)
);
END ENTITY;
ARCHITECTURE sim OF test_program_file_io IS
FILE file_input : text;
SIGNAL value_read : std_logic_vector(data_width-1 DOWNTO 0);
SIGNAL count : integer := 0;
BEGIN
rddata <= value_read;
read_hex_value_from_file : PROCESS
VARIABLE v_in_line : line;
VARIABLE v_value : std_logic_vector(data_width-1 DOWNTO 0);
BEGIN
WAIT ON rd UNTIL rd = '1';
count <= to_integer(unsigned(address));
file_open(file_input, filename, read_mode);
WHILE((NOT ENDFILE(file_input)) AND (count > 0) LOOP
READLINE(file_input,v_in_line);
count <= count - 1;
END LOOP;
HREAD(v_in_line,v_value);
WAIT ON rd UNTIL rd = '0';
value_read <= v_value;
file_close(file_input);
END PROCESS;
END ARCHITECTURE; I believe that the loop using count is not working because it is in a concurrent statement but I am not sure how to do this without them, I am thinking that to get the functionality I want, if address is 3 then i need to perform 3 readline ops (while checking for endline) and then do the hread and output the value. I cant think of a way of doing a variable number of readline ops without the loop. note hread is only compatible with vhdl-2008 Any help or ideas would be greatly appreciated. Thanks James