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

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [rtl/] [core/] [neorv32_bus_keeper.vhd] - Diff between revs 69 and 70

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

Rev 69 Rev 70
Line 1... Line 1...
-- #################################################################################################
-- #################################################################################################
-- # << NEORV32 - Bus Keeper (BUSKEEPER) >>                                                        #
-- # << NEORV32 - Bus Keeper (BUSKEEPER) >>                                                        #
-- # ********************************************************************************************* #
-- # ********************************************************************************************* #
-- # This unit monitors the processor-internal bus. If the accessed module does not respond within #
-- # This unit monitors the processor-internal bus. If the accessed module does not respond within #
-- # the defined number of  cycles (VHDL package: max_proc_int_response_time_c) or issues an ERROR #
-- # the defined number of  cycles (VHDL package: max_proc_int_response_time_c) or issues an ERROR #
-- # conditions the BUS KEEPER asserts the error signal to inform the CPU.                         #
-- # condition, the BUS KEEPER asserts the error signal to inform the CPU.                         #
-- # ********************************************************************************************* #
-- # ********************************************************************************************* #
-- # BSD 3-Clause License                                                                          #
-- # BSD 3-Clause License                                                                          #
-- #                                                                                               #
-- #                                                                                               #
-- # Copyright (c) 2021, Stephan Nolting. All rights reserved.                                     #
-- # Copyright (c) 2022, Stephan Nolting. All rights reserved.                                     #
-- #                                                                                               #
-- #                                                                                               #
-- # Redistribution and use in source and binary forms, with or without modification, are          #
-- # Redistribution and use in source and binary forms, with or without modification, are          #
-- # permitted provided that the following conditions are met:                                     #
-- # permitted provided that the following conditions are met:                                     #
-- #                                                                                               #
-- #                                                                                               #
-- # 1. Redistributions of source code must retain the above copyright notice, this list of        #
-- # 1. Redistributions of source code must retain the above copyright notice, this list of        #
Line 49... Line 49...
    clk_i      : in  std_ulogic; -- global clock line
    clk_i      : in  std_ulogic; -- global clock line
    rstn_i     : in  std_ulogic; -- global reset, low-active, async
    rstn_i     : in  std_ulogic; -- global reset, low-active, async
    addr_i     : in  std_ulogic_vector(31 downto 0); -- address
    addr_i     : in  std_ulogic_vector(31 downto 0); -- address
    rden_i     : in  std_ulogic; -- read enable
    rden_i     : in  std_ulogic; -- read enable
    wren_i     : in  std_ulogic; -- write enable
    wren_i     : in  std_ulogic; -- write enable
 
    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
    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
    -- bus monitoring --
    -- bus monitoring --
    bus_addr_i : in  std_ulogic_vector(31 downto 0); -- address
    bus_addr_i : in  std_ulogic_vector(31 downto 0); -- address
    bus_rden_i : in  std_ulogic; -- read enable
    bus_rden_i : in  std_ulogic; -- read enable
    bus_wren_i : in  std_ulogic; -- write enable
    bus_wren_i : in  std_ulogic; -- write enable
    bus_ack_i  : in  std_ulogic; -- transfer acknowledge from bus system
    bus_ack_i  : in  std_ulogic; -- transfer acknowledge from bus system
    bus_err_i  : in  std_ulogic; -- transfer error from bus system
    bus_err_i  : in  std_ulogic; -- transfer error from bus system
    bus_tmo_i  : in  std_ulogic; -- transfer timeout (external interface)
    bus_tmo_i  : in  std_ulogic; -- transfer timeout (external interface)
    bus_ext_i  : in  std_ulogic  -- external bus access
    bus_ext_i  : in  std_ulogic; -- external bus access
 
    bus_xip_i  : in  std_ulogic  -- pending XIP access
  );
  );
end neorv32_bus_keeper;
end neorv32_bus_keeper;
 
 
architecture neorv32_bus_keeper_rtl of neorv32_bus_keeper is
architecture neorv32_bus_keeper_rtl of neorv32_bus_keeper is
 
 
  -- IO space: module base address --
  -- IO space: module base address --
  constant hi_abb_c : natural := index_size_f(io_size_c)-1; -- high address boundary bit
  constant hi_abb_c : natural := index_size_f(io_size_c)-1; -- high address boundary bit
  constant lo_abb_c : natural := index_size_f(buskeeper_size_c); -- low address boundary bit
  constant lo_abb_c : natural := index_size_f(buskeeper_size_c); -- low address boundary bit
 
 
  -- Control register --
  -- Control register --
  constant ctrl_err_type_c : natural :=  0; -- r/-: error type: 0=device error, 1=access timeout
  constant ctrl_err_type_c     : natural :=  0; -- r/-: error type LSB: 0=device error, 1=access timeout
 
  constant ctrl_nul_check_en_c : natural := 16; -- r/w: enable NULL address check
  constant ctrl_err_flag_c : natural := 31; -- r/c: bus error encountered, sticky; cleared by writing zero
  constant ctrl_err_flag_c : natural := 31; -- r/c: bus error encountered, sticky; cleared by writing zero
 
  --
 
  signal ctrl_null_check_en : std_ulogic;
 
 
 
  -- error codes --
 
  constant err_device_c  : std_ulogic := '0'; -- device access error
 
  constant err_timeout_c : std_ulogic := '1'; -- timeout error
 
 
  -- sticky error flags --
  -- sticky error flags --
  signal err_flag : std_ulogic;
  signal err_flag : std_ulogic;
  signal err_type : std_ulogic;
  signal err_type : std_ulogic;
 
 
 
  -- NULL address check --
 
  signal null_check : std_ulogic;
 
 
  -- access control --
  -- access control --
  signal acc_en : std_ulogic; -- module access enable
  signal acc_en : std_ulogic; -- module access enable
  signal wren   : std_ulogic; -- word write enable
  signal wren   : std_ulogic; -- word write enable
  signal rden   : std_ulogic; -- read enable
  signal rden   : std_ulogic; -- read enable
 
 
Line 107... Line 119...
  rden   <= acc_en and rden_i;
  rden   <= acc_en and rden_i;
 
 
 
 
  -- Read/Write Access ----------------------------------------------------------------------
  -- Read/Write Access ----------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
  rw_access: process(clk_i)
  rw_access: process(rstn_i, clk_i)
  begin
  begin
    if rising_edge(clk_i) then
    if (rstn_i = '0') then
 
      ack_o              <= '-';
 
      data_o             <= (others => '-');
 
      ctrl_null_check_en <= '0'; -- required
 
      err_flag           <= '0'; -- required
 
      err_type           <= '0';
 
    elsif rising_edge(clk_i) then
      -- bus handshake --
      -- bus handshake --
      ack_o <= wren or rden;
      ack_o <= wren or rden;
 
 
 
      -- write access --
 
      if (wren = '1') then
 
        ctrl_null_check_en <= data_i(ctrl_nul_check_en_c);
 
      end if;
 
 
      -- read access --
      -- read access --
      data_o <= (others => '0');
      data_o <= (others => '0');
      if (rden = '1') then
      if (rden = '1') then
        data_o(ctrl_err_type_c) <= err_type;
        data_o(ctrl_err_type_c) <= err_type;
 
        data_o(ctrl_nul_check_en_c) <= ctrl_null_check_en;
        data_o(ctrl_err_flag_c) <= err_flag;
        data_o(ctrl_err_flag_c) <= err_flag;
      end if;
      end if;
      --
      --
      if (control.bus_err = '1') then -- sticky error flag
      if (control.bus_err = '1') then -- sticky error flag
        err_flag <= '1';
        err_flag <= '1';
        err_type <= control.err_type;
        err_type <= control.err_type;
      elsif ((wren or rden) = '1') then -- clear on or read or write
      else
 
        if ((wren or rden) = '1') then -- clear on read or write access
        err_flag <= '0';
        err_flag <= '0';
        err_type <= '0';
        end if;
      end if;
      end if;
    end if;
    end if;
  end process rw_access;
  end process rw_access;
 
 
 
 
  -- Keeper ---------------------------------------------------------------------------------
  -- Keeper ---------------------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
  keeper_control: process(rstn_i, clk_i)
  keeper_control: process(rstn_i, clk_i)
  begin
  begin
    if (rstn_i = '0') then
    if (rstn_i = '0') then
      control.pending  <= '0';
      control.pending  <= '0'; -- required
      control.bus_err  <= '0';
      control.bus_err  <= '0'; -- required
      control.err_type <= def_rst_val_c;
      control.err_type <= '-';
      control.timeout  <= (others => def_rst_val_c);
      control.timeout  <= (others => '-');
    elsif rising_edge(clk_i) then
    elsif rising_edge(clk_i) then
      -- defaults --
      -- defaults --
      control.bus_err <= '0';
      control.bus_err <= '0';
 
 
      -- access monitor: IDLE --
      -- access monitor: IDLE --
      if (control.pending = '0') then
      if (control.pending = '0') then
        control.timeout <= std_ulogic_vector(to_unsigned(max_proc_int_response_time_c, index_size_f(max_proc_int_response_time_c)+1));
        control.timeout <= std_ulogic_vector(to_unsigned(max_proc_int_response_time_c, index_size_f(max_proc_int_response_time_c)+1));
        if (bus_rden_i = '1') or (bus_wren_i = '1') then
        if (bus_rden_i = '1') or (bus_wren_i = '1') then
          control.pending <= '1';
          control.pending <= '1';
 
          if (null_check = '1') then -- invalid access to NULL address
 
            control.bus_err <= '1';
 
          end if;
        end if;
        end if;
      -- access monitor: PENDING --
      -- access monitor: PENDING --
      else
      else
        control.timeout <= std_ulogic_vector(unsigned(control.timeout) - 1); -- countdown timer
        control.timeout <= std_ulogic_vector(unsigned(control.timeout) - 1); -- countdown timer
        if (bus_err_i = '1') then -- error termination by bus system
        if (bus_err_i = '1') or (control.bus_err = '1') then -- error termination by bus system
          control.err_type <= '0'; -- device error
          control.err_type <= err_device_c; -- device error
          control.bus_err  <= '1';
          control.bus_err  <= '1';
          control.pending  <= '0';
          control.pending  <= '0';
        elsif ((or_reduce_f(control.timeout) = '0') and (bus_ext_i = '0')) or -- internal access timeout
        elsif ((or_reduce_f(control.timeout) = '0') and (bus_ext_i = '0') and (bus_xip_i = '0')) or -- valid internal access timeout
              (bus_tmo_i = '1') then -- external access timeout
              (bus_tmo_i = '1') then -- external access timeout
          control.err_type <= '1'; -- timeout error
          control.err_type <= err_timeout_c; -- timeout error
          control.bus_err  <= '1';
          control.bus_err  <= '1';
          control.pending  <= '0';
          control.pending  <= '0';
        elsif (bus_ack_i = '1') then -- normal termination by bus system
        elsif (bus_ack_i = '1') then -- normal termination by bus system
          control.err_type <= '0'; -- don't care
          control.err_type <= '0'; -- don't care
          control.bus_err  <= '0';
          control.bus_err  <= '0';
Line 171... Line 199...
        end if;
        end if;
      end if;
      end if;
    end if;
    end if;
  end process keeper_control;
  end process keeper_control;
 
 
 
  -- NULL address check --
 
  null_check <= '1' when (ctrl_null_check_en = '1') and (or_reduce_f(addr_i) = '0') else '0';
 
 
  -- signal bus error to CPU --
  -- signal bus error to CPU --
  err_o <= control.bus_err;
  err_o <= control.bus_err;
 
 
 
 
end neorv32_bus_keeper_rtl;
end neorv32_bus_keeper_rtl;

powered by: WebSVN 2.1.0

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