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.

152 lines
4.4 KiB

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