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.

110 lines
3.2 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_CLOCK_PERIOD : time := 2 ns;
  15. constant C_WB_ADDR_WIDTH : positive := 32;
  16. constant C_WB_DATA_WIDTH : positive := 32;
  17. constant C_WB_SEL_WIDTH : positive := 4;
  18. constant C_WB_TGA_WIDTH : positive := 4;
  19. constant C_WB_TGC_WIDTH : positive := 4;
  20. constant C_WB_TGD_WIDTH : positive := 4;
  21. signal s_wb_syscon : t_wb_syscon := ('1', '1');
  22. signal s_wb_master : t_wb_master(Adr(C_WB_ADDR_WIDTH-1 downto 0),
  23. Dat(C_WB_DATA_WIDTH-1 downto 0),
  24. Sel(C_WB_SEL_WIDTH-1 downto 0),
  25. Tgc(C_WB_TGC_WIDTH-1 downto 0),
  26. Tga(C_WB_TGA_WIDTH-1 downto 0),
  27. Tgd(C_WB_TGD_WIDTH-1 downto 0));
  28. signal s_wb_slave : t_wb_slave(Dat(C_WB_DATA_WIDTH-1 downto 0),
  29. Tgd(C_WB_TGD_WIDTH-1 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 C_CLOCK_PERIOD / 2;
  34. s_reset <= '0' after 4 ns;
  35. wb_master_p : process is
  36. subtype t_wb_array is t_slv_array(0 to 7)(open);
  37. variable v_wb_adr : t_wb_array(open)(C_WB_ADDR_WIDTH-1 downto 0);
  38. variable v_wb_wdata : t_wb_array(open)(C_WB_DATA_WIDTH-1 downto 0);
  39. variable v_wb_rdata : t_wb_array(open)(C_WB_DATA_WIDTH-1 downto 0);
  40. begin
  41. s_wb_master.Cyc <= '0';
  42. s_wb_master.Stb <= '0';
  43. wait until s_reset = '0';
  44. -- single read cycles
  45. for wait_cycles in 0 to 3 loop
  46. single_cycle(s_wb_syscon, s_wb_master, s_wb_slave, '0', v_wb_adr(0), v_wb_wdata(0), v_wb_rdata(0));
  47. end loop;
  48. -- single write cycles
  49. for wait_cycles in 0 to 3 loop
  50. single_cycle(s_wb_syscon, s_wb_master, s_wb_slave, '1', v_wb_adr(0), v_wb_wdata(0), v_wb_rdata(0));
  51. end loop;
  52. -- block cycles
  53. block_cycle(s_wb_syscon, s_wb_master, s_wb_slave, '0', v_wb_adr, v_wb_wdata, v_wb_rdata);
  54. block_cycle(s_wb_syscon, s_wb_master, s_wb_slave, '1', v_wb_adr, v_wb_wdata, v_wb_rdata);
  55. wait for 10 ns;
  56. stop(0);
  57. end process wb_master_p;
  58. wb_slave_p : process is
  59. begin
  60. s_wb_slave.Rty <= '0';
  61. s_wb_slave.Err <= '0';
  62. s_wb_slave.Ack <= '0';
  63. wait until s_reset = '0';
  64. loop
  65. for wait_cycles in 0 to 3 loop
  66. wait until rising_edge(s_clk) and (s_wb_master.Cyc and s_wb_master.Stb) = '1';
  67. if wait_cycles /= 0 then
  68. wait for C_CLOCK_PERIOD * wait_cycles - 1 ps;
  69. wait until rising_edge(s_clk);
  70. end if;
  71. s_wb_slave.Ack <= '1';
  72. wait until rising_edge(s_clk);
  73. s_wb_slave.Ack <= '0';
  74. end loop;
  75. end loop;
  76. wait;
  77. end process wb_slave_p;
  78. i_wishbone_vip : entity wishbone.wishbone_vip
  79. generic map (
  80. MODE => "CLASSIC"
  81. )
  82. port map (
  83. WbSysCon => s_wb_syscon,
  84. WbMaster => s_wb_master,
  85. WbSlave => s_wb_slave
  86. );
  87. end testbench;