Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.35 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3. use IEEE.STD_LOGIC_ARITH.ALL;
  4. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  5. use IEEE.STD_LOGIC_TEXTIO.ALL;
  6. use STD.TEXTIO.ALL;
  7.  
  8. entity ram20d_tb is
  9. generic (
  10. fileIN : string := "ram_input.txt";
  11. fileOUT : string := "ram_output.txt";
  12. fileCOMPARE : string := "ram_compare.txt");
  13. end ram20d_tb;
  14.  
  15. architecture ram20dTestbench of ram20d_tb is
  16. file infile : TEXT is in fileIN;
  17. file outfile : TEXT is out fileOUT;
  18. file infileCompare : TEXT is in fileIN;
  19. file outfileCompare : TEXT is in fileOUT;
  20.  
  21. file comparefile : TEXT is out fileCOMPARE;
  22.  
  23. component ram20d is
  24. port (
  25. clk : in std_logic;
  26. we : in std_logic;
  27. oe : in std_logic;
  28. addr : in std_logic_vector(5 downto 0);
  29. data : inout std_logic_vector(15 downto 0));
  30. end component;
  31.  
  32. -- ram
  33. constant CLK_PERIOD : time := 20 ns;
  34. constant SIM_TIME : time := 128 * CLK_PERIOD;
  35. signal clk_i, we_i, oe_i : std_logic := '0';
  36. signal addr_i : std_logic_vector(5 downto 0) := "000000";
  37. signal data_i : std_logic_vector(15 downto 0) := "0000000000000000";
  38.  
  39. -- licznik
  40. signal rst_i, ce_i : std_logic := '0';
  41. signal q_i : std_logic_vector( 5 downto 0);
  42.  
  43. signal data_out : std_logic_vector(15 downto 0) := "0000000000000000";
  44. signal compare_e : std_logic := '0';
  45.  
  46. signal check_compare : std_logic := '1';
  47.  
  48. type compareFiles is (idle, compareAndSave, done);
  49. signal compare_state : compareFiles;
  50.  
  51. begin
  52.  
  53. addrGen : entity work.licznik_u
  54. generic map(N => 6, M => 64, T => 1 ns)
  55. port map(q => q_i, rst => rst_i, ce => ce_i, clk => clk_i);
  56.  
  57. UUT : ram20d
  58. PORT MAP(
  59. clk => clk_i,
  60. we => we_i,
  61. oe => oe_i,
  62. addr => addr_i,
  63. data => data_i);
  64.  
  65. clock : process (clk_i)
  66. begin
  67. clk_i <= not clk_i after CLK_PERIOD/2;
  68. end process;
  69.  
  70. select_address : process(clk_i)
  71. begin
  72. if(falling_edge(clk_i)) then
  73. if (we_i = '1' or oe_i = '1') then
  74. addr_i <= q_i;
  75. else
  76. addr_i <= (others => 'Z');
  77. end if;
  78. end if;
  79. end process;
  80.  
  81. write_data : process(clk_i)
  82.  
  83. variable in_line : line;
  84. variable out_line : line;
  85. variable in_data : integer := 0;
  86.  
  87. begin
  88. if (we_i = '1' and oe_i = '0') then
  89. if(falling_edge(clk_i)) then
  90. readline(infile, in_line);
  91. read(in_line, in_data);
  92. data_i <= conv_std_logic_vector(in_data, 16);
  93. end if;
  94. elsif (we_i = '0' and oe_i = '1') then
  95. if(rising_edge(clk_i)) then
  96. data_out <= data_i;
  97. write(out_line, conv_integer(data_i));
  98. write(out_line, HT);
  99. write(out_line, data_i);
  100. writeline(outfile, out_line);
  101. end if;
  102. else
  103. data_i <= (others => 'Z');
  104. end if;
  105. end process;
  106.  
  107. compare : process(clk_i)
  108. variable in_line : line;
  109. variable out_line : line;
  110. variable compare_line :line;
  111. variable in_data : integer := 0;
  112. variable out_data : integer := 0;
  113. begin
  114.  
  115. case compare_state is
  116. when idle =>
  117. if(compare_e = '1') then
  118. compare_state <= compareAndSave;
  119. file_close(infile);
  120. file_close(outfile);
  121. end if;
  122. when compareAndSave =>
  123.  
  124. while not Endfile(infileCompare) loop
  125.  
  126. readline(infileCompare,in_line);
  127. read(in_line, in_data);
  128. readline(outfileCompare,out_line);
  129. read(out_line, out_data);
  130.  
  131. write(compare_line, in_data);
  132. write(compare_line, HT);
  133. write(compare_line, out_data);
  134. writeline(comparefile, compare_line);
  135.  
  136. if(in_data /= out_data) then
  137. check_compare <= '0';
  138. end if;
  139. end loop;
  140.  
  141. compare_state <= done;
  142.  
  143. when done =>
  144. assert check_compare = '1'
  145. report "Comparision error: " & time'image(now)
  146. severity Note ;
  147. assert check_compare = '0'
  148. report "Comparision OK: " & time'image(now)
  149. severity Note ;
  150. assert false
  151. severity Failure;
  152. end case;
  153.  
  154. end process compare;
  155.  
  156. ce_i <= we_i or oe_i;
  157. rst_i <= not we_i and not oe_i;
  158. we_i <= '0', '1' after CLK_PERIOD, '0' after (64+1) * CLK_PERIOD;
  159. oe_i <= '0', '1' after (64+1+1) * CLK_PERIOD, '0' after (128+1+1) * CLK_PERIOD;
  160. compare_e <= '0', '1' after (128+1+1+1) * CLK_PERIOD;
  161.  
  162.  
  163. end ram20dTestbench;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement