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

Subversion Repositories neorv32

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

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 66 zero_gravi
    clk_i      : in  std_ulogic; -- global clock line
66
    rstn_i     : in  std_ulogic; -- global reset, low-active, async
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
    data_o     : out std_ulogic_vector(31 downto 0); -- data out
71
    ack_o      : out std_ulogic; -- transfer acknowledge
72
    err_o      : out std_ulogic; -- transfer error
73
    -- bus monitoring --
74
    bus_addr_i : in  std_ulogic_vector(31 downto 0); -- address
75
    bus_rden_i : in  std_ulogic; -- read enable
76
    bus_wren_i : in  std_ulogic; -- write enable
77
    bus_ack_i  : in  std_ulogic; -- transfer acknowledge from bus system
78
    bus_err_i  : in  std_ulogic  -- transfer error from bus system
79 57 zero_gravi
  );
80
end neorv32_bus_keeper;
81
 
82
architecture neorv32_bus_keeper_rtl of neorv32_bus_keeper is
83
 
84 66 zero_gravi
  -- IO space: module base address --
85
  constant hi_abb_c : natural := index_size_f(io_size_c)-1; -- high address boundary bit
86
  constant lo_abb_c : natural := index_size_f(buskeeper_size_c); -- low address boundary bit
87
 
88
  -- Control register --
89
  constant ctrl_err_type_c : natural :=  0; -- r/-: error type: 0=device error, 1=access timeout
90
  constant ctrl_err_src_c  : natural :=  1; -- r/-: error source: 0=processor-external, 1=processor-internal
91
  constant ctrl_err_flag_c : natural := 31; -- r/c: bus error encountered, sticky; cleared by writing zero
92
 
93
  -- sticky error flag --
94
  signal err_flag : std_ulogic;
95
 
96
  -- access control --
97
  signal acc_en : std_ulogic; -- module access enable
98
  signal wren   : std_ulogic; -- word write enable
99
  signal rden   : std_ulogic; -- read enable
100
 
101
  -- bus access check --
102 57 zero_gravi
  type access_check_t is record
103
    int_imem       : std_ulogic;
104
    int_dmem       : std_ulogic;
105
    int_bootrom_io : std_ulogic;
106
    valid          : std_ulogic;
107
  end record;
108
  signal access_check : access_check_t;
109
 
110
  -- controller --
111
  type control_t is record
112 66 zero_gravi
    pending  : std_ulogic;
113
    timeout  : std_ulogic_vector(index_size_f(max_proc_int_response_time_c)-1 downto 0);
114
    err_type : std_ulogic;
115
    int_ext  : std_ulogic;
116
    bus_err  : std_ulogic;
117 57 zero_gravi
  end record;
118
  signal control : control_t;
119
 
120
begin
121
 
122
  -- Sanity Check --------------------------------------------------------------------------
123
  -- -------------------------------------------------------------------------------------------
124
  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;
125
 
126
 
127
  -- Access Control -------------------------------------------------------------------------
128
  -- -------------------------------------------------------------------------------------------
129 66 zero_gravi
  acc_en <= '1' when (addr_i(hi_abb_c downto lo_abb_c) = buskeeper_base_c(hi_abb_c downto lo_abb_c)) else '0';
130
  wren   <= acc_en and wren_i;
131
  rden   <= acc_en and rden_i;
132
 
133
 
134
  -- Bus Access Check -----------------------------------------------------------------------
135
  -- -------------------------------------------------------------------------------------------
136 57 zero_gravi
  -- access to processor-internal IMEM or DMEM? --
137 66 zero_gravi
  access_check.int_imem <= '1' when (bus_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';
138
  access_check.int_dmem <= '1' when (bus_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';
139 57 zero_gravi
  -- access to processor-internal BOOTROM or IO devices? --
140 66 zero_gravi
  access_check.int_bootrom_io <= '1' when (bus_addr_i(31 downto 16) = boot_rom_base_c(31 downto 16)) else '0'; -- hacky!
141 57 zero_gravi
  -- actual internal bus access? --
142
  access_check.valid <= access_check.int_imem or access_check.int_dmem or access_check.int_bootrom_io;
143
 
144
 
145 66 zero_gravi
  -- Read/Write Access ----------------------------------------------------------------------
146
  -- -------------------------------------------------------------------------------------------
147
  rw_access: process(clk_i)
148
  begin
149
    if rising_edge(clk_i) then
150
      -- bus handshake --
151
      ack_o <= wren or rden;
152
 
153
      -- read access --
154
      data_o <= (others => '0');
155
      if (rden = '1') then
156
        data_o(ctrl_err_type_c) <= control.err_type;
157
        data_o(ctrl_err_src_c)  <= control.int_ext;
158
        data_o(ctrl_err_flag_c) <= err_flag;
159
      end if;
160
      --
161
      if (control.bus_err = '1') then
162
        err_flag <= '1'; -- sticky error flag
163
      elsif (rden = '1') then -- clear on read
164
        err_flag <= '0';
165
      end if;
166
    end if;
167
  end process rw_access;
168
 
169
 
170 57 zero_gravi
  -- Keeper ---------------------------------------------------------------------------------
171
  -- -------------------------------------------------------------------------------------------
172
  keeper_control: process(rstn_i, clk_i)
173
  begin
174
    if (rstn_i = '0') then
175 66 zero_gravi
      control.pending  <= '0';
176
      control.bus_err  <= '0';
177
      control.err_type <= def_rst_val_c;
178
      control.int_ext  <= def_rst_val_c;
179
      control.timeout  <= (others => def_rst_val_c);
180
      err_o            <= '0';
181
    elsif rising_edge(clk_i) then
182
      -- defaults --
183 57 zero_gravi
      control.bus_err <= '0';
184
 
185 66 zero_gravi
      -- access monitor: IDLE --
186
      if (control.pending = '0') then
187
        control.timeout <= std_ulogic_vector(to_unsigned(max_proc_int_response_time_c, index_size_f(max_proc_int_response_time_c)));
188
        if (bus_rden_i = '1') or (bus_wren_i = '1') then
189
          if (access_check.valid = '1') or (MEM_EXT_EN = false) then
190
            control.int_ext <= '1'; -- processor-internal access
191
          else
192
            control.int_ext <= '0'; -- processor-external access
193
          end if;
194 57 zero_gravi
          control.pending <= '1';
195
        end if;
196
 
197 66 zero_gravi
      -- access monitor: PENDING --
198 57 zero_gravi
      else
199
        control.timeout <= std_ulogic_vector(unsigned(control.timeout) - 1); -- countdown timer
200 66 zero_gravi
        if (bus_ack_i = '1') then -- normal termination by bus system
201
          control.err_type <= '0'; -- don't care
202
          control.bus_err  <= '0';
203
          control.pending  <= '0';
204
        elsif (bus_err_i = '1') then -- error termination by bus system
205
          control.err_type <= '0'; -- device error
206
          control.bus_err  <= '1';
207
          control.pending  <= '0';
208
        elsif (or_reduce_f(control.timeout) = '0') and (control.int_ext = '1') then -- timeout! terminate bus transfer (internal accesses only!)
209
          control.err_type <= '1'; -- timeout error
210
          control.bus_err  <= '1';
211
          control.pending  <= '0';
212
        end if;
213 57 zero_gravi
      end if;
214 66 zero_gravi
 
215
    -- only output timeout errors here - device errors are already propagated by the bus system --
216
    err_o <= control.bus_err and control.err_type;
217 57 zero_gravi
    end if;
218
  end process keeper_control;
219
 
220
 
221
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.