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

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [rtl/] [core/] [neorv32_bus_keeper.vhd] - Blame information for rev 62

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 57 zero_gravi
-- #################################################################################################
2
-- # << NEORV32 - Bus Keeper (BUSKEEPER) >>                                                        #
3
-- # ********************************************************************************************* #
4 59 zero_gravi
-- # This unit monitors the processor-internal bus. If the accessed INTERNAL (IMEM if enabled,     #
5 57 zero_gravi
-- # DMEM if enabled, BOOTROM + IO region) module does not respond within the defined number of    #
6 59 zero_gravi
-- # cycles (VHDL package: max_proc_int_response_time_c) the BUS KEEPER asserts the error signal   #
7
-- # to inform the CPU / bus driver.                                                               #
8
-- #                                                                                               #
9
-- # WARNING: The bus keeper timeout does not track accesses via the processor-external bus        #
10
-- #          interface! If the timeout-function of the Wishbone interface is not used, the CPU    #
11
-- #          might be permanently stalled by an an unacknowledged transfer! If the external bus   #
12
-- #          interface is disabled, ALL accesses by the CPU are internal.                         #
13 57 zero_gravi
-- # ********************************************************************************************* #
14
-- # BSD 3-Clause License                                                                          #
15
-- #                                                                                               #
16
-- # Copyright (c) 2021, Stephan Nolting. All rights reserved.                                     #
17
-- #                                                                                               #
18
-- # Redistribution and use in source and binary forms, with or without modification, are          #
19
-- # permitted provided that the following conditions are met:                                     #
20
-- #                                                                                               #
21
-- # 1. Redistributions of source code must retain the above copyright notice, this list of        #
22
-- #    conditions and the following disclaimer.                                                   #
23
-- #                                                                                               #
24
-- # 2. Redistributions in binary form must reproduce the above copyright notice, this list of     #
25
-- #    conditions and the following disclaimer in the documentation and/or other materials        #
26
-- #    provided with the distribution.                                                            #
27
-- #                                                                                               #
28
-- # 3. Neither the name of the copyright holder nor the names of its contributors may be used to  #
29
-- #    endorse or promote products derived from this software without specific prior written      #
30
-- #    permission.                                                                                #
31
-- #                                                                                               #
32
-- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS   #
33
-- # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF               #
34
-- # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE    #
35
-- # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,     #
36
-- # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE #
37
-- # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED    #
38
-- # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING     #
39
-- # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED  #
40
-- # OF THE POSSIBILITY OF SUCH DAMAGE.                                                            #
41
-- # ********************************************************************************************* #
42
-- # The NEORV32 Processor - https://github.com/stnolting/neorv32              (c) Stephan Nolting #
43
-- #################################################################################################
44
 
45
library ieee;
46
use ieee.std_logic_1164.all;
47
use ieee.numeric_std.all;
48
 
49
library neorv32;
50
use neorv32.neorv32_package.all;
51
 
52
entity neorv32_bus_keeper is
53
  generic (
54 59 zero_gravi
    -- External memory interface --
55 62 zero_gravi
    MEM_EXT_EN        : boolean; -- implement external memory bus interface?
56 57 zero_gravi
    -- Internal instruction memory --
57 62 zero_gravi
    MEM_INT_IMEM_EN   : boolean; -- implement processor-internal instruction memory
58
    MEM_INT_IMEM_SIZE : natural; -- size of processor-internal instruction memory in bytes
59 57 zero_gravi
    -- Internal data memory --
60 62 zero_gravi
    MEM_INT_DMEM_EN   : boolean; -- implement processor-internal data memory
61
    MEM_INT_DMEM_SIZE : natural  -- size of processor-internal data memory in bytes
62 57 zero_gravi
  );
63
  port (
64
    -- host access --
65
    clk_i  : in  std_ulogic; -- global clock line
66
    rstn_i : in  std_ulogic; -- global reset line, low-active
67
    addr_i : in  std_ulogic_vector(31 downto 0); -- address
68
    rden_i : in  std_ulogic; -- read enable
69
    wren_i : in  std_ulogic; -- write enable
70
    ack_i  : in  std_ulogic; -- transfer acknowledge from bus system
71
    err_i  : in  std_ulogic; -- transfer error from bus system
72
    err_o  : out std_ulogic  -- bus error
73
  );
74
end neorv32_bus_keeper;
75
 
76
architecture neorv32_bus_keeper_rtl of neorv32_bus_keeper is
77
 
78
  -- access check --
79
  type access_check_t is record
80
    int_imem       : std_ulogic;
81
    int_dmem       : std_ulogic;
82
    int_bootrom_io : std_ulogic;
83
    valid          : std_ulogic;
84
  end record;
85
  signal access_check : access_check_t;
86
 
87
  -- controller --
88
  type control_t is record
89
    pending : std_ulogic;
90
    timeout : std_ulogic_vector(index_size_f(max_proc_int_response_time_c)-1 downto 0);
91
    bus_err : std_ulogic;
92
  end record;
93
  signal control : control_t;
94
 
95
begin
96
 
97
  -- Sanity Check --------------------------------------------------------------------------
98
  -- -------------------------------------------------------------------------------------------
99
  assert not (max_proc_int_response_time_c < 2) report "NEORV32 PROCESSOR CONFIG ERROR! Processor-internal bus timeout <max_proc_int_response_time_c> has to >= 2." severity error;
100
 
101
 
102
  -- Access Control -------------------------------------------------------------------------
103
  -- -------------------------------------------------------------------------------------------
104
  -- access to processor-internal IMEM or DMEM? --
105
  access_check.int_imem <= '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_EN = true) else '0';
106
  access_check.int_dmem <= '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_EN = true) else '0';
107
  -- access to processor-internal BOOTROM or IO devices? --
108
  access_check.int_bootrom_io <= '1' when (addr_i(31 downto 16) = boot_rom_base_c(31 downto 16)) else '0'; -- hacky!
109
  -- actual internal bus access? --
110
  access_check.valid <= access_check.int_imem or access_check.int_dmem or access_check.int_bootrom_io;
111
 
112
 
113
  -- Keeper ---------------------------------------------------------------------------------
114
  -- -------------------------------------------------------------------------------------------
115
  keeper_control: process(rstn_i, clk_i)
116
  begin
117
    if (rstn_i = '0') then
118
      control.pending <= '0';
119
      control.bus_err <= '0';
120
      control.timeout <= (others => def_rst_val_c);
121
    elsif rising_edge(clk_i) then
122
 
123
      -- pending access? --
124
      control.bus_err <= '0';
125
      if (control.pending = '0') then -- idle
126 59 zero_gravi
        if ((rden_i or wren_i) = '1') and ((access_check.valid = '1') or (MEM_EXT_EN = false)) then -- valid INTERNAL access
127 57 zero_gravi
          control.pending <= '1';
128
        end if;
129
      else -- pending
130
        if (ack_i = '1') or (err_i = '1') then -- termination by bus system
131
          control.pending <= '0';
132 60 zero_gravi
        elsif (or_reduce_f(control.timeout) = '0') then -- timeout! terminate bus transfer
133 57 zero_gravi
          control.pending <= '0';
134
          control.bus_err <= '1';
135
        end if;
136
      end if;
137
 
138
      -- timeout counter --
139
      if (control.pending = '0') then
140
        control.timeout <= std_ulogic_vector(to_unsigned(max_proc_int_response_time_c, index_size_f(max_proc_int_response_time_c)));
141
      else
142
        control.timeout <= std_ulogic_vector(unsigned(control.timeout) - 1); -- countdown timer
143
      end if;
144
    end if;
145
  end process keeper_control;
146
 
147
  err_o <= control.bus_err;
148
 
149
 
150
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.