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.

119 lines
3.2 KiB

  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. entity WishBoneMasterE is
  4. generic (
  5. G_ADR_WIDTH : positive := 8; --* address bus width
  6. G_DATA_WIDTH : positive := 8 --* data bus width
  7. );
  8. port (
  9. --+ wishbone system if
  10. WbRst_i : in std_logic;
  11. WbClk_i : in std_logic;
  12. --+ wishbone outputs
  13. WbCyc_o : out std_logic;
  14. WbStb_o : out std_logic;
  15. WbWe_o : out std_logic;
  16. WbAdr_o : out std_logic_vector(G_ADR_WIDTH-1 downto 0);
  17. WbDat_o : out std_logic_vector(G_DATA_WIDTH-1 downto 0);
  18. --+ wishbone inputs
  19. WbDat_i : in std_logic_vector(G_DATA_WIDTH-1 downto 0);
  20. WbAck_i : in std_logic;
  21. WbErr_i : in std_logic;
  22. --+ local register if
  23. LocalWen_i : in std_logic;
  24. LocalRen_i : in std_logic;
  25. LocalAdress_i : in std_logic_vector(G_ADR_WIDTH-1 downto 0);
  26. LocalData_i : in std_logic_vector(G_DATA_WIDTH-1 downto 0);
  27. LocalData_o : out std_logic_vector(G_DATA_WIDTH-1 downto 0);
  28. LocalAck_o : out std_logic;
  29. LocalError_o : out std_logic
  30. );
  31. end entity WishBoneMasterE;
  32. architecture rtl of WishBoneMasterE is
  33. type t_wb_master_fsm is (IDLE, ADDRESS, DATA);
  34. signal s_wb_master_fsm : t_wb_master_fsm;
  35. signal s_wb_wen : std_logic;
  36. begin
  37. --+ Wishbone master control state machine
  38. WbMasterStatesP : process (WbClk_i) is
  39. begin
  40. if (rising_edge(WbClk_i)) then
  41. if (WbRst_i = '1') then
  42. s_wb_master_fsm <= IDLE;
  43. else
  44. WbReadC : case s_wb_master_fsm is
  45. when IDLE =>
  46. if (LocalWen_i = '1' or LocalRen_i = '1') then
  47. s_wb_master_fsm <= ADDRESS;
  48. end if;
  49. when ADDRESS =>
  50. if (WbAck_i = '1' or WbErr_i = '1') then
  51. s_wb_master_fsm <= IDLE;
  52. else
  53. s_wb_master_fsm <= DATA;
  54. end if;
  55. when DATA =>
  56. if (WbErr_i = '1' or WbAck_i = '1') then
  57. s_wb_master_fsm <= IDLE;
  58. end if;
  59. when others =>
  60. s_wb_master_fsm <= IDLE;
  61. end case;
  62. end if;
  63. end if;
  64. end process WbMasterStatesP;
  65. --+ combinatoral local register if outputs
  66. LocalData_o <= WbDat_i when s_wb_master_fsm = DATA else (others => '0');
  67. LocalError_o <= WbErr_i when s_wb_master_fsm /= IDLE else '0';
  68. LocalAck_o <= WbAck_i when (s_wb_master_fsm = ADDRESS or s_wb_master_fsm = DATA) and WbErr_i = '0' else '0';
  69. --+ combinatoral wishbone if outputs
  70. WbStb_o <= '1' when s_wb_master_fsm /= IDLE else '0';
  71. WbCyc_o <= '1' when s_wb_master_fsm /= IDLE else '0';
  72. WbWe_o <= s_wb_wen when s_wb_master_fsm /= IDLE else '0';
  73. --+ registered wishbone if outputs
  74. OutRegsP : process (WbClk_i) is
  75. begin
  76. if(rising_edge(WbClk_i)) then
  77. if(WbRst_i = '1') then
  78. WbAdr_o <= (others => '0');
  79. WbDat_o <= (others => '0');
  80. s_wb_wen <= '0';
  81. else
  82. if (s_wb_master_fsm = IDLE) then
  83. if (LocalWen_i = '1' or LocalRen_i = '1') then
  84. WbAdr_o <= LocalAdress_i;
  85. s_wb_wen <= LocalWen_i;
  86. end if;
  87. if (LocalWen_i = '1') then
  88. WbDat_o <= LocalData_i;
  89. end if;
  90. end if;
  91. end if;
  92. end if;
  93. end process OutRegsP;
  94. end architecture rtl;