Forum Discussion
Altera_Forum
Honored Contributor
15 years agoVHDL tools support text(and binary) file read/writes.
the principle is quite a simple two stage assignments: to write out to a file ,values are first passed to an object called line then passed to a named file. to read, value is first read from file to line then to vhdl object. In short the line is the middleman between vhdl object and files you can additionall design your read write with some structuring e.g. functions,procedures or components then call them back and some prefer to use intermediary array in order to do read/write once and for all than to do that repeatedly saving processing speed. examples:Here I use intermediary array and procedure struture. In the main code you will then need to call back the procedure: The example may be too much for beginner, but the basic principle is clear
use std.textio.all;
-- write Tx output data to files
constant tx_data_sz : integer := 4096;
type type1 is array (0 to tx_data_sz-1) of signed(5 downto 0);
procedure write_tx_data(signal I: in type1; signal Q: in type1) is
file file1 : text open write_mode is "sim_I_data.txt";
file file2 : text open write_mode is "sim_Q_data.txt";
variable line1 : line;
variable line2 : line;
begin
for j in 0 to tx_data_sz-1 loop
write(line1,to_integer(I(j)));
writeline(file1,line1);
write(line2,to_integer(Q(j)));
writeline(file2,line2);
end loop;
assert false report "finished writing shaped I/Q data" severity note;
file_close(file1);
file_close(file2);
end procedure;
---------------------------- *************** -------------------------
-- read Rx inputs from Matlab files
constant rx_data_sz : integer := 4096;
type type2 is array (0 to rx_data_sz-1) of signed(9 downto 0);
----------------------------------------------------------------------
--procedure read_rx_data(signal I: out type2; signal Q: out type2) is
--
-- file file1 : text open read_mode is c_stim_i_fname;
-- file file2 : text open read_mode is c_stim_q_fname;
-- variable line1 : line;
-- variable input_tmp : integer := 0;
-- variable j : integer := 0;
--
-- begin
--
-- while(not endfile(file1)) loop
-- readline(file1,line1);
-- read(line1,input_tmp);
-- I(j) <= to_signed(input_tmp,10);
-- j := j + 1;
-- end loop;
--
-- assert false report "finished reading I data" severity note;
-- file_close(file1);
--
-- j := 0;
-- while(not endfile(file2)) loop
-- readline(file2,line1);
-- read(line1,input_tmp);
-- Q(j) <= to_signed(input_tmp,10);
-- j := j + 1;
-- end loop;
--
-- assert false report "finished reading Q data" severity note;
-- file_close(file2);
--
--end procedure;