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

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [rtl/] [core/] [neorv32_wishbone.vhd] - Diff between revs 11 and 23

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

Rev 11 Rev 23
Line 2... Line 2...
-- # << NEORV32 - External Bus Interface (WISHBONE) >>                                             #
-- # << NEORV32 - External Bus Interface (WISHBONE) >>                                             #
-- # ********************************************************************************************* #
-- # ********************************************************************************************* #
-- # The interface is either unregistered (INTERFACE_REG_STAGES = 0), only outgoing signals are    #
-- # The interface is either unregistered (INTERFACE_REG_STAGES = 0), only outgoing signals are    #
-- # registered (INTERFACE_REG_STAGES = 1) or incoming and outgoing signals are registered         #
-- # registered (INTERFACE_REG_STAGES = 1) or incoming and outgoing signals are registered         #
-- # (INTERFACE_REG_STAGES = 2).                                                                   #
-- # (INTERFACE_REG_STAGES = 2).                                                                   #
-- #                                                                                               #
-- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
-- # All bus accesses from the CPU, which do not target the internal IO region, the internal boot- #
-- # All bus accesses from the CPU, which do not target the internal IO region, the internal boot- #
-- # loader or the internal instruction & data memories (if implemented), are delegated via this   #
-- # loader or the internal instruction or data memories (if implemented), are delegated via this  #
-- # Wishbone gateway to the external bus interface.                                               #
-- # Wishbone gateway to the external bus interface.                                               #
-- # ********************************************************************************************* #
-- # ********************************************************************************************* #
-- # BSD 3-Clause License                                                                          #
-- # BSD 3-Clause License                                                                          #
-- #                                                                                               #
-- #                                                                                               #
-- # Copyright (c) 2020, Stephan Nolting. All rights reserved.                                     #
-- # Copyright (c) 2020, Stephan Nolting. All rights reserved.                                     #
Line 48... Line 48...
use neorv32.neorv32_package.all;
use neorv32.neorv32_package.all;
 
 
entity neorv32_wishbone is
entity neorv32_wishbone is
  generic (
  generic (
    INTERFACE_REG_STAGES : natural := 2; -- number of interface register stages (0,1,2)
    INTERFACE_REG_STAGES : natural := 2; -- number of interface register stages (0,1,2)
    -- Memory configuration: Instruction memory --
    -- Internal instruction memory --
    MEM_ISPACE_BASE      : std_ulogic_vector(31 downto 0) := x"00000000"; -- base address of instruction memory space
 
    MEM_ISPACE_SIZE      : natural := 8*1024; -- total size of instruction memory space in byte
 
    MEM_INT_IMEM_USE     : boolean := true;   -- implement processor-internal instruction memory
    MEM_INT_IMEM_USE     : boolean := true;   -- implement processor-internal instruction memory
    MEM_INT_IMEM_SIZE    : natural := 8*1024; -- size of processor-internal instruction memory in bytes
    MEM_INT_IMEM_SIZE    : natural := 8*1024; -- size of processor-internal instruction memory in bytes
    -- Memory configuration: Data memory --
    -- Internal data memory --
    MEM_DSPACE_BASE      : std_ulogic_vector(31 downto 0) := x"80000000"; -- base address of data memory space
 
    MEM_DSPACE_SIZE      : natural := 4*1024; -- total size of data memory space in byte
 
    MEM_INT_DMEM_USE     : boolean := true;   -- implement processor-internal data memory
    MEM_INT_DMEM_USE     : boolean := true;   -- implement processor-internal data memory
    MEM_INT_DMEM_SIZE    : natural := 4*1024  -- size of processor-internal data memory in bytes
    MEM_INT_DMEM_SIZE    : natural := 4*1024  -- size of processor-internal data memory in bytes
  );
  );
  port (
  port (
    -- global control --
    -- global control --
Line 91... Line 87...
architecture neorv32_wishbone_rtl of neorv32_wishbone is
architecture neorv32_wishbone_rtl of neorv32_wishbone is
 
 
  -- access control --
  -- access control --
  signal int_imem_acc, int_imem_acc_real : std_ulogic;
  signal int_imem_acc, int_imem_acc_real : std_ulogic;
  signal int_dmem_acc, int_dmem_acc_real : std_ulogic;
  signal int_dmem_acc, int_dmem_acc_real : std_ulogic;
  signal int_boot_acc, int_io_acc        : std_ulogic;
  signal int_boot_acc                    : std_ulogic;
  signal wb_access                       : std_ulogic;
  signal wb_access                       : std_ulogic;
 
  signal wb_access_ff, wb_access_ff_ff   : std_ulogic;
 
  signal rb_en                           : std_ulogic;
 
 
  -- bus arbiter --
  -- bus arbiter --
  signal wb_stb_ff0 : std_ulogic;
  signal wb_stb_ff0 : std_ulogic;
  signal wb_stb_ff1 : std_ulogic;
  signal wb_stb_ff1 : std_ulogic;
  signal wb_cyc_ff  : std_ulogic;
  signal wb_cyc_ff  : std_ulogic;
  signal wb_ack_ff  : std_ulogic;
  signal wb_ack_ff  : std_ulogic;
  signal wb_err_ff  : std_ulogic;
  signal wb_err_ff  : std_ulogic;
 
 
 
  -- data read-back --
 
  signal wb_rdata : std_ulogic_vector(31 downto 0);
 
 
begin
begin
 
 
  -- Sanity Check ---------------------------------------------------------------------------
  -- Sanity Check ---------------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
  sanity_check: process(clk_i)
  assert (INTERFACE_REG_STAGES <= 2) report "NEORV32 CONFIG ERROR! Number of external memory interface buffer stages must be 0, 1 or 2." severity error;
  begin
  assert (INTERFACE_REG_STAGES /= 0) report "NEORV32 CONFIG WARNING! External memory interface without register stages is still experimental for peripherals with more than 1 cycle latency." severity warning;
    if rising_edge(clk_i) then
 
      if (INTERFACE_REG_STAGES > 2) then
 
        assert false report "NEORV32 CONFIG ERROR! Number of external memory interface buffer stages must be 0, 1 or 2." severity error;
 
      end if;
 
    end if;
 
  end process sanity_check;
 
 
 
 
 
  -- Access Control -------------------------------------------------------------------------
  -- Access Control -------------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
  -- access to internal IMEM or DMEM? --
  -- access to internal IMEM or DMEM? --
  int_imem_acc <= '1' when (addr_i >= MEM_ISPACE_BASE) and (addr_i < std_ulogic_vector(unsigned(MEM_ISPACE_BASE) + MEM_INT_IMEM_SIZE)) else '0';
  int_imem_acc <= '1' when (addr_i >= imem_base_c) and (addr_i < std_ulogic_vector(unsigned(imem_base_c) + MEM_INT_IMEM_SIZE)) else '0';
  int_dmem_acc <= '1' when (addr_i >= MEM_DSPACE_BASE) and (addr_i < std_ulogic_vector(unsigned(MEM_DSPACE_BASE) + MEM_INT_DMEM_SIZE)) else '0';
  int_dmem_acc <= '1' when (addr_i >= dmem_base_c) and (addr_i < std_ulogic_vector(unsigned(dmem_base_c) + MEM_INT_DMEM_SIZE)) else '0';
  int_imem_acc_real <= int_imem_acc when (MEM_INT_IMEM_USE = true) else '0';
  int_imem_acc_real <= int_imem_acc when (MEM_INT_IMEM_USE = true) else '0';
  int_dmem_acc_real <= int_dmem_acc when (MEM_INT_DMEM_USE = true) else '0';
  int_dmem_acc_real <= int_dmem_acc when (MEM_INT_DMEM_USE = true) else '0';
  int_boot_acc <= '1' when (addr_i >= boot_base_c) else '0';
  int_boot_acc <= '1' when (addr_i >= boot_rom_base_c) else '0'; -- this also covers access to the IO space
  int_io_acc   <= '1' when (addr_i >= io_base_c)   else '0';
--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) and (not int_io_acc) and (wren_i or rden_i);
  wb_access <= (not int_imem_acc_real) and (not int_dmem_acc_real) and (not int_boot_acc) and (wren_i or rden_i);
 
 
 
 
  -- Bus Arbiter -----------------------------------------------------------------------------
  -- Bus Arbiter -----------------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
  bus_arbiter: process(rstn_i, clk_i)
  bus_arbiter: process(rstn_i, clk_i)
Line 139... Line 134...
      wb_cyc_ff  <= '0';
      wb_cyc_ff  <= '0';
      wb_stb_ff1 <= '0';
      wb_stb_ff1 <= '0';
      wb_stb_ff0 <= '0';
      wb_stb_ff0 <= '0';
      wb_ack_ff  <= '0';
      wb_ack_ff  <= '0';
      wb_err_ff  <= '0';
      wb_err_ff  <= '0';
 
      wb_access_ff    <= '0';
 
      wb_access_ff_ff <= '0';
    elsif rising_edge(clk_i) then
    elsif rising_edge(clk_i) then
      -- bus cycle --
      -- bus cycle --
      if (INTERFACE_REG_STAGES = 0) then
      if (INTERFACE_REG_STAGES = 0) then
        wb_cyc_ff <= '0'; -- unused
        wb_cyc_ff <= '0'; -- unused
      else
      else
        wb_cyc_ff <= (wb_cyc_ff or wb_access) and ((not wb_ack_i) or (not wb_err_i)) and (not cancel_i);
        wb_cyc_ff <= (wb_cyc_ff or wb_access) and (not wb_ack_i) and (not wb_err_i) and (not cancel_i);
      end if;
      end if;
      -- bus strobe --
      -- bus strobe --
      wb_stb_ff1 <= wb_stb_ff0;
      wb_stb_ff1 <= wb_stb_ff0;
      wb_stb_ff0 <= wb_access;
      wb_stb_ff0 <= wb_access;
      -- bus ack --
      -- bus ack --
      wb_ack_ff <= wb_ack_i;
      wb_ack_ff <= wb_ack_i;
      -- bus err --
      -- bus err --
      wb_err_ff <= wb_err_i;
      wb_err_ff <= wb_err_i;
 
      -- access still active? --
 
      wb_access_ff_ff <= wb_access_ff;
 
      if (wb_access = '1') then
 
        wb_access_ff <= '1';
 
      elsif ((wb_ack_i or wb_err_i or cancel_i) = '1') then
 
        wb_access_ff <= '0';
 
      end if;
    end if;
    end if;
  end process bus_arbiter;
  end process bus_arbiter;
 
 
  -- bus cycle --
  -- bus cycle --
  wb_cyc_o <= wb_access when (INTERFACE_REG_STAGES = 0) else wb_cyc_ff;
  wb_cyc_o <= wb_access when (INTERFACE_REG_STAGES = 0) else wb_cyc_ff;
Line 168... Line 172...
  ack_o <= wb_ack_ff when (INTERFACE_REG_STAGES = 2) else wb_ack_i;
  ack_o <= wb_ack_ff when (INTERFACE_REG_STAGES = 2) else wb_ack_i;
 
 
  -- cpu err --
  -- cpu err --
  err_o <= wb_err_ff when (INTERFACE_REG_STAGES = 2) else wb_err_i;
  err_o <= wb_err_ff when (INTERFACE_REG_STAGES = 2) else wb_err_i;
 
 
 
  -- cpu read-data --
 
  rb_en  <= wb_access_ff_ff when (INTERFACE_REG_STAGES = 2) else wb_access_ff;
 
  data_o <= wb_rdata when (rb_en = '1') else (others => '0');
 
 
 
 
  -- Bus Buffer -----------------------------------------------------------------------------
  -- Bus Buffer -----------------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
  interface_reg_level_zero:
  interface_reg_level_zero:
  if (INTERFACE_REG_STAGES = 0) generate -- 0 register levels: direct connection
  if (INTERFACE_REG_STAGES = 0) generate -- 0 register levels: direct connection
    data_o   <= wb_dat_i;
    wb_rdata <= wb_dat_i;
    wb_adr_o <= addr_i;
    wb_adr_o <= addr_i;
    wb_dat_o <= data_i;
    wb_dat_o <= data_i;
    wb_sel_o <= ben_i;
    wb_sel_o <= ben_i;
    wb_we_o  <= wren_i;
    wb_we_o  <= wren_i;
  end generate;
  end generate;
Line 193... Line 201...
          wb_sel_o <= ben_i;
          wb_sel_o <= ben_i;
          wb_we_o  <= wren_i;
          wb_we_o  <= wren_i;
        end if;
        end if;
      end if;
      end if;
    end process buffer_stages_one;
    end process buffer_stages_one;
    data_o <= wb_dat_i;
    wb_rdata <= wb_dat_i;
  end generate;
  end generate;
 
 
  interface_reg_level_two:
  interface_reg_level_two:
  if (INTERFACE_REG_STAGES = 2) generate -- 2 register levels: buffer incoming and outgoing signals
  if (INTERFACE_REG_STAGES = 2) generate -- 2 register levels: buffer incoming and outgoing signals
    buffer_stages_two: process(clk_i)
    buffer_stages_two: process(clk_i)
Line 206... Line 214...
        if (wb_cyc_ff = '0') then
        if (wb_cyc_ff = '0') then
          wb_adr_o <= addr_i;
          wb_adr_o <= addr_i;
          wb_dat_o <= data_i;
          wb_dat_o <= data_i;
          wb_sel_o <= ben_i;
          wb_sel_o <= ben_i;
          wb_we_o  <= wren_i;
          wb_we_o  <= wren_i;
          data_o   <= wb_dat_i;
        end if;
 
        if (wb_ack_i = '1') then
 
          wb_rdata <= wb_dat_i;
        end if;
        end if;
      end if;
      end if;
    end process buffer_stages_two;
    end process buffer_stages_two;
  end generate;
  end generate;
 
 

powered by: WebSVN 2.1.0

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