VHDL-testbench之txt按行读
对txt进行按行读取,以";"结束
--//使用的Library库文件
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
--//TXT相关的Library库
use IEEE.STD_LOGIC_TEXTIO.all;
use STD.TEXTIO.ALL;
--//实体
entity test is
-- Port ( );
end test;
--//构造体
architecture Behavioral of test is
--//定义UDP_TEST元件及其端口
COMPONENT UDP_TEST
PORT(
DATA_IN :IN STD_LOGIC_VECTOR(7 DOWNTO 0);
CE :IN STD_LOGIC;
clk :IN STD_LOGIC
);
END COMPONENT;
--//定义常量(时间)
CONSTANT clk_period : time := 5ns;
--//定义信号(与UDP_TEST元件对应)
signal clk :STD_LOGIC:='0';
signal DATA_IN :STD_LOGIC_VECTOR(7 DOWNTO 0);
signal CE :STD_LOGIC;
begin
--//时钟信号,频率为(1/clk_period)
clk <= not clk after(clk_period/2);
--//打开第一个txt的进程file_stdlogic1
file_stdlogic1:process
variable vline:line;
variable v:std_logic_vector(7 downto 0);
file invect:text is "C:\Users\Administrator\Desktop\data_in.txt";
begin
wait until rising_edge(clk);
if clk'event and clk='1' then
if not(endfile(invect)) then
readline(invect,vline);
read(vline,v);
data_in <= v;
end if;
end if;
end process file_stdlogic1;
--//打开第二个txt的进程file_stdlogic2
file_stdlogic2:process
variable vline:line;
variable v:std_logic;
file invect:text is "C:\Users\Administrator\Desktop\ce.txt";
begin
wait until rising_edge(clk);
if clk'event and clk='1' then
if not(endfile(invect)) then
readline(invect,vline);
read(vline,v);
ce <= v;
end if;
end if;
end process file_stdlogic2;
--//端口映射
u1:UDP_TEST port map(
clk =>clk,
data_in => data_in,
ce => ce
);
end Behavioral;