Advertisement
Guest User

Untitled

a guest
Sep 10th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 5.09 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_FAMAKIN_XOR_CASCADES IS
  9. END;
  10.  
  11. ARCHITECTURE TESTBENCH OF TB_FAMAKIN_XOR_CASCADES IS
  12.  
  13.  
  14. ---------------------------------------------------------------
  15. -- COMPONENTS
  16. ---------------------------------------------------------------
  17.  
  18. COMPONENT famakin_xor_cascades          -- In/out Ports
  19.     PORT(   --Clk: IN STD_LOGIC;
  20.         OP_A: IN STD_LOGIC_VECTOR(7 DOWNTO 0);
  21.         OP_Q: OUT STD_LOGIC);
  22. END COMPONENT;
  23.  
  24. COMPONENT CLOCK
  25.     port(CLK: out std_logic);
  26. END COMPONENT;
  27.  
  28. ---------------------------------------------------------------
  29. -- Read/Write FILES
  30. ---------------------------------------------------------------
  31.  
  32.  
  33. FILE in_file : TEXT open read_mode is   "FAMAKIN_XOR_INPUT.txt";   -- Inputs, reset, enr,enl
  34. FILE exo_file : TEXT open read_mode is  "FAMAKIN_XOR_EXP_CASCADE_OUTPUT.txt";   -- Expected output (binary)
  35. FILE out_file : TEXT open  write_mode is  "FAMAKIN_ODDPD_Book_dataout.txt";
  36. FILE xout_file : TEXT open  write_mode is "FAMAKIN_ODDPD_Book_TestOut.txt";
  37. FILE hex_out_file : TEXT open  write_mode is "FAMAKIN_ODDPD_Book_hex_out.txt";
  38.  
  39. ---------------------------------------------------------------
  40. -- SIGNALS
  41. ---------------------------------------------------------------
  42.  
  43.   SIGNAL OP_A: STD_LOGIC_VECTOR(7 downto 0):= "XXXXXXXX";
  44.   SIGNAL CLK: STD_LOGIC;   
  45.   SIGNAL OP_Q : STD_LOGIC:= 'X';
  46.   SIGNAL Exp_Op_Q : STD_LOGIC:= 'X';
  47.   SIGNAL Test_Out_Q : STD_LOGIC:= 'X';
  48.   SIGNAL LineNumber: integer:=0;
  49.  
  50. ---------------------------------------------------------------
  51. -- BEGIN
  52. ---------------------------------------------------------------
  53.  
  54. BEGIN
  55.  
  56. ---------------------------------------------------------------
  57. -- Instantiate Components
  58. ---------------------------------------------------------------
  59.  
  60.  
  61. U0: CLOCK port map (CLK );
  62. Instfamakin_xor_cascades: famakin_xor_cascades port map (OP_A, OP_Q);
  63.  
  64. ---------------------------------------------------------------
  65. -- PROCESS
  66. ---------------------------------------------------------------
  67. PROCESS
  68.  
  69. variable in_line, exo_line, out_line, xout_line : LINE;
  70. variable comment, xcomment : string(1 to 128);
  71. variable i : integer range 1 to 128;
  72. variable simcomplete : boolean;
  73.  
  74. variable vOp_A   : std_logic_vector(7 downto 0):= (OTHERS => 'X');
  75. variable vOp_Q : std_logic:= '0';
  76. variable vExp_Op_Q : std_logic:= '0';
  77. variable vTest_Out_Q : std_logic := '0';
  78. variable vlinenumber: integer;
  79.  
  80. BEGIN
  81.  
  82. simcomplete := false;
  83.  
  84. while (not simcomplete) LOOP
  85.  
  86.     if (not endfile(in_file) ) then
  87.         readline(in_file, in_line);
  88.     else
  89.         simcomplete := true;
  90.     end if;
  91.  
  92.     if (not endfile(exo_file) ) then
  93.         readline(exo_file, exo_line);
  94.     else
  95.         simcomplete := true;
  96.     end if;
  97.    
  98.     if (in_line(1) = '-') then  --Skip comments
  99.         next;
  100.     elsif (in_line(1) = '.')  then  --exit Loop
  101.       Test_Out_Q <= 'Z';
  102.         simcomplete := true;
  103.     elsif (in_line(1) = '#') then        --Echo comments to out.txt
  104.       i := 1;
  105.       while in_line(i) /= '.' LOOP
  106.         comment(i) := in_line(i);
  107.         i := i + 1;
  108.       end LOOP;
  109.  
  110.     elsif (exo_line(1) = '-') then  --Skip comments
  111.         next;
  112.     elsif (exo_line(1) = '.')  then  --exit Loop
  113.           Test_Out_Q  <= 'Z';
  114.            simcomplete := true;
  115.     elsif (exo_line(1) = '#') then        --Echo comments to out.txt
  116.          i := 1;
  117.        while exo_line(i) /= '.' LOOP
  118.          xcomment(i) := exo_line(i);
  119.          i := i + 1;
  120.        end LOOP;
  121.  
  122.    
  123.       write(out_line, comment);
  124.       writeline(out_file, out_line);
  125.      
  126.       write(xout_line, xcomment);
  127.       writeline(xout_file, xout_line);
  128.  
  129.      
  130.     ELSE      --Begin processing
  131.  
  132.  
  133.         read(in_line, vOp_A );
  134.         OP_A  <= vOp_A;
  135.  
  136.         read(exo_line, vexp_Op_Q );
  137.         read(exo_line, vTest_Out_Q );
  138.        
  139.     vlinenumber :=LineNumber;
  140.    
  141.     write(out_line, vlinenumber);
  142.     write(out_line, STRING'("."));
  143.     write(out_line, STRING'("    "));
  144.  
  145.    
  146.  
  147.     CYCLE(1,CLK);
  148.    
  149.     Exp_Op_Q      <= vexp_Op_Q;
  150.    
  151.      
  152.     if (Exp_Op_Q = OP_Q) then
  153.       Test_Out_Q <= '0';
  154.     else
  155.       Test_Out_Q <= 'X';
  156.     end if;
  157.  
  158.         vOp_Q   := OP_Q;
  159.         vTest_Out_Q:= Test_Out_Q;
  160.                
  161.         write(out_line, vOp_Q, left, 32);
  162.         write(out_line, STRING'("       "));                           --ht is ascii for horizontal tab
  163.         write(out_line,vTest_Out_Q, left, 5);                           --ht is ascii for horizontal tab
  164.         write(out_line, STRING'("       "));                           --ht is ascii for horizontal tab
  165.         write(out_line, vexp_Op_Q, left, 32);
  166.         write(out_line, STRING'("       "));                           --ht is ascii for horizontal tab
  167.         writeline(out_file, out_line);
  168.         print(xout_file,    str(LineNumber)& "." & "    " &    str(OP_Q) & "          " &   str(Exp_Op_Q)  & "          " & str(Test_Out_Q) );
  169.    
  170.     END IF;
  171.     LineNumber<= LineNumber+1;
  172.  
  173.     END LOOP;
  174.     WAIT;
  175.    
  176.     END PROCESS;
  177.  
  178. END TESTBENCH;
  179.  
  180.  
  181.  
  182. CONFIGURATION cfg_TB_FAMAKIN_XOR_CASCADES OF TB_FAMAKIN_XOR_CASCADES IS
  183.     FOR TESTBENCH
  184.         FOR Instfamakin_xor_cascades: famakin_xor_cascades
  185.             use entity work.famakin_xor_cascades(tree_arch);
  186.         END FOR;
  187.     END FOR;
  188. END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement