rommik

(NEW)testbench.vhd

Dec 19th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 7.62 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.std_logic_1164.all;
  3. use IEEE.numeric_std.ALL;
  4. use STD.textio.all;
  5. use IEEE.std_logic_textio.ALL;
  6.  
  7.  
  8. entity testbench is
  9. end entity;
  10.  
  11. architecture test of testbench is
  12.  
  13.     signal EndOfSim       : boolean := false;
  14.     constant half_clk     : time    := 10 ps;
  15.    
  16.     type frame_size_array is array (0 to 1) of integer;
  17.     constant frame_size    : frame_size_array := (0 => 64800, 1 => 16200);
  18.     constant address_space : frame_size_array := (0 => 64800, 1 => 16200);
  19.     constant input_size    : integer          := 1;
  20.  
  21.     signal i_clk           : std_logic := '0';
  22.     signal i_enb           : std_logic := '0';
  23.     signal i_res           : std_logic := '0';
  24.     signal i_frame_select  : std_logic_vector (0 downto 0);
  25.     signal i_QAM_select    : std_logic_vector (2 downto 0);
  26.     signal i_data          : std_logic_vector (input_size - 1 downto 0);
  27.     signal o_data          : std_logic_vector (input_size - 1 downto 0);
  28.     signal expected        : std_logic_vector (input_size - 1 downto 0);
  29.     signal start_r         : std_logic;
  30.     signal correct         : std_logic;
  31.     file testing_data      : text;
  32.     signal expected_d1     : std_logic_vector (input_size - 1 downto 0);
  33.     signal expected_d2     : std_logic_vector (input_size - 1 downto 0);
  34.  
  35. --    component dvb_s2x_interleaver is
  36. --        Port(
  37. --            i_clk             :  in  std_logic;                              -- тактирование
  38. --            i_res             :  in  std_logic;                              -- сброс
  39. --            i_enb             :  in  std_logic;                              -- разрешение работы
  40. --            i_QAM_select      :  in  std_logic_vector (2 downto 0);          -- выбор модуляции
  41. --            i_frame_select    :  in  std_logic_vector (0 downto 0);          -- выбор фрейма
  42. --            i_data            :  in  std_logic_vector (0 downto 0);          -- входные данные
  43. --            o_data            :  out std_logic_vector (0 downto 0));         -- выходные данные
  44. --    end component;
  45.  
  46.     component clk_dvb_s2x
  47.         Port(
  48.             clk           : in  std_logic;                              
  49.             res           : in  std_logic;                              
  50.             enb           : in  std_logic;                              
  51.             QAM_select    : in  std_logic_vector (2 downto 0);          
  52.             frame_select  : in  std_logic_vector (0 downto 0);          
  53.             data_in       : in  std_logic_vector (0 downto 0);                              
  54.             data_out      : out std_logic_vector (0 downto 0));
  55.     end component;
  56.    
  57. begin
  58.  
  59. --    dut: dvb_s2x_interleaver
  60. --    port map(
  61. --        i_clk          => i_clk,
  62. --        i_res          => i_res,
  63. --        i_enb          => i_enb,
  64. --        i_QAM_select   => i_QAM_select,
  65. --        i_frame_select => i_frame_select,
  66. --        i_data         => i_data,
  67. --        o_data         => o_data);
  68.        
  69.     dut: clk_dvb_s2x
  70.         port map(
  71.             clk          => i_clk,
  72.             enb          => i_enb,
  73.             res          => i_res,
  74.             QAM_select   => i_QAM_select,
  75.             frame_select => i_frame_select,
  76.             data_in      => i_data,
  77.             data_out     => o_data);
  78.        
  79.        
  80. clock: process is
  81.     begin               -- clock generator, toggle clk every half periode
  82.         if EndOfSim then
  83.         wait;
  84.         end if;
  85.         i_clk <= not i_clk;
  86.         wait for half_clk;
  87. end process;
  88.  
  89.     main: process is
  90.         variable read_line          : line;
  91.         variable frame_count        : integer;
  92.         variable M_frame_select     : std_logic_vector (0 downto 0);
  93.         variable int_frame_select   : integer;
  94.         variable M_APSK_SELECT      : std_logic_vector (2 downto 0);
  95.         variable M_INPUT            : std_logic_vector (0 to frame_size(0) - 1);
  96.         variable M_OUTPUT           : std_logic_vector (0 to frame_size(0) - 1);
  97.         variable frame_counter      : integer;
  98.         variable input_counter      : integer;
  99.         variable input              : std_logic_vector (input_size - 1 downto 0);
  100.         variable output             : std_logic_vector (input_size - 1 downto 0);
  101.         variable lower_bound        : integer;
  102.         variable upper_bound        : integer;
  103.     begin
  104.         file_open(testing_data, "Test_input_interleaver.txt", read_mode);
  105.         readline(testing_data, read_line);
  106.         read(read_line, frame_count);
  107.         read(read_line, M_frame_select);
  108.         int_frame_select := to_integer(unsigned(M_frame_select));
  109.         report "frame_count = " & integer'image(frame_count);
  110.         wait until falling_edge(i_clk);
  111.         i_enb          <= '0';
  112.         i_res          <= '1';
  113.         i_frame_select <= M_frame_select;
  114.         wait until rising_edge(i_clk);
  115.         wait until falling_edge(i_clk);
  116.         i_enb         <= '1';
  117.         i_res         <= '0';
  118.         frame_counter := 0;
  119.         -- FIRST LOOP THAT WRITES WORDS
  120.         while frame_counter < frame_count + 1 loop
  121.             if (frame_counter < frame_count) then
  122.                 readline(testing_data, read_line);
  123.                 read(read_line, M_APSK_SELECT);
  124.                 read(read_line, M_INPUT(0 to frame_size(int_frame_select)-1));
  125.                 report "Frame: " & integer'image(frame_counter) & " M_APSK_SELECT = " & integer'image(to_integer(unsigned(M_APSK_SELECT)));
  126.             else end if;
  127.             -- SECOND LOOP THAT WRITES WORDS
  128.             input_counter := 0;
  129.             while input_counter < (address_space(int_frame_select)) loop
  130.                 lower_bound := input_size * input_counter;
  131.                 upper_bound := input_size * (input_counter + 1) - 1;
  132.                 -- WRITE INPUT(DON'T WRITE AT THE END)
  133.                 if(frame_counter < frame_count) then
  134.                     i_QAM_select <= M_APSK_SELECT;
  135.                     i_data       <= M_INPUT(lower_bound to upper_bound);
  136.                 else
  137.                     i_data       <= (others => 'U');
  138.                 end if;
  139.                 wait until rising_edge(i_clk);
  140.                 -- WRITE EXPECTED OUTPUT(DON'T WRITE AT THE BEGINNING)
  141.                 if (frame_counter > 0) then
  142.                     expected <= M_OUTPUT(lower_bound to upper_bound);
  143.                 else end if;
  144.                 wait until falling_edge(i_clk);
  145.                 input_counter := input_counter + 1;
  146.             end loop;
  147.             if (frame_counter < frame_count) then
  148.                 read (read_line, M_OUTPUT(0 to frame_size(int_frame_select)-1));
  149.             else end if;
  150.             start_r       <= '1';
  151.             frame_counter := frame_counter + 1;
  152.         end loop;
  153.         file_close(testing_data);
  154.         start_r  <= '0';
  155.         i_enb    <= '0';
  156.         wait for 10*half_clk;
  157.         EndOfSim <= true;
  158.         report "Simulation finished succcesfully" severity FAILURE;
  159.         wait;
  160.     end process;
  161.  
  162.     testing: process is
  163.     begin  
  164.         wait until falling_edge(i_clk);      
  165.         if(start_r = '1') then
  166.             if(expected_d2 = o_data) then
  167.                 correct <= '1';
  168.             else
  169.                 report "ERROR: incorrect";
  170.                 wait for 4*half_clk;
  171.                 report "ERROR: exiting" severity FAILURE;
  172.                 correct <= '0';
  173.             end if;
  174.         end if;
  175.     end process;
  176.    
  177.     process(i_clk) begin
  178.         if rising_edge(i_clk) then
  179.             expected_d1 <= expected;
  180.             expected_d2 <= expected_d1;
  181.         end if;
  182.     end process;
  183. end architecture;
Add Comment
Please, Sign In to add comment