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

Subversion Repositories neorv32

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

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 68 zero_gravi
-- # This unit monitors the processor-internal bus. If the accessed module does not respond within #
5 70 zero_gravi
-- # the defined number of cycles (VHDL package: max_proc_int_response_time_c) or issues an ERROR  #
6
-- # condition, the BUS KEEPER asserts the error signal to inform the CPU.                         #
7 57 zero_gravi
-- # ********************************************************************************************* #
8
-- # BSD 3-Clause License                                                                          #
9
-- #                                                                                               #
10 70 zero_gravi
-- # Copyright (c) 2022, Stephan Nolting. All rights reserved.                                     #
11 57 zero_gravi
-- #                                                                                               #
12
-- # Redistribution and use in source and binary forms, with or without modification, are          #
13
-- # permitted provided that the following conditions are met:                                     #
14
-- #                                                                                               #
15
-- # 1. Redistributions of source code must retain the above copyright notice, this list of        #
16
-- #    conditions and the following disclaimer.                                                   #
17
-- #                                                                                               #
18
-- # 2. Redistributions in binary form must reproduce the above copyright notice, this list of     #
19
-- #    conditions and the following disclaimer in the documentation and/or other materials        #
20
-- #    provided with the distribution.                                                            #
21
-- #                                                                                               #
22
-- # 3. Neither the name of the copyright holder nor the names of its contributors may be used to  #
23
-- #    endorse or promote products derived from this software without specific prior written      #
24
-- #    permission.                                                                                #
25
-- #                                                                                               #
26
-- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS   #
27
-- # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF               #
28
-- # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE    #
29
-- # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,     #
30
-- # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE #
31
-- # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED    #
32
-- # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING     #
33
-- # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED  #
34
-- # OF THE POSSIBILITY OF SUCH DAMAGE.                                                            #
35
-- # ********************************************************************************************* #
36
-- # The NEORV32 Processor - https://github.com/stnolting/neorv32              (c) Stephan Nolting #
37
-- #################################################################################################
38
 
39
library ieee;
40
use ieee.std_logic_1164.all;
41
use ieee.numeric_std.all;
42
 
43
library neorv32;
44
use neorv32.neorv32_package.all;
45
 
46
entity neorv32_bus_keeper is
47
  port (
48
    -- host access --
49 66 zero_gravi
    clk_i      : in  std_ulogic; -- global clock line
50
    rstn_i     : in  std_ulogic; -- global reset, low-active, async
51
    addr_i     : in  std_ulogic_vector(31 downto 0); -- address
52
    rden_i     : in  std_ulogic; -- read enable
53
    wren_i     : in  std_ulogic; -- write enable
54 70 zero_gravi
    data_i     : in  std_ulogic_vector(31 downto 0); -- data in
55 66 zero_gravi
    data_o     : out std_ulogic_vector(31 downto 0); -- data out
56
    ack_o      : out std_ulogic; -- transfer acknowledge
57
    err_o      : out std_ulogic; -- transfer error
58
    -- bus monitoring --
59
    bus_addr_i : in  std_ulogic_vector(31 downto 0); -- address
60
    bus_rden_i : in  std_ulogic; -- read enable
61
    bus_wren_i : in  std_ulogic; -- write enable
62
    bus_ack_i  : in  std_ulogic; -- transfer acknowledge from bus system
63 68 zero_gravi
    bus_err_i  : in  std_ulogic; -- transfer error from bus system
64
    bus_tmo_i  : in  std_ulogic; -- transfer timeout (external interface)
65 70 zero_gravi
    bus_ext_i  : in  std_ulogic; -- external bus access
66
    bus_xip_i  : in  std_ulogic  -- pending XIP access
67 57 zero_gravi
  );
68
end neorv32_bus_keeper;
69
 
70
architecture neorv32_bus_keeper_rtl of neorv32_bus_keeper is
71
 
72 66 zero_gravi
  -- IO space: module base address --
73
  constant hi_abb_c : natural := index_size_f(io_size_c)-1; -- high address boundary bit
74
  constant lo_abb_c : natural := index_size_f(buskeeper_size_c); -- low address boundary bit
75
 
76
  -- Control register --
77 70 zero_gravi
  constant ctrl_err_type_c     : natural :=  0; -- r/-: error type LSB: 0=device error, 1=access timeout
78
  constant ctrl_nul_check_en_c : natural := 16; -- r/w: enable NULL address check
79
  constant ctrl_err_flag_c     : natural := 31; -- r/c: bus error encountered, sticky; cleared by writing zero
80
  --
81
  signal ctrl_null_check_en : std_ulogic;
82 66 zero_gravi
 
83 70 zero_gravi
  -- error codes --
84
  constant err_device_c  : std_ulogic := '0'; -- device access error
85
  constant err_timeout_c : std_ulogic := '1'; -- timeout error
86
 
87 68 zero_gravi
  -- sticky error flags --
88 66 zero_gravi
  signal err_flag : std_ulogic;
89 68 zero_gravi
  signal err_type : std_ulogic;
90 66 zero_gravi
 
91 70 zero_gravi
  -- NULL address check --
92
  signal null_check : std_ulogic;
93
 
94 66 zero_gravi
  -- access control --
95
  signal acc_en : std_ulogic; -- module access enable
96
  signal wren   : std_ulogic; -- word write enable
97
  signal rden   : std_ulogic; -- read enable
98
 
99 57 zero_gravi
  -- controller --
100
  type control_t is record
101 66 zero_gravi
    pending  : std_ulogic;
102 69 zero_gravi
    timeout  : std_ulogic_vector(index_size_f(max_proc_int_response_time_c) downto 0);
103 66 zero_gravi
    err_type : std_ulogic;
104
    bus_err  : std_ulogic;
105 57 zero_gravi
  end record;
106
  signal control : control_t;
107
 
108
begin
109
 
110
  -- Sanity Check --------------------------------------------------------------------------
111
  -- -------------------------------------------------------------------------------------------
112
  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;
113
 
114
 
115
  -- Access Control -------------------------------------------------------------------------
116
  -- -------------------------------------------------------------------------------------------
117 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';
118
  wren   <= acc_en and wren_i;
119
  rden   <= acc_en and rden_i;
120
 
121
 
122
  -- Read/Write Access ----------------------------------------------------------------------
123
  -- -------------------------------------------------------------------------------------------
124 70 zero_gravi
  rw_access: process(rstn_i, clk_i)
125 66 zero_gravi
  begin
126 70 zero_gravi
    if (rstn_i = '0') then
127
      ack_o              <= '-';
128
      data_o             <= (others => '-');
129
      ctrl_null_check_en <= '0'; -- required
130
      err_flag           <= '0'; -- required
131
      err_type           <= '0';
132
    elsif rising_edge(clk_i) then
133 66 zero_gravi
      -- bus handshake --
134
      ack_o <= wren or rden;
135
 
136 70 zero_gravi
      -- write access --
137
      if (wren = '1') then
138
        ctrl_null_check_en <= data_i(ctrl_nul_check_en_c);
139
      end if;
140
 
141 66 zero_gravi
      -- read access --
142
      data_o <= (others => '0');
143
      if (rden = '1') then
144 70 zero_gravi
        data_o(ctrl_err_type_c)     <= err_type;
145
        data_o(ctrl_nul_check_en_c) <= ctrl_null_check_en;
146
        data_o(ctrl_err_flag_c)     <= err_flag;
147 66 zero_gravi
      end if;
148
      --
149 68 zero_gravi
      if (control.bus_err = '1') then -- sticky error flag
150
        err_flag <= '1';
151
        err_type <= control.err_type;
152 70 zero_gravi
      else
153
        if ((wren or rden) = '1') then -- clear on read or write access
154
          err_flag <= '0';
155
        end if;
156 66 zero_gravi
      end if;
157
    end if;
158
  end process rw_access;
159
 
160
 
161 57 zero_gravi
  -- Keeper ---------------------------------------------------------------------------------
162
  -- -------------------------------------------------------------------------------------------
163
  keeper_control: process(rstn_i, clk_i)
164
  begin
165
    if (rstn_i = '0') then
166 70 zero_gravi
      control.pending  <= '0'; -- required
167
      control.bus_err  <= '0'; -- required
168
      control.err_type <= '-';
169
      control.timeout  <= (others => '-');
170 66 zero_gravi
    elsif rising_edge(clk_i) then
171
      -- defaults --
172 57 zero_gravi
      control.bus_err <= '0';
173
 
174 66 zero_gravi
      -- access monitor: IDLE --
175
      if (control.pending = '0') then
176 69 zero_gravi
        control.timeout <= std_ulogic_vector(to_unsigned(max_proc_int_response_time_c, index_size_f(max_proc_int_response_time_c)+1));
177 66 zero_gravi
        if (bus_rden_i = '1') or (bus_wren_i = '1') then
178 57 zero_gravi
          control.pending <= '1';
179 70 zero_gravi
          if (null_check = '1') then -- invalid access to NULL address
180
            control.bus_err <= '1';
181
          end if;
182 57 zero_gravi
        end if;
183 66 zero_gravi
      -- access monitor: PENDING --
184 57 zero_gravi
      else
185
        control.timeout <= std_ulogic_vector(unsigned(control.timeout) - 1); -- countdown timer
186 70 zero_gravi
        if (bus_err_i = '1') or (control.bus_err = '1') then -- error termination by bus system
187
          control.err_type <= err_device_c; -- device error
188 66 zero_gravi
          control.bus_err  <= '1';
189
          control.pending  <= '0';
190 70 zero_gravi
        elsif ((or_reduce_f(control.timeout) = '0') and (bus_ext_i = '0') and (bus_xip_i = '0')) or -- valid internal access timeout
191 68 zero_gravi
              (bus_tmo_i = '1') then -- external access timeout
192 70 zero_gravi
          control.err_type <= err_timeout_c; -- timeout error
193 66 zero_gravi
          control.bus_err  <= '1';
194
          control.pending  <= '0';
195 68 zero_gravi
        elsif (bus_ack_i = '1') then -- normal termination by bus system
196
          control.err_type <= '0'; -- don't care
197
          control.bus_err  <= '0';
198
          control.pending  <= '0';
199 66 zero_gravi
        end if;
200 57 zero_gravi
      end if;
201
    end if;
202
  end process keeper_control;
203
 
204 70 zero_gravi
  -- NULL address check --
205
  null_check <= '1' when (ctrl_null_check_en = '1') and (or_reduce_f(addr_i) = '0') else '0';
206
 
207 68 zero_gravi
  -- signal bus error to CPU --
208
  err_o <= control.bus_err;
209 57 zero_gravi
 
210 68 zero_gravi
 
211 57 zero_gravi
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.