我尝试在txt文件上编写VHDL模拟结果。
我可以写一些数据。
但我喜欢按行顺序堆叠这些数据。也就是说,保存的数据之间有新行。
我扩展了写行函数来移动换行符。但事实并非如此。
TEXT_OUT : process (I_CLK,I_RST)
file file_RESULTS : text open write_mode is "output_result.txt";
variable v_OLINE : line;
begin
if (I_RST = '1') then
null;
elsif (rising_edge(I_CLK)) then
if (I_BRAM_ENA = '1') then
hwrite(v_OLINE, O_ADDRB, left, 5);
writeline(file_RESULTS, v_OLINE);
report "Save the output address!";
end if;
end if;
end process;
如果O_ADDRB依次有 0000、0001、0002,随着时间的流逝。
然后output_result.txt有如下数据
0000
0001
0002
如果您需要在新
行中打印,那么除非您必须一次性完成所有操作,而无需关闭文件并再次打开,否则我可能无法帮助您(在这种情况下,您可以按照 user1155120 的评论中所述进行操作。但如果只是为了调试,那么使用这段代码在控制台中打印:
library ieee;
use ieee.std_logic_1164.all;
use std.textio.all;
use ieee.std_logic_textio.all;
procedure writeproc(sig: in std_logic_vector; s : string) is
variable li : line;
variable str : string(1 to sig'length);
file f_in : text; -- open read_mode is "output";
file f_out : text; -- open write_mode is "output";
begin
file_open(f_out, "output", write_mode);
write(li, std_logic_vector(sig));
write(li, lf); writeline(f_out, li);
file_close(f_out);
file_open(f_in, "output", read_mode);
readline(f_in, li);
read(li, str);
file_close(f_in);
report "read " & s & str;
end procedure writeproc;