OpenCores
URL https://opencores.org/ocsvn/neorv32/neorv32/trunk

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [rtl/] [core/] [neorv32_wishbone.vhd] - Diff between revs 38 and 39

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 38 Rev 39
Line 1... Line 1...
-- #################################################################################################
-- #################################################################################################
-- # << NEORV32 - External Bus Interface (WISHBONE) >>                                             #
-- # << NEORV32 - External Bus Interface (WISHBONE) >>                                             #
-- # ********************************************************************************************* #
-- # ********************************************************************************************* #
-- # The interface provides registers for all outgoing signals. If the host cancels a running      #
-- # The interface provides registers for all outgoing signals. If the host cancels a running      #
-- # transfer, the Wishbone arbiter still waits some time for the bus system to ACK to transfer.   #
-- # transfer, the Wishbone arbiter still waits some time for the bus system to ACK the transfer   #
 
-- # before the arbiter forces termination.                                                        #
-- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
-- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
-- # All bus accesses from the CPU, which do not target the internal IO region, the internal boot- #
-- # Even when all processor-internal memories and IO devices are disabled, the EXTERNAL address   #
-- # loader or the internal instruction or data memories (if implemented), are delegated via this  #
-- # space ENDS at address 0xffff0000 (begin of internal BOOTROM address space).                   #
-- # Wishbone gateway to the external bus interface.                                               #
-- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
 
-- # All bus accesses from the CPU, which do not target the internal IO region / the internal      #
 
-- # bootlloader / the internal instruction or data memories (if implemented), are delegated via   #
 
-- # this Wishbone gateway to the external bus interface. Accessed peripherals can have a response #
 
-- # latency of up to neorv32_package.vhd:bus_timeout_c - 2 cycles.                                #
-- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
-- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
-- # This interface supports classic/standard Wishbone transactions (WB_PIPELINED_MODE = false)    #
-- # This interface supports classic/standard Wishbone transactions (WB_PIPELINED_MODE = false)    #
-- # and also pipelined transactions (WB_PIPELINED_MODE = true).                                   #
-- # and also pipelined transactions (WB_PIPELINED_MODE = true).                                   #
-- # ********************************************************************************************* #
-- # ********************************************************************************************* #
-- # BSD 3-Clause License                                                                          #
-- # BSD 3-Clause License                                                                          #
Line 70... Line 75...
    wren_i   : in  std_ulogic; -- write enable
    wren_i   : in  std_ulogic; -- write enable
    ben_i    : in  std_ulogic_vector(03 downto 0); -- byte write enable
    ben_i    : in  std_ulogic_vector(03 downto 0); -- byte write enable
    data_i   : in  std_ulogic_vector(31 downto 0); -- data in
    data_i   : in  std_ulogic_vector(31 downto 0); -- data in
    data_o   : out std_ulogic_vector(31 downto 0); -- data out
    data_o   : out std_ulogic_vector(31 downto 0); -- data out
    cancel_i : in  std_ulogic; -- cancel current bus transaction
    cancel_i : in  std_ulogic; -- cancel current bus transaction
 
    lock_i    : in  std_ulogic; -- locked/exclusive bus access
    ack_o    : out std_ulogic; -- transfer acknowledge
    ack_o    : out std_ulogic; -- transfer acknowledge
    err_o    : out std_ulogic; -- transfer error
    err_o    : out std_ulogic; -- transfer error
    priv_i   : in  std_ulogic_vector(1 downto 0); -- current CPU privilege level
    priv_i   : in  std_ulogic_vector(1 downto 0); -- current CPU privilege level
    -- wishbone interface --
    -- wishbone interface --
    wb_tag_o : out std_ulogic_vector(2 downto 0); -- tag
    wb_tag_o : out std_ulogic_vector(2 downto 0); -- tag
Line 82... Line 88...
    wb_dat_o : out std_ulogic_vector(31 downto 0); -- write data
    wb_dat_o : out std_ulogic_vector(31 downto 0); -- write data
    wb_we_o  : out std_ulogic; -- read/write
    wb_we_o  : out std_ulogic; -- read/write
    wb_sel_o : out std_ulogic_vector(03 downto 0); -- byte enable
    wb_sel_o : out std_ulogic_vector(03 downto 0); -- byte enable
    wb_stb_o : out std_ulogic; -- strobe
    wb_stb_o : out std_ulogic; -- strobe
    wb_cyc_o : out std_ulogic; -- valid cycle
    wb_cyc_o : out std_ulogic; -- valid cycle
 
    wb_lock_o : out std_ulogic; -- locked/exclusive bus access
    wb_ack_i : in  std_ulogic; -- transfer acknowledge
    wb_ack_i : in  std_ulogic; -- transfer acknowledge
    wb_err_i : in  std_ulogic  -- transfer error
    wb_err_i : in  std_ulogic  -- transfer error
  );
  );
end neorv32_wishbone;
end neorv32_wishbone;
 
 
architecture neorv32_wishbone_rtl of neorv32_wishbone is
architecture neorv32_wishbone_rtl of neorv32_wishbone is
 
 
  -- constants --
  -- constants --
  constant wb_timeout_c : natural := bus_timeout_c/2;
  constant xbus_timeout_c : natural := bus_timeout_c/4;
 
 
  -- access control --
  -- access control --
  signal int_imem_acc, int_imem_acc_real : std_ulogic;
  signal int_imem_acc : std_ulogic;
  signal int_dmem_acc, int_dmem_acc_real : std_ulogic;
  signal int_dmem_acc : std_ulogic;
  signal int_boot_acc                    : std_ulogic;
  signal int_boot_acc                    : std_ulogic;
  signal wb_access                       : std_ulogic;
  signal xbus_access  : std_ulogic;
 
 
  -- bus arbiter
  -- bus arbiter
  type ctrl_state_t is (IDLE, BUSY, CANCELED, RESYNC);
  type ctrl_state_t is (IDLE, BUSY, CANCELED, RESYNC);
  type ctrl_t is record
  type ctrl_t is record
    state      : ctrl_state_t;
    state      : ctrl_state_t;
    state_prev : ctrl_state_t;
 
    we         : std_ulogic;
    we         : std_ulogic;
    rd_req     : std_ulogic;
    rd_req     : std_ulogic;
    wr_req     : std_ulogic;
    wr_req     : std_ulogic;
    adr        : std_ulogic_vector(31 downto 0);
    adr        : std_ulogic_vector(31 downto 0);
    wdat       : std_ulogic_vector(31 downto 0);
    wdat       : std_ulogic_vector(31 downto 0);
    rdat       : std_ulogic_vector(31 downto 0);
    rdat       : std_ulogic_vector(31 downto 0);
    sel        : std_ulogic_vector(3 downto 0);
    sel        : std_ulogic_vector(3 downto 0);
    ack        : std_ulogic;
    ack        : std_ulogic;
    err        : std_ulogic;
    err        : std_ulogic;
    timeout    : std_ulogic_vector(index_size_f(wb_timeout_c)-1 downto 0);
    timeout : std_ulogic_vector(index_size_f(xbus_timeout_c)-1 downto 0);
    src        : std_ulogic;
    src        : std_ulogic;
 
    lock    : std_ulogic;
    priv       : std_ulogic_vector(1 downto 0);
    priv       : std_ulogic_vector(1 downto 0);
  end record;
  end record;
  signal ctrl    : ctrl_t;
  signal ctrl    : ctrl_t;
  signal stb_int : std_ulogic;
  signal stb_int : std_ulogic;
  signal cyc_int : std_ulogic;
  signal cyc_int : std_ulogic;
 
 
begin
begin
 
 
  -- Sanity Checks --------------------------------------------------------------------------
  -- Sanity Checks --------------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
  assert not (bus_timeout_c <= 15) report "NEORV32 PROCESSOR CONFIG ERROR: Bus timeout (bus_timeout_c) should be >16 for interfacing external modules." severity error;
  -- max bus timeout latency lower than recommended --
 
  assert not (bus_timeout_c <= 32) report "NEORV32 PROCESSOR CONFIG ERROR: Bus timeout (neorv32_package.vhd:bus_timeout_c) should be >32 when using external bus interface." severity error;
 
  -- external memory iterface protocol + max timeout latency notifier (warning) --
 
  assert not (wb_pipe_mode_c = false) report "NEORV32 PROCESSOR CONFIG NOTE: Implementing external memory interface using STANDARD Wishbone protocol with max latency = " & integer'image(bus_timeout_c) & " cycles." severity warning;
 
  assert not (wb_pipe_mode_c =  true) report "NEORV32 PROCESSOR CONFIG NOTE: Implementing external memory interface using PIEPLINED Wishbone protocol with max latency = " & integer'image(bus_timeout_c) & " cycles." severity warning;
 
 
 
 
  -- Access Control -------------------------------------------------------------------------
  -- Access Control -------------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
  -- access to internal IMEM or DMEM? --
  -- access to processor-internal IMEM or DMEM? --
  int_imem_acc <= '1' when (addr_i(31 downto index_size_f(MEM_INT_IMEM_SIZE)) = imem_base_c(31 downto index_size_f(MEM_INT_IMEM_SIZE))) else '0';
  int_imem_acc <= '1' when (addr_i(31 downto index_size_f(MEM_INT_IMEM_SIZE)) = imem_base_c(31 downto index_size_f(MEM_INT_IMEM_SIZE))) and (MEM_INT_IMEM_USE = true) else '0';
  int_dmem_acc <= '1' when (addr_i(31 downto index_size_f(MEM_INT_DMEM_SIZE)) = dmem_base_c(31 downto index_size_f(MEM_INT_DMEM_SIZE))) else '0';
  int_dmem_acc <= '1' when (addr_i(31 downto index_size_f(MEM_INT_DMEM_SIZE)) = dmem_base_c(31 downto index_size_f(MEM_INT_DMEM_SIZE))) and (MEM_INT_DMEM_USE = true) else '0';
  int_imem_acc_real <= int_imem_acc when (MEM_INT_IMEM_USE = true) else '0';
  -- access to processor-internal BOOTROM or IO devices? --
  int_dmem_acc_real <= int_dmem_acc when (MEM_INT_DMEM_USE = true) else '0';
  int_boot_acc <= '1' when (addr_i(31 downto 16) = boot_rom_base_c(31 downto 16)) else '0'; -- hacky!
 
 
  -- access to internal BOOTROM or IO devices? --
 
  int_boot_acc <= '1' when (addr_i >= boot_rom_base_c) else '0'; -- this also covers access to the IO space
 
--int_boot_acc <= '1' when (addr_i(31 downto index_size_f(2*boot_rom_max_size_c)) = boot_rom_base_c(31 downto index_size_f(2*boot_rom_max_size_c))) else '0'; -- this also covers access to the IO space
 
--int_io_acc   <= '1' when (addr_i >= io_base_c) else '0';
 
 
 
  -- actual external bus access? --
  -- actual external bus access? --
  wb_access <= (not int_imem_acc_real) and (not int_dmem_acc_real) and (not int_boot_acc);
  xbus_access <= (not int_imem_acc) and (not int_dmem_acc) and (not int_boot_acc);
 
 
  -- Bus Arbiter -----------------------------------------------------------------------------
  -- Bus Arbiter -----------------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
  bus_arbiter: process(rstn_i, clk_i)
  bus_arbiter: process(rstn_i, clk_i)
  begin
  begin
    if (rstn_i = '0') then
    if (rstn_i = '0') then
      ctrl.state      <= IDLE;
      ctrl.state      <= IDLE;
      ctrl.state_prev <= IDLE;
 
      ctrl.we         <= '0';
      ctrl.we         <= '0';
      ctrl.rd_req     <= '0';
      ctrl.rd_req     <= '0';
      ctrl.wr_req     <= '0';
      ctrl.wr_req     <= '0';
      ctrl.adr        <= (others => '0');
      ctrl.adr        <= (others => '0');
      ctrl.wdat       <= (others => '0');
      ctrl.wdat       <= (others => '0');
Line 161... Line 165...
      ctrl.sel        <= (others => '0');
      ctrl.sel        <= (others => '0');
      ctrl.timeout    <= (others => '0');
      ctrl.timeout    <= (others => '0');
      ctrl.ack        <= '0';
      ctrl.ack        <= '0';
      ctrl.err        <= '0';
      ctrl.err        <= '0';
      ctrl.src        <= '0';
      ctrl.src        <= '0';
 
      ctrl.lock    <= '0';
      ctrl.priv       <= "00";
      ctrl.priv       <= "00";
    elsif rising_edge(clk_i) then
    elsif rising_edge(clk_i) then
      -- defaults --
      -- defaults --
      ctrl.state_prev <= ctrl.state;
 
      ctrl.rdat       <= (others => '0');
      ctrl.rdat       <= (others => '0');
      ctrl.ack        <= '0';
      ctrl.ack        <= '0';
      ctrl.err        <= '0';
      ctrl.err        <= '0';
      ctrl.timeout    <= std_ulogic_vector(to_unsigned(wb_timeout_c, index_size_f(wb_timeout_c)));
      ctrl.timeout <= std_ulogic_vector(to_unsigned(xbus_timeout_c, index_size_f(xbus_timeout_c)));
 
 
      -- state machine --
      -- state machine --
      case ctrl.state is
      case ctrl.state is
 
 
        when IDLE => -- waiting for host request
        when IDLE => -- waiting for host request
Line 183... Line 187...
          ctrl.we   <= wren_i;
          ctrl.we   <= wren_i;
          ctrl.adr  <= addr_i;
          ctrl.adr  <= addr_i;
          ctrl.wdat <= data_i;
          ctrl.wdat <= data_i;
          ctrl.sel  <= ben_i;
          ctrl.sel  <= ben_i;
          ctrl.src  <= src_i;
          ctrl.src  <= src_i;
 
          ctrl.lock <= lock_i;
          ctrl.priv <= priv_i;
          ctrl.priv <= priv_i;
          -- valid read/write access --
          -- valid new or buffered read/write request --
          if ((wb_access and (wren_i or ctrl.wr_req or rden_i or ctrl.rd_req)) = '1') then
          if ((xbus_access and (wren_i or ctrl.wr_req or rden_i or ctrl.rd_req)) = '1') then
            ctrl.state <= BUSY;
            ctrl.state <= BUSY;
          end if;
          end if;
 
 
        when BUSY => -- transfer in progress
        when BUSY => -- transfer in progress
        -- ------------------------------------------------------------
        -- ------------------------------------------------------------
Line 241... Line 246...
 
 
  wb_adr_o <= ctrl.adr;
  wb_adr_o <= ctrl.adr;
  wb_dat_o <= ctrl.wdat;
  wb_dat_o <= ctrl.wdat;
  wb_we_o  <= ctrl.we;
  wb_we_o  <= ctrl.we;
  wb_sel_o <= ctrl.sel;
  wb_sel_o <= ctrl.sel;
 
  wb_lock_o <= ctrl.lock;
  wb_stb_o <= stb_int when (WB_PIPELINED_MODE = true) else cyc_int;
  wb_stb_o <= stb_int when (WB_PIPELINED_MODE = true) else cyc_int;
  wb_cyc_o <= cyc_int;
  wb_cyc_o <= cyc_int;
 
 
  stb_int  <= '1' when ((ctrl.state = BUSY) and (ctrl.state_prev = IDLE)) else '0';
  stb_int <= '1' when (ctrl.state = BUSY) else '0';
  cyc_int  <= '0' when ((ctrl.state = IDLE) or (ctrl.state = RESYNC)) else '1';
  cyc_int <= '0' when (ctrl.state = IDLE) or (ctrl.state = RESYNC) else '1';
 
 
 
 
end neorv32_wishbone_rtl;
end neorv32_wishbone_rtl;
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.