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.

170 lines
4.7 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. library wishbone;
  9. use wishbone.wishbone_pkg.all;
  10. entity wishbone_vip is
  11. generic (
  12. MODE : string := "CLASSIC";
  13. ASSERTS : boolean := true;
  14. COVERAGE : boolean := true
  15. );
  16. port (
  17. -- syscon signals
  18. WbSysCon : in t_wb_syscon;
  19. -- master signals
  20. WbMaster : in t_wb_master;
  21. -- slave signals
  22. WbSlave : in t_wb_slave
  23. );
  24. end entity wishbone_vip;
  25. architecture verification of wishbone_vip is
  26. function count_ones (data : in std_logic_vector) return natural is
  27. variable v_return : natural := 0;
  28. begin
  29. for i in data'range loop
  30. if (to_x01(data(i)) = '1') then
  31. v_return := v_return + 1;
  32. end if;
  33. end loop;
  34. return v_return;
  35. end function count_ones;
  36. function one_hot (data : in std_logic_vector) return boolean is
  37. begin
  38. return count_ones(data) = 1;
  39. end function one_hot;
  40. function one_hot_0 (data : in std_logic_vector) return boolean is
  41. begin
  42. return count_ones(data) <= 1;
  43. end function one_hot_0;
  44. alias Clk is WbSysCon.Clk;
  45. alias Reset is WbSysCon.Reset;
  46. signal s_wb_slave_resp : std_logic_vector(2 downto 0);
  47. begin
  48. s_wb_slave_resp <= WbSlave.Rty & WbSlave.Err & WbSlave.Ack;
  49. -- Static interface checks
  50. -- Always enabled, regardless of generic ASSERTS setting
  51. MODE_a : assert MODE = "CLASSIC"
  52. report "ERROR: Unsupported mode"
  53. severity failure;
  54. DATA_MS_WIDTH_a : assert WbMaster.Dat'length = 8 or WbMaster.Dat'length = 16 or
  55. WbMaster.Dat'length = 32 or WbMaster.Dat'length = 64
  56. report "ERROR: Invalid Master Data length"
  57. severity failure;
  58. DATA_SM_WIDTH_a : assert WbSlave.Dat'length = 8 or WbSlave.Dat'length = 16 or
  59. WbSlave.Dat'length = 32 or WbSlave.Dat'length = 64
  60. report "ERROR: Invalid Slave Data length"
  61. severity failure;
  62. DATA_EQUAL_WIDTH_a : assert WbMaster.Dat'length = WbSlave.Dat'length
  63. report "ERROR: Master & Slave Data don't have equal length"
  64. severity failure;
  65. default clock is rising_edge(Clk);
  66. ASSERTS_G : if ASSERTS generate
  67. signal s_wb_master : t_wb_master(Adr(WbMaster.Adr'range),
  68. Dat(WbMaster.Dat'range),
  69. Sel(WbMaster.Sel'range),
  70. Tgc(WbMaster.Tgc'range),
  71. Tga(WbMaster.Tga'range),
  72. Tgd(WbMaster.Tgd'range));
  73. signal s_wb_slave : t_wb_slave(Dat(WbSlave.Dat'range),
  74. Tgd(WbSlave.Tgd'range));
  75. begin
  76. -- Create copies of bus signals
  77. process (Clk) is
  78. begin
  79. if rising_edge(Clk) then
  80. s_wb_master <= WbMaster;
  81. s_wb_slave <= WbSlave;
  82. end if;
  83. end process;
  84. -- RULE 3.20
  85. STB_RESET_a : assert always Reset -> not WbMaster.Stb;
  86. CYC_RESET_a : assert always Reset -> not WbMaster.Cyc;
  87. -- RULE 3.25
  88. STB_CYC_a : assert always WbMaster.Stb -> WbMaster.Cyc;
  89. -- RULE 3.45
  90. ACK_ERR_RTY_ONEHOT_a : assert always one_hot_0(s_wb_slave_resp);
  91. -- RULE 3.50
  92. ACK_ERR_RTY_STB_a : assert always or s_wb_slave_resp -> WbMaster.Stb;
  93. DAT_STABLE_STB_a : assert always WbMaster.Stb and s_wb_slave_resp = "000" ->
  94. next (WbMaster.Dat = s_wb_master.Dat);
  95. end generate ASSERTS_G;
  96. COVERAGE_G : if COVERAGE generate
  97. sequence s_single_read (boolean resp) is {
  98. not WbMaster.Cyc;
  99. WbMaster.Cyc and not WbMaster.Stb[*];
  100. {s_wb_slave_resp = "000"[*]; resp} &&
  101. {WbMaster.Cyc and WbMaster.Stb and not WbMaster.We}[+]
  102. };
  103. sequence s_single_write (boolean resp) is {
  104. not WbMaster.Cyc;
  105. WbMaster.Cyc and not WbMaster.Stb[*];
  106. {s_wb_slave_resp = "000"[*]; resp} &&
  107. {WbMaster.Cyc and WbMaster.Stb and WbMaster.We}[+]
  108. };
  109. SINGLE_READ_ACKED_c : cover s_single_read(WbSlave.Ack)
  110. report "Single read with ack finished";
  111. SINGLE_READ_ERROR_c : cover s_single_read(WbSlave.Err)
  112. report "Single read with error finished";
  113. SINGLE_READ_RETRY_c : cover s_single_read(WbSlave.Rty)
  114. report "Single read with retry finished";
  115. SINGLE_WRITE_ACKED_c : cover s_single_write(WbSlave.Ack)
  116. report "Single read with ack finished";
  117. SINGLE_WRITE_ERROR_c : cover s_single_write(WbSlave.Err)
  118. report "Single read with error finished";
  119. SINGLE_WRITE_RETRY_c : cover s_single_write(WbSlave.Rty)
  120. report "Single read with retry finished";
  121. end generate COVERAGE_G;
  122. end architecture verification;