Library of reusable VHDL components
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.

159 lines
4.7 KiB

  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4. entity WishBoneMasterE is
  5. generic (
  6. Coverage : boolean := false;
  7. AddressWidth : natural := 8;
  8. DataWidth : natural := 8
  9. );
  10. port (
  11. --+ wishbone system if
  12. WbRst_i : in std_logic;
  13. WbClk_i : in std_logic;
  14. --+ wishbone outputs
  15. WbCyc_o : out std_logic;
  16. WbStb_o : out std_logic;
  17. WbWe_o : out std_logic;
  18. WbAdr_o : out std_logic_vector(AddressWidth-1 downto 0);
  19. WbDat_o : out std_logic_vector(DataWidth-1 downto 0);
  20. --+ wishbone inputs
  21. WbDat_i : in std_logic_vector(DataWidth-1 downto 0);
  22. WbAck_i : in std_logic;
  23. WbErr_i : in std_logic;
  24. --+ local register if
  25. LocalWen_i : in std_logic;
  26. LocalRen_i : in std_logic;
  27. LocalAdress_i : in std_logic_vector(AddressWidth-1 downto 0);
  28. LocalData_i : in std_logic_vector(DataWidth-1 downto 0);
  29. LocalData_o : out std_logic_vector(DataWidth-1 downto 0);
  30. LocalAck_o : out std_logic;
  31. LocalError_o : out std_logic
  32. );
  33. end entity WishBoneMasterE;
  34. architecture rtl of WishBoneMasterE is
  35. type t_wb_master_fsm is (IDLE, ADDRESS, DATA);
  36. signal s_wb_master_fsm : t_wb_master_fsm;
  37. signal s_wb_wen : std_logic;
  38. begin
  39. --+ Wishbone master control state machine
  40. WbMasterStatesP : process (WbClk_i) is
  41. begin
  42. if (rising_edge(WbClk_i)) then
  43. if (WbRst_i = '1') then
  44. s_wb_master_fsm <= IDLE;
  45. else
  46. WbReadC : case s_wb_master_fsm is
  47. when IDLE =>
  48. if ((LocalWen_i xor LocalRen_i) = '1') then
  49. s_wb_master_fsm <= ADDRESS;
  50. end if;
  51. when ADDRESS =>
  52. if (WbAck_i = '1' or WbErr_i = '1') then
  53. s_wb_master_fsm <= IDLE;
  54. else
  55. s_wb_master_fsm <= DATA;
  56. end if;
  57. when DATA =>
  58. if (WbErr_i = '1' or WbAck_i = '1') then
  59. s_wb_master_fsm <= IDLE;
  60. end if;
  61. when others =>
  62. s_wb_master_fsm <= IDLE;
  63. end case;
  64. end if;
  65. end if;
  66. end process WbMasterStatesP;
  67. --+ combinatoral local register if outputs
  68. LocalData_o <= WbDat_i when s_wb_master_fsm = DATA else (others => '0');
  69. LocalError_o <= WbErr_i when s_wb_master_fsm /= IDLE else '0';
  70. LocalAck_o <= WbAck_i when (s_wb_master_fsm = ADDRESS or s_wb_master_fsm = DATA) and WbErr_i = '0' else '0';
  71. --+ combinatoral wishbone if outputs
  72. WbStb_o <= '1' when s_wb_master_fsm /= IDLE else '0';
  73. WbCyc_o <= '1' when s_wb_master_fsm /= IDLE else '0';
  74. WbWe_o <= s_wb_wen when s_wb_master_fsm /= IDLE else '0';
  75. --+ registered wishbone if outputs
  76. OutRegsP : process (WbClk_i) is
  77. begin
  78. if(rising_edge(WbClk_i)) then
  79. if(WbRst_i = '1') then
  80. WbAdr_o <= (others => '0');
  81. WbDat_o <= (others => '0');
  82. s_wb_wen <= '0';
  83. else
  84. if (s_wb_master_fsm = IDLE) then
  85. if ((LocalWen_i xor LocalRen_i) = '1') then
  86. WbAdr_o <= LocalAdress_i;
  87. s_wb_wen <= LocalWen_i;
  88. end if;
  89. if (LocalWen_i = '1') then
  90. WbDat_o <= LocalData_i;
  91. end if;
  92. end if;
  93. end if;
  94. end if;
  95. end process OutRegsP;
  96. -- psl default clock is rising_edge(WbClk_i);
  97. -- PSL assert directives
  98. -- psl RESET : assert always
  99. -- WbRst_i ->
  100. -- WbCyc_o = '0' and WbStb_o = '0' and WbWe_o = '0' and
  101. -- to_integer(unsigned(WbAdr_o)) = 0 and to_integer(unsigned(WbDat_o)) = 0 and
  102. -- LocalAck_o = '0' and LocalError_o = '0' and to_integer(unsigned(LocalData_o)) = 0
  103. -- report "WB master: Reset error";
  104. --
  105. -- psl WB_WRITE : assert always
  106. -- ((not(WbCyc_o) and not(WbStb_o) and LocalWen_i and not (LocalRen_i)) ->
  107. -- next (WbCyc_o = '1' and WbStb_o = '1' and WbWe_o = '1')) abort WbRst_i
  108. -- report "WB master: Write error";
  109. --
  110. -- psl WB_READ : assert always
  111. -- ((not(WbCyc_o) and not(WbStb_o) and LocalRen_i and not(LocalWen_i)) ->
  112. -- next (WbCyc_o = '1' and WbStb_o = '1' and WbWe_o = '0')) abort WbRst_i
  113. -- report "WB master: Read error";
  114. CoverageG : if Coverage generate
  115. -- psl COVER_LOCAL_WRITE : cover {s_wb_master_fsm = IDLE and LocalWen_i = '1' and
  116. -- LocalRen_i = '0' and WbRst_i = '0'}
  117. -- report "WB master: Local write";
  118. --
  119. -- psl COVER_LOCAL_READ : cover {s_wb_master_fsm = IDLE and LocalRen_i = '1' and
  120. -- LocalWen_i = '0' and WbRst_i = '0'}
  121. -- report "WB master: Local read";
  122. --
  123. -- psl COVER_LOCAL_WRITE_READ : cover {s_wb_master_fsm = IDLE and LocalWen_i = '1' and
  124. -- LocalRen_i = '1' and WbRst_i = '0'}
  125. -- report "WB master: Local write & read";
  126. end generate CoverageG;
  127. end architecture rtl;