tb.vhd 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4. use ieee.std_logic_textio.all;
  5. library std; -- for Printing
  6. use std.env.all;
  7. use std.textio.all;
  8. library bootloader;
  9. use bootloader.dev_pkg.all;
  10. use work.mem_pkg.all;
  11. entity tb_cpu is
  12. generic (
  13. IMEM : string := "imem.mif";
  14. DMEM : string := "dmem.mif"
  15. );
  16. end entity;
  17. architecture bench of tb_cpu is
  18. constant CLK_PERIOD : time := 10 ns;
  19. signal clk : std_logic := '0';
  20. signal res_n : std_logic := '0';
  21. signal mem_i_in, mem_d_in : mem_in_type;
  22. signal mem_i_out, mem_d_out : mem_out_type;
  23. component core is
  24. port (
  25. clk : in std_logic;
  26. res_n : in std_logic;
  27. -- instruction interface
  28. mem_i_out : out mem_out_type;
  29. mem_i_in : in mem_in_type;
  30. -- data interface
  31. mem_d_out : out mem_out_type;
  32. mem_d_in : in mem_in_type
  33. );
  34. end component;
  35. begin
  36. dut : core
  37. port map (
  38. clk => clk,
  39. res_n => res_n,
  40. mem_i_out => mem_i_out,
  41. mem_i_in => mem_i_in,
  42. mem_d_out => mem_d_out,
  43. mem_d_in => mem_d_in
  44. );
  45. dev_inst : dev
  46. generic map (
  47. IMEM_FILE => IMEM,
  48. DMEM_FILE => DMEM,
  49. IMEM_DELAY => 0,
  50. DMEM_DELAY => 3
  51. )
  52. port map (
  53. clk => clk,
  54. res_n => res_n,
  55. mem_i_out => to_std_logic_vector(mem_i_out),
  56. to_mem_in_type(mem_i_in) => mem_i_in,
  57. mem_d_out => to_std_logic_vector(mem_d_out),
  58. to_mem_in_type(mem_d_in) => mem_d_in
  59. );
  60. generate_clk : process
  61. begin
  62. clk <= '0';
  63. wait for CLK_PERIOD/2;
  64. clk <= '1';
  65. wait for CLK_PERIOD/2;
  66. end process;
  67. generate_reset : process
  68. begin
  69. res_n <= '0';
  70. wait for CLK_PERIOD;
  71. res_n <= '1';
  72. wait;
  73. end process;
  74. end architecture;