Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.42 KB | None | 0 0
  1. LIBRARY ieee;
  2. USE ieee.std_logic_1164.ALL;
  3. USE ieee.std_logic_unsigned.all;
  4. USE ieee.numeric_std.ALL;
  5. use std.textio.all; --
  6.  
  7.  
  8. ENTITY TB_ds IS
  9. port (
  10. saidat: out std_logic_vector(11 downto 0);
  11. END TB_ds;
  12.  
  13. architecture comportamento of TB_ds is
  14.  
  15. component ds is
  16. port (
  17. entrada: in std_logic_vector(7 downto 0);
  18. clock: in std_logic;
  19. saidaindex: out std_logic_vector(3 downto 0);
  20. saida: out std_logic_vector(11 downto 0)
  21. );
  22. end component;
  23. --funcao
  24. function str_to_stdvec(inp: string) return std_logic_vector is
  25. variable temp: std_logic_vector(inp'range);
  26. begin
  27. for i in inp'range loop
  28. if (inp(i) = '1') then
  29. temp(i) := '1';
  30. elsif (inp(i) = '0') then
  31. temp(i) := '0';
  32. end if;
  33. end loop;
  34. return temp;
  35. end function str_to_stdvec;
  36.  
  37. --funcao
  38. function stdvec_to_str(inp: std_logic_vector) return string is
  39. variable temp: string(inp'left+1 downto 1);
  40. begin
  41. for i in inp'reverse_range loop
  42. if (inp(i) = '1') then
  43. temp(i+1) := '1';
  44. elsif (inp(i) = '0') then
  45. temp(i+1) := '0';
  46. end if;
  47. end loop;
  48. return temp;
  49. end function stdvec_to_str;
  50.  
  51. --entradas e saídas
  52. signal flag: std_logic := '0';
  53. signal flag_end, flag_never: std_logic := '0';
  54. signal flag_end_file: std_logic := '0';
  55. signal clk: std_logic := '0';
  56. signal reset: std_logic := '1';
  57. signal saidaindex: std_logic_vector(3 downto 0);
  58. signal entrada_ref: std_logic_vector(7 downto 0);
  59. --signal entrada_blk: REG_ROWS;
  60. --signal saida: REG_ROWS;
  61.  
  62. signal sig_start_sad_manager: std_logic := '0';
  63. signal sig_start_reference_manager : std_logic := '0';
  64. signal start_fill, start_shifts: std_logic := '0';
  65. signal sig_vector_x: std_logic_vector(4 DOWNTO 0);
  66. signal sig_vector_y: std_logic_vector(4 DOWNTO 0);
  67.  
  68. --col_left: out REG_COLS;
  69. --col_right: out REG_COLS;
  70.  
  71. signal sig_result: std_logic_vector(11 DOWNTO 0); -- resultado do SAD entre o BRB (banco de registradores de bloco)e o BRR (banco de registradores de referencia)
  72.  
  73. file infile, outfile: text;
  74.  
  75. begin
  76. clockgen :PROCESS
  77. BEGIN
  78. clk <= '1', '0' AFTER 20 ns;
  79. WAIT FOR 40 ns;
  80. END PROCESS;
  81.  
  82. resetgen :PROCESS
  83. BEGIN
  84. wait until (clk'event AND clk = '0');
  85. reset <= '1';
  86. wait until (clk'event AND clk = '0');
  87. reset <= '0';
  88. wait until (clk'event AND clk = '0' and flag_never = '1');
  89. END PROCESS;
  90.  
  91. startFillGen :PROCESS
  92. BEGIN
  93. wait until (clk'event AND clk = '0');--0 -- reset
  94. wait until (clk'event AND clk = '0');--0 -- reset
  95. start_fill <= '1';
  96. wait until (clk'event AND clk = '0');--
  97. start_fill <= '0';
  98. wait until (clk'event AND clk = '0' and flag_end = '1');
  99. END PROCESS;
  100.  
  101. startShiftsGen :PROCESS
  102. BEGIN
  103. wait until (start_fill = '1');
  104. wait until (clk'event AND clk = '0');--1
  105. wait until (clk'event AND clk = '0');--2
  106. wait until (clk'event AND clk = '0');--3
  107. wait until (clk'event AND clk = '0');--4
  108. wait until (clk'event AND clk = '0');--5
  109. wait until (clk'event AND clk = '0');--6
  110. wait until (clk'event AND clk = '0');--7
  111. wait until (clk'event AND clk = '0');--8
  112. wait until (clk'event AND clk = '0');--inserido
  113. --wait until (clk'event AND clk = '0');--inserido
  114.  
  115. start_shifts <= '1';
  116. wait until (clk'event AND clk = '0');--2
  117. start_shifts <= '0';
  118. wait until (clk'event AND clk = '0' and flag_end = '1');
  119.  
  120. END PROCESS;
  121.  
  122. start_sad_manager:PROCESS
  123. BEGIN
  124. wait until (start_shifts = '1');
  125. sig_start_sad_manager <= '1';
  126. wait until (clk'event and clk='0');
  127. sig_start_sad_manager <= '0';
  128. wait until (clk'event AND clk = '0' and flag_end = '1');
  129. END PROCESS;
  130.  
  131.  
  132. estimulos_entrada: process
  133. variable i, j, k: integer;
  134. variable linha: line;
  135. variable linhaStr: string(8 downto 1);
  136. variable linhaVec: std_logic_vector(7 downto 0);
  137. begin
  138.  
  139. FILE_OPEN(infile, "entrada.txt", READ_MODE);
  140. wait until (clk'event and clk='0' and reset='0');
  141. while not endfile(infile) loop
  142.  
  143. --lendo os valores do bloco
  144. --i:=0;
  145. --while(i<8) loop
  146. -- j:=0;
  147. -- while (j<8) loop
  148. -- readline(infile, linha);
  149. -- read(linha, linhaStr);
  150. -- entrada_blk(i)(j) <= str_to_stdvec (linhaStr);
  151. -- j := j+1;
  152. -- end loop;
  153. -- i := i+1;
  154. --end loop;
  155.  
  156. --Lendo a primeira posicao da area de pesquisa
  157. i := 0;
  158. while(i<8) loop
  159. j := 0;
  160. while (j<8) loop
  161. readline(infile, linha);
  162. read(linha, linhaStr);
  163. entrada_ref <= str_to_stdvec(linhaStr);
  164. j:= j+1;
  165. end loop;
  166. i:= i+1;
  167. wait until (clk'event and clk = '0');
  168. end loop;
  169.  
  170. wait until (clk'event and clk = '0' and start_shifts = '1');
  171.  
  172. --lendo os dados de entrada para os proximos casamentos (624 casamentos)
  173. --k := 0;
  174. --while (k<624) loop --624
  175. --i:= 0;
  176. --while(i<8) loop
  177. -- readline(infile, linha);
  178. -- read(linha, linhaStr);
  179. -- entrada_ref(i) <= str_to_stdvec (linhaStr);
  180. -- i:= i+1;
  181. --end loop;
  182. --wait until (clk'event and clk='0');
  183. --k := k+1;
  184. --end loop;
  185.  
  186. flag <= '1';
  187. wait until (clk'event and clk='0');
  188. flag <= '0';
  189.  
  190. end loop;
  191. file_close(infile);
  192. flag_end_file <= '1';
  193. wait until (flag_never = '1');
  194. end process;
  195.  
  196. estimulos_saida: process
  197. variable i,j: integer;
  198. variable outData: string(12 downto 1);
  199. variable linha: line;
  200.  
  201. begin
  202. FILE_OPEN(outfile,"saida.txt", WRITE_MODE);
  203. i:= 0;
  204.  
  205. while (flag_end_file /= '1') loop
  206.  
  207. wait until (sig_start_sad_manager = '1');
  208. wait until (clk'event and clk='0'); --1
  209. wait until (clk'event and clk='0'); --2
  210. wait until (clk'event and clk='0'); --3
  211. wait until (clk'event and clk='0'); --4
  212. wait until (clk'event and clk='0'); --5
  213. wait until (clk'event and clk='0'); --6
  214. wait until (clk'event and clk='0'); --7
  215. wait until (clk'event and clk='0'); --8
  216.  
  217. while (flag /= '1') loop
  218. outData := stdvec_to_str(sig_result);
  219. write(linha,outData);
  220. writeline(outfile,linha);
  221. wait until (clk'event and clk='0');
  222. end loop;
  223.  
  224. i := 0;
  225. while (i < 7) loop
  226. outData := stdvec_to_str(sig_result);
  227. write(linha,outData);
  228. writeline(outfile,linha);
  229. i := i + 1;
  230. wait until (clk'event and clk='0');
  231. end loop;
  232.  
  233. flag_end <= '1';
  234. wait until (clk'event and clk='0');
  235. flag_end <= '0';
  236.  
  237. end loop;
  238.  
  239. file_close(outfile);
  240. end process;
  241. saidat<= sig_result;
  242. diamond: ds
  243. port map (entrada_ref,clk,saidaindex,sig_result);
  244. end comportamento;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement