1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
| LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE IEEE.numeric_std.ALL;
--
LIBRARY std;
USE std.textio.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--USE ieee.numeric_std.ALL;
ENTITY multiplication_tb IS
generic (N : integer:= 16);
END multiplication_tb;
ARCHITECTURE behavior OF multiplication_tb IS
-- Component Declaration for the Unit Under Test (UUT)
COMPONENT multiplication
PORT(
clk : IN std_logic;
rst : IN std_logic;
en : IN std_logic;
AA : IN std_logic_vector(N downto 0);
BB : IN std_logic_vector(N downto 0);
SS : OUT std_logic_vector(2*N downto 0)
);
END COMPONENT;
--Inputs
signal clk : std_logic := '1';
signal rst : std_logic := '0';
signal en : std_logic := '1';
signal AA : std_logic_vector(N downto 0) := (others => '0');
signal BB : std_logic_vector(N downto 0) := (others => '0');
--Outputs
signal SS : std_logic_vector(2*N downto 0);
-- Clock period definitions
constant clk_period : time := 10 ns; --10 ns;
--CONSTANT PERIOD : time := 12500 ps;
--files decleration
file signal1_vect : text open READ_MODE is "C:\Users\CHIHEB\Documents\MATLAB\data_in1.dat";
file signal2_vect : text open READ_MODE is "C:\Users\CHIHEB\Documents\MATLAB\data_in2.dat";
file signalout_vect : text open WRITE_MODE is "C:\Users\CHIHEB\Documents\MATLAB\data_out.dat";
--conversion functions decleration
--
FUNCTION str_to_stdvec(inp: string) return std_logic_vector is
VARIABLE temp: std_logic_vector(inp'range) := (others => 'X');
BEGIN
for i in inp'range loop
if (inp(i) = '1') then
temp(i) := '1';
elsif (inp(i) = '0') then
temp(i) := '0';
else temp(i) :='X';
end if;
end loop;
return temp;
end function str_to_stdvec;
--
FUNCTION stdvec_to_str(inp: std_logic_vector) return string is
VARIABLE temp: string(inp'left+1 downto 1) := (others => 'U');
BEGIN
for i in inp'reverse_range loop
if (inp(i) = '1') then
temp(i+1) := '1';
elsif (inp(i) = '0') then
temp(i+1) := '0';
else temp(i+1) := 'X';
end if;
end loop;
return temp;
end function stdvec_to_str;
--
BEGIN
-- Instantiate the Unit Under Test (UUT)
uut: multiplication PORT MAP (
clk => clk,
rst => rst,
en => en,
AA => AA,
BB => BB,
SS => SS
);
-- Clock process definitions
clk_process :process
begin
clk <= '0';
wait for clk_period/2;
clk <= '1';
wait for clk_period/2;
end process;
-- ENABLE CLOCK DEF
ENABLE : process
begin
en <= not en;
wait for 10*clk_period/2;
end process ENABLE;
-- RESET CLOCK DEF
RESET : process
begin
rst <= transport '1';
wait for 7000 ps;
rst <= transport '0';
wait for 1000000 ns;
end process RESET;
--
-- -- Stimulus process
-- stim_proc: process
-- begin
-- -- hold reset state for 100 ns.
-- wait for 100 ns;
--
-- wait for clk_period*10;
--
-- -- insert stimulus here
--
-- wait;
-- end process;
--
Read_input : process
variable str1_signal : string (N+1 downto 1);
variable file1_line : line;
variable str2_signal: string (N+1 downto 1);
variable file2_line : line;
begin
wait until rising_edge(Clk);
while not endfile(signal1_vect)and not endfile(signal2_vect)loop
readline(signal1_vect,file1_line);
readline(signal2_vect,file2_line);
read(file1_line,str1_signal);
read(file2_line,str2_signal);
wait for 1 ns;
AA <= str_to_stdvec(str1_signal);
BB <= str_to_stdvec(str2_signal);
wait until falling_edge(Clk);
end loop;
file_close(signal1_vect);
file_close(signal2_vect);
end process;
--
Write_output:process
variable temp_out: std_logic_vector (2*N downto 0);
variable outb: string (2*N+1 downto 1);
variable file_line : line;
begin
wait until falling_edge(Clk);
while not endfile(signal1_vect)and not endfile (signal2_vect)loop
wait for clk_period;
temp_out := SS;
outb := stdvec_to_str(temp_out);
write(file_line,outb);
writeline(signalout_vect,file_line);
end loop;
file_close(signalout_vect);
end process Write_output;
END behavior; |
Partager