Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.06 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_TEXTIO.ALL;
  5. use ieee.numeric_std.all;
  6. USE STD.TEXTIO.ALL;
  7.  
  8. entity bin2onehot_tb is
  9. end bin2onehot_tb;
  10.  
  11. architecture testbench_arch of bin2onehot_tb is
  12. constant Tpd: time:= 6 ns;
  13. signal addr_internal : std_logic_vector(5 downto 0) := "000000";
  14. signal clk_internal, we_internal, oe_internal : std_logic;
  15. signal data_internal : std_logic_vector(15 downto 0);
  16. signal reducedDataInternal : std_logic_vector(3 downto 0);
  17. signal dlugoscArgumentu : integer := 8;
  18. signal nazwapliku : string(1 to dlugoscArgumentu);
  19. file infile: text; -- plik wymuszen
  20. file outfile: text open WRITE_MODE is "wyniki.txt"; -- plik wynikow
  21.  
  22. --komponent ram20 ---------
  23. component ram20d
  24. port (clk : in std_logic;
  25. we : in std_logic;
  26. oe : in std_logic;
  27. addr: in std_logic_vector(5 downto 0);
  28. data: inout std_logic_vector(15 downto 0));
  29. end component;
  30.  
  31.  
  32. --zamiana STD Logic Vector na Stringa
  33. function doStringa (SLV : std_logic_vector) return string is
  34. variable L : LINE;
  35. begin
  36. hwrite(L,SLV);
  37. return L.all;
  38. end function doStringa;
  39.  
  40. --procedura odczytu-----
  41. procedure odczyt(signal datain : in std_logic_vector(15 downto 0);signal adres : out std_logic_vector(5 downto 0);
  42. signal zegar : out std_logic;signal we : out std_logic;signal oe : out std_logic;
  43. signal dataout : out std_logic_vector(3 downto 0)) is
  44. variable readData : std_logic_vector(3 downto 0) := std_logic_vector(resize(ieee.numeric_std.signed(datain),dataout'length));
  45. begin
  46. we <= '0';
  47. oe <= '1';
  48. wait for 1ns;
  49. zegar <= '1';
  50. wait for 1.1ns;
  51. zegar <= '0';
  52. --dataout <= readData;
  53. --wait for 1ns;
  54. end procedure;
  55.  
  56. --procedura zapisu------
  57. procedure zapis(signal danain : in std_logic_vector(3 downto 0); signal adres : out std_logic_vector(5 downto 0);
  58. signal zegar : out std_logic;signal we : out std_logic;signal oe : out std_logic;
  59. signal danaout : out std_logic_vector(15 downto 0)) is
  60. --variable add : std_logic_vector(5 downto 0);
  61. variable datka : std_logic_vector(15 downto 0) := std_logic_vector(resize(ieee.numeric_std.signed(danain), danaout'length));
  62. begin
  63. danaout <= datka;
  64. we <= '1';
  65. oe <= '0';
  66. zegar <= '0';
  67. wait for 1ns;
  68. zegar <= '1';
  69. wait for 1ns;
  70. zegar <= '0';
  71. --wait for 1ns;
  72.  
  73. end procedure;
  74.  
  75. -- procedury lokalne
  76. procedure slv2_to_file(slv1, slv2: in std_logic_vector; file f: text; header: boolean:=false) is
  77. variable text_out : line;
  78. begin
  79. if header then
  80. report "Rozpoczynam dzialanie z plikiem: " & nazwapliku severity note;
  81. write(text_out,string'("bin") & HT & string'("onehot"));
  82. else
  83. hwrite(text_out,slv1); write(text_out,HT); write(text_out,slv2);
  84. end if;
  85. writeline(f,text_out);
  86.  
  87. --wait for Tpd/2;
  88. if (slv1 /= "U") and (slv1 /= "X") and (slv1 /= "") then
  89. report "Zamiana liczby: " & doStringa(slv1) & " na: " & doStringa(slv2) severity note;
  90. end if;
  91. end procedure;
  92.  
  93. procedure slv1_from_file(signal slv1: out std_logic_vector; file f: text; nbit: positive:=4) is
  94. variable text_in : line;
  95. variable in_data : integer := 0;
  96. begin
  97. readline(f, text_in); -- czytaj linie pliku wejsciowego
  98. read(text_in, in_data); -- pobierz zmienna in_data
  99. slv1 <= conv_std_logic_vector(in_data,nbit);
  100. end procedure;
  101.  
  102. -- deklaracja komponentu badanego ------------------------------
  103. component bin2onehot
  104. port (
  105. bin : in std_logic_vector (3 downto 0);
  106. onehot : out std_logic_vector (9 downto 0)
  107. );
  108. end component;
  109.  
  110. signal bin_internal : std_logic_vector (3 downto 0);
  111. signal onehot_internal : std_logic_vector (9 downto 0);
  112.  
  113. -- architektura testbench'a-------------------------------------
  114. begin
  115. ramik : ram20d
  116. port map(clk => clk_internal,
  117. we => we_internal,
  118. oe => oe_internal,
  119. addr => addr_internal,
  120. data => data_internal);
  121.  
  122. UUT : bin2onehot -- unit under test
  123. port map ( bin => reducedDataInternal,
  124. onehot => onehot_internal);
  125.  
  126. process -- process bez listy wrazliwosci
  127. variable fstatus: file_open_status;
  128.  
  129. begin
  130. file_open(fstatus,infile,nazwapliku,read_mode);
  131. slv2_to_file(bin_internal, onehot_internal, outfile, True); -- header
  132. czytaj: while not Endfile(infile) loop
  133. --data_Internal <= (others => 'Z');
  134. slv1_from_file(bin_internal, infile); -- nowy wektor z pliku
  135. zapis(bin_internal, addr_internal,clk_internal,we_internal,oe_internal,data_internal);
  136. reducedDataInternal <= std_logic_vector(resize(ieee.numeric_std.signed(data_Internal), reducedDataInternal'length));
  137. wait for Tpd;
  138. --odczyt(data_internal, addr_internal,clk_internal,we_internal,oe_internal,reducedDataInternal);
  139. slv2_to_file(reducedDataInternal, onehot_internal, outfile); -- kolejny wynik do pliku
  140. addr_internal <= std_logic_vector(ieee.numeric_std.signed(addr_internal) + 1 );
  141. end loop czytaj;
  142. wait; -- zawies proces
  143. end process;
  144. end testbench_arch;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement