1 |
64 |
zero_gravi |
-- #################################################################################################
|
2 |
|
|
-- # << NEORV32 - Processor-internal data memory (DMEM) >> #
|
3 |
|
|
-- # ********************************************************************************************* #
|
4 |
|
|
-- # BSD 3-Clause License #
|
5 |
|
|
-- # #
|
6 |
|
|
-- # Copyright (c) 2021, Stephan Nolting. All rights reserved. #
|
7 |
|
|
-- # #
|
8 |
|
|
-- # Redistribution and use in source and binary forms, with or without modification, are #
|
9 |
|
|
-- # permitted provided that the following conditions are met: #
|
10 |
|
|
-- # #
|
11 |
|
|
-- # 1. Redistributions of source code must retain the above copyright notice, this list of #
|
12 |
|
|
-- # conditions and the following disclaimer. #
|
13 |
|
|
-- # #
|
14 |
|
|
-- # 2. Redistributions in binary form must reproduce the above copyright notice, this list of #
|
15 |
|
|
-- # conditions and the following disclaimer in the documentation and/or other materials #
|
16 |
|
|
-- # provided with the distribution. #
|
17 |
|
|
-- # #
|
18 |
|
|
-- # 3. Neither the name of the copyright holder nor the names of its contributors may be used to #
|
19 |
|
|
-- # endorse or promote products derived from this software without specific prior written #
|
20 |
|
|
-- # permission. #
|
21 |
|
|
-- # #
|
22 |
|
|
-- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS #
|
23 |
|
|
-- # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF #
|
24 |
|
|
-- # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE #
|
25 |
|
|
-- # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, #
|
26 |
|
|
-- # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE #
|
27 |
|
|
-- # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED #
|
28 |
|
|
-- # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING #
|
29 |
|
|
-- # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED #
|
30 |
|
|
-- # OF THE POSSIBILITY OF SUCH DAMAGE. #
|
31 |
|
|
-- # ********************************************************************************************* #
|
32 |
|
|
-- # The NEORV32 Processor - https://github.com/stnolting/neorv32 (c) Stephan Nolting #
|
33 |
|
|
-- #################################################################################################
|
34 |
|
|
|
35 |
|
|
library ieee;
|
36 |
|
|
use ieee.std_logic_1164.all;
|
37 |
|
|
use ieee.numeric_std.all;
|
38 |
|
|
|
39 |
|
|
library neorv32;
|
40 |
|
|
use neorv32.neorv32_package.all;
|
41 |
|
|
|
42 |
|
|
architecture neorv32_dmem_rtl of neorv32_dmem is
|
43 |
|
|
|
44 |
|
|
-- IO space: module base address --
|
45 |
|
|
constant hi_abb_c : natural := 31; -- high address boundary bit
|
46 |
|
|
constant lo_abb_c : natural := index_size_f(DMEM_SIZE); -- low address boundary bit
|
47 |
|
|
|
48 |
|
|
-- local signals --
|
49 |
|
|
signal acc_en : std_ulogic;
|
50 |
|
|
signal rdata : std_ulogic_vector(31 downto 0);
|
51 |
|
|
signal rden : std_ulogic;
|
52 |
|
|
signal addr : std_ulogic_vector(index_size_f(DMEM_SIZE/4)-1 downto 0);
|
53 |
|
|
|
54 |
|
|
-- -------------------------------------------------------------------------------------------------------------- --
|
55 |
|
|
-- The memory (RAM) is built from 4 individual byte-wide memories b0..b3, since some synthesis tools have --
|
56 |
|
|
-- problems with 32-bit memories that provide dedicated byte-enable signals AND/OR with multi-dimensional arrays. --
|
57 |
|
|
-- -------------------------------------------------------------------------------------------------------------- --
|
58 |
|
|
|
59 |
|
|
-- RAM - not initialized at all --
|
60 |
|
|
signal mem_ram_b0 : mem8_t(0 to DMEM_SIZE/4-1);
|
61 |
|
|
signal mem_ram_b1 : mem8_t(0 to DMEM_SIZE/4-1);
|
62 |
|
|
signal mem_ram_b2 : mem8_t(0 to DMEM_SIZE/4-1);
|
63 |
|
|
signal mem_ram_b3 : mem8_t(0 to DMEM_SIZE/4-1);
|
64 |
|
|
|
65 |
|
|
-- read data --
|
66 |
|
|
signal mem_ram_b0_rd, mem_ram_b1_rd, mem_ram_b2_rd, mem_ram_b3_rd : std_ulogic_vector(7 downto 0);
|
67 |
|
|
|
68 |
|
|
begin
|
69 |
|
|
|
70 |
|
|
-- Sanity Checks --------------------------------------------------------------------------
|
71 |
|
|
-- -------------------------------------------------------------------------------------------
|
72 |
68 |
zero_gravi |
assert false report "NEORV32 PROCESSOR CONFIG NOTE: Using DEFAULT platform-agnostic DMEM." severity note;
|
73 |
64 |
zero_gravi |
assert false report "NEORV32 PROCESSOR CONFIG NOTE: Implementing processor-internal DMEM (RAM, " & natural'image(DMEM_SIZE) & " bytes)." severity note;
|
74 |
|
|
|
75 |
|
|
|
76 |
|
|
-- Access Control -------------------------------------------------------------------------
|
77 |
|
|
-- -------------------------------------------------------------------------------------------
|
78 |
|
|
acc_en <= '1' when (addr_i(hi_abb_c downto lo_abb_c) = DMEM_BASE(hi_abb_c downto lo_abb_c)) else '0';
|
79 |
|
|
addr <= addr_i(index_size_f(DMEM_SIZE/4)+1 downto 2); -- word aligned
|
80 |
|
|
|
81 |
|
|
|
82 |
|
|
-- Memory Access --------------------------------------------------------------------------
|
83 |
|
|
-- -------------------------------------------------------------------------------------------
|
84 |
|
|
mem_access: process(clk_i)
|
85 |
|
|
begin
|
86 |
|
|
if rising_edge(clk_i) then
|
87 |
|
|
-- this RAM style should not require "no_rw_check" attributes as the read-after-write behavior
|
88 |
|
|
-- is intended to be defined implicitly via the if-WRITE-else-READ construct
|
89 |
|
|
if (acc_en = '1') then -- reduce switching activity when not accessed
|
90 |
|
|
if (wren_i = '1') and (ben_i(0) = '1') then -- byte 0
|
91 |
|
|
mem_ram_b0(to_integer(unsigned(addr))) <= data_i(07 downto 00);
|
92 |
|
|
else
|
93 |
|
|
mem_ram_b0_rd <= mem_ram_b0(to_integer(unsigned(addr)));
|
94 |
|
|
end if;
|
95 |
|
|
if (wren_i = '1') and (ben_i(1) = '1') then -- byte 1
|
96 |
|
|
mem_ram_b1(to_integer(unsigned(addr))) <= data_i(15 downto 08);
|
97 |
|
|
else
|
98 |
|
|
mem_ram_b1_rd <= mem_ram_b1(to_integer(unsigned(addr)));
|
99 |
|
|
end if;
|
100 |
|
|
if (wren_i = '1') and (ben_i(2) = '1') then -- byte 2
|
101 |
|
|
mem_ram_b2(to_integer(unsigned(addr))) <= data_i(23 downto 16);
|
102 |
|
|
else
|
103 |
|
|
mem_ram_b2_rd <= mem_ram_b2(to_integer(unsigned(addr)));
|
104 |
|
|
end if;
|
105 |
|
|
if (wren_i = '1') and (ben_i(3) = '1') then -- byte 3
|
106 |
|
|
mem_ram_b3(to_integer(unsigned(addr))) <= data_i(31 downto 24);
|
107 |
|
|
else
|
108 |
|
|
mem_ram_b3_rd <= mem_ram_b3(to_integer(unsigned(addr)));
|
109 |
|
|
end if;
|
110 |
|
|
end if;
|
111 |
|
|
end if;
|
112 |
|
|
end process mem_access;
|
113 |
|
|
|
114 |
|
|
|
115 |
|
|
-- Bus Feedback ---------------------------------------------------------------------------
|
116 |
|
|
-- -------------------------------------------------------------------------------------------
|
117 |
|
|
bus_feedback: process(clk_i)
|
118 |
|
|
begin
|
119 |
|
|
if rising_edge(clk_i) then
|
120 |
|
|
rden <= acc_en and rden_i;
|
121 |
|
|
ack_o <= acc_en and (rden_i or wren_i);
|
122 |
|
|
end if;
|
123 |
|
|
end process bus_feedback;
|
124 |
|
|
|
125 |
|
|
-- pack --
|
126 |
|
|
rdata <= mem_ram_b3_rd & mem_ram_b2_rd & mem_ram_b1_rd & mem_ram_b0_rd;
|
127 |
|
|
|
128 |
|
|
-- output gate --
|
129 |
|
|
data_o <= rdata when (rden = '1') else (others => '0');
|
130 |
|
|
|
131 |
|
|
|
132 |
|
|
end neorv32_dmem_rtl;
|