Advertisement
Guest User

Untitled

a guest
Nov 7th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 5.53 KB | None | 0 0
  1. LIBRARY IEEE;
  2. USE work.CLOCKS.all;   -- Entity that uses CLOCKS
  3. USE IEEE.std_logic_1164.all;
  4. USE IEEE.std_logic_textio.all;
  5. USE std.textio.all;
  6. USE work.txt_util.all;
  7.  
  8. ENTITY tb_JOSEPH_4_STAGE_ADDER IS
  9. END;
  10.  
  11. ARCHITECTURE TESTBENCH OF tb_JOSEPH_4_STAGE_ADDER IS
  12.     constant P:integer:= 16;
  13.     constant W:integer:= 4;
  14.     constant E:integer:= 8;
  15.  
  16. ---------------------------------------------------------------
  17. -- COMPONENTS
  18. ---------------------------------------------------------------
  19.  
  20. COMPONENT CLOCK
  21.     port(CLK: out std_logic);
  22. END COMPONENT;
  23.  
  24. COMPONENT JOSEPH_4_STAGE_ADDER          -- In/out Ports
  25.  
  26. generic(P: integer:=16;
  27.     W: integer:=4;
  28.     E: integer:=8
  29.       );
  30.  
  31. port(CLK: in std_logic;
  32.        Reset: in std_logic;
  33.        EN: in std_logic;
  34.        OP_A: in std_logic_vector(P-1 downto 0);
  35.        OP_B: in std_logic_vector(P-1 downto 0);
  36.        OP_Q: out std_logic_vector(P-1 downto 0);
  37.        OP_F: out std_logic_vector(W-2 downto 0)
  38.      );
  39. END COMPONENT;
  40.  
  41. ---------------------------------------------------------------
  42. -- Read/Write FILES
  43. ---------------------------------------------------------------
  44.  
  45.  
  46. FILE in_file : TEXT open read_mode is   "JOSEPH_FULL_ADDER_INPUT.txt";   -- Inputs, reset, enr,enl
  47. FILE exo_file : TEXT open read_mode is  "JOSEPH_FULL_ADDER_OUTPUT.txt";   -- Expected output (binary)
  48. FILE out_file : TEXT open  write_mode is  "AMOO_EVENPD_Book_dataout_dacus.txt";
  49. FILE xout_file : TEXT open  write_mode is "AMOO_EVENPD_Book_TestOut_dacus.txt";
  50. FILE hex_out_file : TEXT open  write_mode is "AMOO_EVENPD_Book_hex_out_dacus.txt";
  51. ---------------------------------------------------------------
  52. -- SIGNALS
  53. ---------------------------------------------------------------
  54.  
  55.   SIGNAL CLK: STD_LOGIC;
  56.   SIGNAL OP_A: STD_LOGIC_VECTOR(P-1 downto 0):= (OTHERS => 'X');
  57.   SIGNAL Reset: STD_LOGIC;
  58.   SIGNAL EN: STD_LOGIC;
  59.   SIGNAL OP_B: STD_LOGIC_VECTOR(P-1 downto 0):= (OTHERS => 'X');
  60.   SIGNAL OP_F: STD_LOGIC_VECTOR(W-2 downto 0):= (OTHERS => 'X');
  61.   SIGNAL OP_Q : STD_LOGIC_VECTOR(P-1 downto 0):= (OTHERS => 'X');
  62.   SIGNAL Exp_OP_Q : STD_LOGIC_VECTOR(P-1 downto 0):= (OTHERS => 'X');
  63.   SIGNAL Exp_OP_F : STD_LOGIC_VECTOR(W-2 downto 0):= (OTHERS => 'X');
  64.   SIGNAL Test_OP_Q : STD_LOGIC:='X';
  65.   SIGNAL Test_OP_F : STD_LOGIC:='X';
  66.   SIGNAL LineNumber: integer:=0;
  67.  
  68. ---------------------------------------------------------------
  69. -- BEGIN
  70. ---------------------------------------------------------------
  71.  
  72. BEGIN
  73.  
  74. ---------------------------------------------------------------
  75. -- Instantiate Components
  76. ---------------------------------------------------------------
  77.  
  78.  
  79. U0: CLOCK port map (CLK );
  80. InstJOSEPH_4_STAGE_ADDER : JOSEPH_4_STAGE_ADDER  generic map (P, W, E)
  81. port map (CLK, Reset, EN, OP_A, OP_B, OP_Q, OP_F);
  82.  
  83. ---------------------------------------------------------------
  84. -- PROCESS
  85. ---------------------------------------------------------------
  86. PROCESS
  87.  
  88. variable in_line, exo_line : LINE;
  89. variable comment, xcomment : string(1 to 128);
  90. variable i : integer range 1 to 128;
  91. variable simcomplete : boolean;
  92.  
  93. variable vOP_A   : std_logic_vector(P-1 downto 0):= (OTHERS => 'X');
  94. variable vOP_B   : std_logic_vector(P-1 downto 0):= (OTHERS => 'X');
  95. variable vReset   : std_logic:= '0';
  96. variable vEN: std_logic:= '0';
  97. variable vOP_Q : std_logic_vector(P-1 downto 0):= (OTHERS => 'X');
  98. variable vOP_F: std_logic_vector(W-2 downto 0):= (OTHERS => 'X');
  99. variable vExp_OP_Q : std_logic_vector(P-1 downto 0):= (OTHERS => 'X');
  100. variable vExp_OP_F : std_logic_vector(W-2 downto 0):= (OTHERS => 'X');
  101. variable vTest_OP_Q : std_logic := '0';
  102. variable vTest_OP_F : std_logic := '0';
  103. variable vlinenumber: integer;
  104.  
  105. BEGIN
  106.  
  107. simcomplete := false;
  108.  
  109. while (not simcomplete) LOOP
  110.  
  111.     if (not endfile(in_file) ) then
  112.         readline(in_file, in_line);
  113.     else
  114.         simcomplete := true;
  115.     end if;
  116.  
  117.     if (not endfile(exo_file) ) then
  118.         readline(exo_file, exo_line);
  119.     else
  120.         simcomplete := true;
  121.     end if;
  122.    
  123.     if (in_line(1) = '-') then  --Skip comments
  124.         next;
  125.     elsif (in_line(1) = '.')  then  --exit Loop
  126.       Test_OP_Q <= 'Z';
  127.         simcomplete := true;
  128.     elsif (in_line(1) = '#') then        --Echo comments to out.txt
  129.       i := 1;
  130.       while in_line(i) /= '.' LOOP
  131.         comment(i) := in_line(i);
  132.         i := i + 1;
  133.       end LOOP;
  134.  
  135.     elsif (exo_line(1) = '-') then  --Skip comments
  136.         next;
  137.     elsif (exo_line(1) = '.')  then  --exit Loop
  138.           Test_OP_Q  <= 'Z';
  139.            simcomplete := true;
  140.     elsif (exo_line(1) = '#') then        --Echo comments to out.txt
  141.          i := 1;
  142.        while exo_line(i) /= '.' LOOP
  143.          xcomment(i) := exo_line(i);
  144.          i := i + 1;
  145.        end LOOP;
  146.  
  147.      
  148.     ELSE      --Begin processing
  149.                 read(in_line, vOP_A);
  150.         OP_A  <= vOP_A;
  151.  
  152.         read(in_line, vOP_B);
  153.         OP_B  <= vOP_B;
  154.  
  155.         read(in_line, vReset);
  156.         Reset  <= vReset;
  157.  
  158.         read(in_line, vEN);
  159.         EN  <= vEN;
  160.  
  161.        
  162.        
  163.  
  164.         read(exo_line, vexp_OP_Q );
  165.         read(exo_line, vexp_OP_F);
  166.         read(exo_line, vTest_OP_Q );
  167.         read(exo_line, vTest_OP_F);
  168.        
  169.     vlinenumber :=LineNumber;
  170.    
  171.  
  172.     CYCLE(1,CLK);
  173.    
  174.     Exp_OP_Q      <= vexp_OP_Q;
  175.     Exp_OP_F      <= vexp_OP_F;
  176.      
  177.     if (Exp_OP_Q = OP_Q) then
  178.       Test_OP_Q <= '0';
  179.     else
  180.       Test_OP_Q <= 'X';
  181.     end if;
  182.  
  183.     if (Exp_OP_F = OP_F) then
  184.       Test_OP_F <= '0';
  185.     else
  186.       Test_OP_F <= 'X';
  187.     end if;
  188.  
  189.     END IF;
  190.     LineNumber<= LineNumber+1;
  191.  
  192.     END LOOP;
  193.     WAIT;
  194.    
  195.     END PROCESS;
  196.  
  197. END TESTBENCH;
  198.  
  199.  
  200. CONFIGURATION cfg_tb_JOSEPH_4_STAGE_ADDER OF tb_JOSEPH_4_STAGE_ADDER IS
  201.     FOR TESTBENCH
  202.         FOR InstJOSEPH_4_STAGE_ADDER: JOSEPH_4_STAGE_ADDER
  203.         END FOR;
  204.     END FOR;
  205. END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement