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 |
73 |
zero_gravi |
constant ctrl_err_type_c : natural := 0; -- r/-: error type LSB: 0=device error, 1=access timeout
|
78 |
|
|
constant ctrl_err_flag_c : natural := 31; -- r/c: bus error encountered, sticky; cleared by writing zero
|
79 |
66 |
zero_gravi |
|
80 |
70 |
zero_gravi |
-- error codes --
|
81 |
|
|
constant err_device_c : std_ulogic := '0'; -- device access error
|
82 |
|
|
constant err_timeout_c : std_ulogic := '1'; -- timeout error
|
83 |
|
|
|
84 |
68 |
zero_gravi |
-- sticky error flags --
|
85 |
66 |
zero_gravi |
signal err_flag : std_ulogic;
|
86 |
68 |
zero_gravi |
signal err_type : std_ulogic;
|
87 |
66 |
zero_gravi |
|
88 |
|
|
-- access control --
|
89 |
|
|
signal acc_en : std_ulogic; -- module access enable
|
90 |
|
|
signal wren : std_ulogic; -- word write enable
|
91 |
|
|
signal rden : std_ulogic; -- read enable
|
92 |
|
|
|
93 |
57 |
zero_gravi |
-- controller --
|
94 |
|
|
type control_t is record
|
95 |
66 |
zero_gravi |
pending : std_ulogic;
|
96 |
69 |
zero_gravi |
timeout : std_ulogic_vector(index_size_f(max_proc_int_response_time_c) downto 0);
|
97 |
66 |
zero_gravi |
err_type : std_ulogic;
|
98 |
|
|
bus_err : std_ulogic;
|
99 |
57 |
zero_gravi |
end record;
|
100 |
|
|
signal control : control_t;
|
101 |
|
|
|
102 |
|
|
begin
|
103 |
|
|
|
104 |
|
|
-- Sanity Check --------------------------------------------------------------------------
|
105 |
|
|
-- -------------------------------------------------------------------------------------------
|
106 |
|
|
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;
|
107 |
|
|
|
108 |
|
|
|
109 |
|
|
-- Access Control -------------------------------------------------------------------------
|
110 |
|
|
-- -------------------------------------------------------------------------------------------
|
111 |
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';
|
112 |
|
|
wren <= acc_en and wren_i;
|
113 |
|
|
rden <= acc_en and rden_i;
|
114 |
|
|
|
115 |
|
|
|
116 |
|
|
-- Read/Write Access ----------------------------------------------------------------------
|
117 |
|
|
-- -------------------------------------------------------------------------------------------
|
118 |
70 |
zero_gravi |
rw_access: process(rstn_i, clk_i)
|
119 |
66 |
zero_gravi |
begin
|
120 |
70 |
zero_gravi |
if (rstn_i = '0') then
|
121 |
73 |
zero_gravi |
ack_o <= '-';
|
122 |
|
|
data_o <= (others => '-');
|
123 |
|
|
err_flag <= '0'; -- required
|
124 |
|
|
err_type <= '0';
|
125 |
70 |
zero_gravi |
elsif rising_edge(clk_i) then
|
126 |
66 |
zero_gravi |
-- bus handshake --
|
127 |
|
|
ack_o <= wren or rden;
|
128 |
|
|
|
129 |
|
|
-- read access --
|
130 |
|
|
data_o <= (others => '0');
|
131 |
|
|
if (rden = '1') then
|
132 |
73 |
zero_gravi |
data_o(ctrl_err_type_c) <= err_type;
|
133 |
|
|
data_o(ctrl_err_flag_c) <= err_flag;
|
134 |
66 |
zero_gravi |
end if;
|
135 |
|
|
--
|
136 |
68 |
zero_gravi |
if (control.bus_err = '1') then -- sticky error flag
|
137 |
|
|
err_flag <= '1';
|
138 |
|
|
err_type <= control.err_type;
|
139 |
70 |
zero_gravi |
else
|
140 |
|
|
if ((wren or rden) = '1') then -- clear on read or write access
|
141 |
|
|
err_flag <= '0';
|
142 |
|
|
end if;
|
143 |
66 |
zero_gravi |
end if;
|
144 |
|
|
end if;
|
145 |
|
|
end process rw_access;
|
146 |
|
|
|
147 |
|
|
|
148 |
57 |
zero_gravi |
-- Keeper ---------------------------------------------------------------------------------
|
149 |
|
|
-- -------------------------------------------------------------------------------------------
|
150 |
|
|
keeper_control: process(rstn_i, clk_i)
|
151 |
|
|
begin
|
152 |
|
|
if (rstn_i = '0') then
|
153 |
70 |
zero_gravi |
control.pending <= '0'; -- required
|
154 |
|
|
control.bus_err <= '0'; -- required
|
155 |
|
|
control.err_type <= '-';
|
156 |
|
|
control.timeout <= (others => '-');
|
157 |
66 |
zero_gravi |
elsif rising_edge(clk_i) then
|
158 |
|
|
-- defaults --
|
159 |
57 |
zero_gravi |
control.bus_err <= '0';
|
160 |
|
|
|
161 |
66 |
zero_gravi |
-- access monitor: IDLE --
|
162 |
|
|
if (control.pending = '0') then
|
163 |
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));
|
164 |
66 |
zero_gravi |
if (bus_rden_i = '1') or (bus_wren_i = '1') then
|
165 |
57 |
zero_gravi |
control.pending <= '1';
|
166 |
|
|
end if;
|
167 |
66 |
zero_gravi |
-- access monitor: PENDING --
|
168 |
57 |
zero_gravi |
else
|
169 |
|
|
control.timeout <= std_ulogic_vector(unsigned(control.timeout) - 1); -- countdown timer
|
170 |
73 |
zero_gravi |
if (bus_err_i = '1') then -- error termination by bus system
|
171 |
70 |
zero_gravi |
control.err_type <= err_device_c; -- device error
|
172 |
66 |
zero_gravi |
control.bus_err <= '1';
|
173 |
|
|
control.pending <= '0';
|
174 |
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
|
175 |
68 |
zero_gravi |
(bus_tmo_i = '1') then -- external access timeout
|
176 |
70 |
zero_gravi |
control.err_type <= err_timeout_c; -- timeout error
|
177 |
66 |
zero_gravi |
control.bus_err <= '1';
|
178 |
|
|
control.pending <= '0';
|
179 |
68 |
zero_gravi |
elsif (bus_ack_i = '1') then -- normal termination by bus system
|
180 |
|
|
control.err_type <= '0'; -- don't care
|
181 |
|
|
control.bus_err <= '0';
|
182 |
|
|
control.pending <= '0';
|
183 |
66 |
zero_gravi |
end if;
|
184 |
57 |
zero_gravi |
end if;
|
185 |
|
|
end if;
|
186 |
|
|
end process keeper_control;
|
187 |
|
|
|
188 |
68 |
zero_gravi |
-- signal bus error to CPU --
|
189 |
|
|
err_o <= control.bus_err;
|
190 |
57 |
zero_gravi |
|
191 |
68 |
zero_gravi |
|
192 |
57 |
zero_gravi |
end neorv32_bus_keeper_rtl;
|