在VHDL testbench中读取文本文件

时间:2016-06-16 15:32:04

标签: vhdl

我有一个文件source.txt,它看起来像这样:

00660066006700670067006800680069006B006D006E
00660066006700670067006800680069006B006D006E
00660066006700670067006800680069006B006D006E
00660066006700670067006800680069006B006D006E
00660066006700670067006800680069006B006D006E
0065006500660067006700690069006A006B006C006E
00650065006600670067006700680069006A006C006D
00650065006600670067006600660068006A006B006D
006500650066006700670065006600670069006B006D
00650065006600670067006600670068006A006C006D
0065006500660067006700690069006A006B006C006E
*

在每一行之后都有隐藏的换行符'\ n'。 星号'*'是我可见的文件结尾字符。

如何在VHDL中编写执行以下操作的测试平台:

  • 读取文件
  • 在向量中存储一行
  • 将该矢量写入新的target.txt

1 个答案:

答案 0 :(得分:1)

使用VHDL-2008,并显示std_logic_vector正在进行中,代码可以是:

library ieee;
use ieee.std_logic_1164.all;
use std.textio.all;

entity tb is
end entity;

architecture syn of tb is
begin
  process is
    variable line_v : line;
    file read_file : text;
    file write_file : text;
    variable slv_v : std_logic_vector(44 * 4 - 1 downto 0);
  begin
    file_open(read_file, "source.txt", read_mode);
    file_open(write_file, "target.txt", write_mode);
    while not endfile(read_file) loop
      readline(read_file, line_v);
      hread(line_v, slv_v);
      report "slv_v: " & to_hstring(slv_v);
      hwrite(line_v, slv_v);
      writeline(write_file, line_v);
    end loop;
    file_close(read_file);
    file_close(write_file);
    wait;
  end process;
end architecture;