tb.vhd 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3. use IEEE.std_logic_arith.ALL;
  4. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  5. use STD.textio.all;
  6. use ieee.std_logic_textio.all;
  7. entity tb is
  8. end tb;
  9. architecture Behavioral of tb is
  10. constant busWidth : integer:=32;
  11. component packaging is
  12. generic(
  13. busWidth : integer:=32);
  14. Port ( clk : in STD_LOGIC;
  15. rst : in STD_LOGIC;
  16. inputStream : in STD_LOGIC_VECTOR (busWidth-1 downto 0);
  17. inpRdEn : out std_logic;
  18. inputEmpty : in std_logic;
  19. outData : out STD_LOGIC_VECTOR (busWidth-1 downto 0);
  20. outWrEn : out std_logic;
  21. outputFull : in std_logic;
  22. errorCode : out STD_LOGIC_VECTOR(3 DOWNTO 0);
  23. stateOut : out STD_LOGIC_VECTOR(3 downto 0));
  24. end component;
  25. signal clk : std_logic := '1';
  26. signal rst : std_logic := '0';
  27. file inputFile : text;
  28. file outputTimingsFile : text;
  29. file outputFile : text;
  30. signal s_inData : std_logic_vector(busWidth-1 downto 0);
  31. signal srcAvail: std_logic := '1';
  32. signal inputEmpty : std_logic := '0';
  33. signal rdEn : std_logic;
  34. signal s_outData : std_logic_vector(busWidth-1 downto 0);
  35. signal outputFull : std_logic := '0';
  36. signal wrEn : std_logic;
  37. signal done: std_logic := '0';
  38. signal index : integer := 0;
  39. signal seek : integer := 0;
  40. signal eth : integer range 0 to 7 := 0;
  41. begin
  42. dut : packaging port map (
  43. clk => clk,
  44. rst => rst,
  45. inputStream => s_inData,
  46. inputEmpty => inputEmpty,
  47. inpRdEn => rdEn,
  48. outData => s_outData,
  49. outWrEn => wrEn,
  50. outputFull => outputFull
  51. );
  52. p_read : process
  53. variable v_inLine : line;
  54. variable v_inTime : time;
  55. variable v_space : character;
  56. variable v_inData : std_logic_vector(busWidth-1 downto 0);
  57. begin
  58. file_open(inputFile, "input.txt", read_mode);
  59. while not endfile(inputFile) loop
  60. wait until rising_edge(clk);
  61. if rdEn = '1' then
  62. assert srcAvail = '1'
  63. report "input underflow"
  64. severity warning;
  65. readline(inputFile, v_inLine);
  66. read(v_inLine, v_inTime);
  67. read(v_inLine, v_space);
  68. read(v_inLine, v_inData);
  69. s_inData <= v_inData;
  70. if v_inTime > 10 ns then
  71. srcAvail <= '0';
  72. srcAvail <= '1' after v_inTime;
  73. end if;
  74. end if;
  75. end loop;
  76. wait until rising_edge(clk);
  77. file_close(inputFile);
  78. srcAvail <= '0';
  79. done <= '1' after 100 ns;
  80. wait;
  81. end process;
  82. inputEmpty <= not srcAvail or not rst;
  83. p_write : process
  84. variable v_outLine : line;
  85. variable v_outTime : time;
  86. variable c_space : character := ' ';
  87. begin
  88. file_open(outputFile, "output.txt", write_mode);
  89. while not done = '1' loop
  90. wait until rising_edge(clk);
  91. if wrEn = '1' then
  92. assert outputFull = '0'
  93. report "output overflow"
  94. severity warning;
  95. write(v_outLine, time'image(now));
  96. write(v_outLine, c_space);
  97. write(v_outLine, s_outData);
  98. writeline(outputFile, v_outLine);
  99. end if;
  100. end loop;
  101. file_close(outputFile);
  102. wait;
  103. end process;
  104. p_throttleOut : process
  105. variable v_inLine : line;
  106. variable v_inTime : time;
  107. begin
  108. file_open(outputTimingsFile, "outputTimings.txt", read_mode);
  109. while not endfile(outputTimingsFile) and done = '0' loop
  110. wait until rising_edge(clk);
  111. if wrEn = '1' then
  112. readline(outputTimingsFile, v_inLine);
  113. read(v_inLine, v_inTime);
  114. if v_inTime > 10 ns then
  115. outputFull <= '1';
  116. outputFull <= '0' after v_inTime;
  117. end if;
  118. end if;
  119. end loop;
  120. file_close(outputTimingsFile);
  121. wait;
  122. end process;
  123. clkGen : process begin
  124. wait for 5ns;
  125. clk <= not clk;
  126. end process;
  127. rstGen : process begin
  128. rst <= '0';
  129. wait for 15 ns;
  130. rst <= '1';
  131. wait until rising_edge(done);
  132. wait until rising_edge(clk);
  133. assert false
  134. report "simulation ended"
  135. severity failure;
  136. end process;
  137. end Behavioral;