You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
2.8 KiB

  1. -- Simple wishbone verification IP
  2. -- For use with GHDL only
  3. -- Suitable for simulation & formal verification
  4. -- Copyright 2021 by Torsten Meissner (programming@goodcleanfun.de)
  5. library ieee;
  6. use ieee.std_logic_1164.all;
  7. use ieee.numeric_std.all;
  8. use std.env.all;
  9. library wishbone;
  10. use wishbone.wishbone_pkg.all;
  11. entity wishbone_tb is
  12. end entity wishbone_tb;
  13. architecture testbench of wishbone_tb is
  14. constant C_WB_ADDR_WIDTH : positive := 32;
  15. constant C_WB_DATA_WIDTH : positive := 32;
  16. constant C_WB_SEL_WIDTH : positive := 4;
  17. constant C_WB_TGA_WIDTH : positive := 4;
  18. constant C_WB_TGC_WIDTH : positive := 4;
  19. constant C_WB_TGD_WIDTH : positive := 4;
  20. signal s_wb_syscon : t_wb_syscon := ('1', '1');
  21. signal s_wb_master : t_wb_master(Adr(C_WB_ADDR_WIDTH-1 downto 0),
  22. Dat(C_WB_DATA_WIDTH-1 downto 0),
  23. Sel(C_WB_SEL_WIDTH-1 downto 0),
  24. Tgc(C_WB_TGC_WIDTH-1 downto 0),
  25. Tga(C_WB_TGA_WIDTH-1 downto 0),
  26. Tgd(C_WB_TGD_WIDTH-1 downto 0));
  27. signal s_wb_slave : t_wb_slave(Dat(C_WB_DATA_WIDTH-1 downto 0),
  28. Tgd(C_WB_TGD_WIDTH-1 downto 0));
  29. signal s_wb_slave_resp : std_logic_vector(2 downto 0);
  30. alias s_clk is s_wb_syscon.Clk;
  31. alias s_reset is s_wb_syscon.Reset;
  32. begin
  33. s_clk <= not s_clk after 1 ns;
  34. s_reset <= '0' after 4 ns;
  35. s_wb_slave_resp <= s_wb_slave.Rty & s_wb_slave.Err & s_wb_slave.Ack;
  36. wb_master_p : process is
  37. begin
  38. s_wb_master.Cyc <= '0';
  39. s_wb_master.Stb <= '0';
  40. wait until s_reset = '0';
  41. -- simple reads
  42. for i in 0 to 2 loop
  43. wait until rising_edge(s_clk);
  44. s_wb_master.Cyc <= '1';
  45. s_wb_master.Stb <= '1';
  46. s_wb_master.We <= '0';
  47. wait until s_wb_slave_resp(i) = '1' and rising_edge(s_clk);
  48. report "Master: end simple read cycle";
  49. s_wb_master.Cyc <= '0';
  50. s_wb_master.Stb <= '0';
  51. end loop;
  52. wait for 10 ns;
  53. stop(0);
  54. end process wb_master_p;
  55. wb_slave_p : process is
  56. variable v_resp : std_logic_vector(2 downto 0) := "000";
  57. begin
  58. (s_wb_slave.Rty, s_wb_slave.Err, s_wb_slave.Ack) <= v_resp;
  59. wait until s_reset = '0';
  60. -- simple read
  61. for i in 0 to 2 loop
  62. wait until (s_wb_master.Cyc and s_wb_master.Stb) = '1' and rising_edge(s_clk);
  63. v_resp(i) := '1';
  64. (s_wb_slave.Rty, s_wb_slave.Err, s_wb_slave.Ack) <= v_resp;
  65. wait until not s_wb_master.Stb;
  66. v_resp(i) := '0';
  67. (s_wb_slave.Rty, s_wb_slave.Err, s_wb_slave.Ack) <= v_resp;
  68. end loop;
  69. wait;
  70. end process wb_slave_p;
  71. i_wishbone_vip : entity wishbone.wishbone_vip
  72. generic map (
  73. MODE => "CLASSIC"
  74. )
  75. port map (
  76. WbSysCon => s_wb_syscon,
  77. WbMaster => s_wb_master,
  78. WbSlave => s_wb_slave
  79. );
  80. end testbench;