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

Subversion Repositories neorv32

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

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
-- # the defined number of  cycles (VHDL package: max_proc_int_response_time_c) or issues an ERROR #
6
-- # conditions the BUS KEEPER asserts the error signal to inform the CPU.                         #
7 57 zero_gravi
-- # ********************************************************************************************* #
8
-- # BSD 3-Clause License                                                                          #
9
-- #                                                                                               #
10
-- # Copyright (c) 2021, Stephan Nolting. All rights reserved.                                     #
11
-- #                                                                                               #
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
    data_o     : out std_ulogic_vector(31 downto 0); -- data out
55
    ack_o      : out std_ulogic; -- transfer acknowledge
56
    err_o      : out std_ulogic; -- transfer error
57
    -- bus monitoring --
58
    bus_addr_i : in  std_ulogic_vector(31 downto 0); -- address
59
    bus_rden_i : in  std_ulogic; -- read enable
60
    bus_wren_i : in  std_ulogic; -- write enable
61
    bus_ack_i  : in  std_ulogic; -- transfer acknowledge from bus system
62 68 zero_gravi
    bus_err_i  : in  std_ulogic; -- transfer error from bus system
63
    bus_tmo_i  : in  std_ulogic; -- transfer timeout (external interface)
64
    bus_ext_i  : in  std_ulogic  -- external bus access
65 57 zero_gravi
  );
66
end neorv32_bus_keeper;
67
 
68
architecture neorv32_bus_keeper_rtl of neorv32_bus_keeper is
69
 
70 66 zero_gravi
  -- IO space: module base address --
71
  constant hi_abb_c : natural := index_size_f(io_size_c)-1; -- high address boundary bit
72
  constant lo_abb_c : natural := index_size_f(buskeeper_size_c); -- low address boundary bit
73
 
74
  -- Control register --
75
  constant ctrl_err_type_c : natural :=  0; -- r/-: error type: 0=device error, 1=access timeout
76
  constant ctrl_err_flag_c : natural := 31; -- r/c: bus error encountered, sticky; cleared by writing zero
77
 
78 68 zero_gravi
  -- sticky error flags --
79 66 zero_gravi
  signal err_flag : std_ulogic;
80 68 zero_gravi
  signal err_type : std_ulogic;
81 66 zero_gravi
 
82
  -- access control --
83
  signal acc_en : std_ulogic; -- module access enable
84
  signal wren   : std_ulogic; -- word write enable
85
  signal rden   : std_ulogic; -- read enable
86
 
87 57 zero_gravi
  -- controller --
88
  type control_t is record
89 66 zero_gravi
    pending  : std_ulogic;
90
    timeout  : std_ulogic_vector(index_size_f(max_proc_int_response_time_c)-1 downto 0);
91
    err_type : std_ulogic;
92
    bus_err  : std_ulogic;
93 57 zero_gravi
  end record;
94
  signal control : control_t;
95
 
96
begin
97
 
98
  -- Sanity Check --------------------------------------------------------------------------
99
  -- -------------------------------------------------------------------------------------------
100
  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;
101
 
102
 
103
  -- Access Control -------------------------------------------------------------------------
104
  -- -------------------------------------------------------------------------------------------
105 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';
106
  wren   <= acc_en and wren_i;
107
  rden   <= acc_en and rden_i;
108
 
109
 
110
  -- Read/Write Access ----------------------------------------------------------------------
111
  -- -------------------------------------------------------------------------------------------
112
  rw_access: process(clk_i)
113
  begin
114
    if rising_edge(clk_i) then
115
      -- bus handshake --
116
      ack_o <= wren or rden;
117
 
118
      -- read access --
119
      data_o <= (others => '0');
120
      if (rden = '1') then
121 68 zero_gravi
        data_o(ctrl_err_type_c) <= err_type;
122 66 zero_gravi
        data_o(ctrl_err_flag_c) <= err_flag;
123
      end if;
124
      --
125 68 zero_gravi
      if (control.bus_err = '1') then -- sticky error flag
126
        err_flag <= '1';
127
        err_type <= control.err_type;
128
      elsif ((wren or rden) = '1') then -- clear on or read or write
129 66 zero_gravi
        err_flag <= '0';
130 68 zero_gravi
        err_type <= '0';
131 66 zero_gravi
      end if;
132
    end if;
133
  end process rw_access;
134
 
135
 
136 57 zero_gravi
  -- Keeper ---------------------------------------------------------------------------------
137
  -- -------------------------------------------------------------------------------------------
138
  keeper_control: process(rstn_i, clk_i)
139
  begin
140
    if (rstn_i = '0') then
141 66 zero_gravi
      control.pending  <= '0';
142
      control.bus_err  <= '0';
143
      control.err_type <= def_rst_val_c;
144
      control.timeout  <= (others => def_rst_val_c);
145
    elsif rising_edge(clk_i) then
146
      -- defaults --
147 57 zero_gravi
      control.bus_err <= '0';
148
 
149 66 zero_gravi
      -- access monitor: IDLE --
150
      if (control.pending = '0') then
151
        control.timeout <= std_ulogic_vector(to_unsigned(max_proc_int_response_time_c, index_size_f(max_proc_int_response_time_c)));
152
        if (bus_rden_i = '1') or (bus_wren_i = '1') then
153 57 zero_gravi
          control.pending <= '1';
154
        end if;
155 66 zero_gravi
      -- access monitor: PENDING --
156 57 zero_gravi
      else
157
        control.timeout <= std_ulogic_vector(unsigned(control.timeout) - 1); -- countdown timer
158 68 zero_gravi
        if (bus_err_i = '1') then -- error termination by bus system
159 66 zero_gravi
          control.err_type <= '0'; -- device error
160
          control.bus_err  <= '1';
161
          control.pending  <= '0';
162 68 zero_gravi
        elsif ((or_reduce_f(control.timeout) = '0') and (bus_ext_i = '0')) or -- internal access timeout
163
              (bus_tmo_i = '1') then -- external access timeout
164 66 zero_gravi
          control.err_type <= '1'; -- timeout error
165
          control.bus_err  <= '1';
166
          control.pending  <= '0';
167 68 zero_gravi
        elsif (bus_ack_i = '1') then -- normal termination by bus system
168
          control.err_type <= '0'; -- don't care
169
          control.bus_err  <= '0';
170
          control.pending  <= '0';
171 66 zero_gravi
        end if;
172 57 zero_gravi
      end if;
173
    end if;
174
  end process keeper_control;
175
 
176 68 zero_gravi
  -- signal bus error to CPU --
177
  err_o <= control.bus_err;
178 57 zero_gravi
 
179 68 zero_gravi
 
180 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.