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

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [rtl/] [core/] [mem/] [neorv32_dmem.legacy.vhd] - Blame information for rev 70

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 70 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
  signal addr_ff : std_ulogic_vector(index_size_f(DMEM_SIZE/4)-1 downto 0);
54
 
55
  -- -------------------------------------------------------------------------------------------------------------- --
56
  -- The memory (RAM) is built from 4 individual byte-wide memories b0..b3, since some synthesis tools have         --
57
  -- problems with 32-bit memories that provide dedicated byte-enable signals AND/OR with multi-dimensional arrays. --
58
  -- -------------------------------------------------------------------------------------------------------------- --
59
 
60
  -- RAM - not initialized at all --
61
  signal mem_ram_b0 : mem8_t(0 to DMEM_SIZE/4-1);
62
  signal mem_ram_b1 : mem8_t(0 to DMEM_SIZE/4-1);
63
  signal mem_ram_b2 : mem8_t(0 to DMEM_SIZE/4-1);
64
  signal mem_ram_b3 : mem8_t(0 to DMEM_SIZE/4-1);
65
 
66
  -- read data --
67
  signal mem_ram_b0_rd, mem_ram_b1_rd, mem_ram_b2_rd, mem_ram_b3_rd : std_ulogic_vector(7 downto 0);
68
 
69
begin
70
 
71
  -- Sanity Checks --------------------------------------------------------------------------
72
  -- -------------------------------------------------------------------------------------------
73
  assert false report "NEORV32 PROCESSOR CONFIG NOTE: Using legacy HDL style DMEM." severity note;
74
  assert false report "NEORV32 PROCESSOR CONFIG NOTE: Implementing processor-internal DMEM (RAM, " & natural'image(DMEM_SIZE) & " bytes)." severity note;
75
 
76
 
77
  -- Access Control -------------------------------------------------------------------------
78
  -- -------------------------------------------------------------------------------------------
79
  acc_en <= '1' when (addr_i(hi_abb_c downto lo_abb_c) = DMEM_BASE(hi_abb_c downto lo_abb_c)) else '0';
80
  addr   <= addr_i(index_size_f(DMEM_SIZE/4)+1 downto 2); -- word aligned
81
 
82
 
83
  -- Memory Access --------------------------------------------------------------------------
84
  -- -------------------------------------------------------------------------------------------
85
  mem_access: process(clk_i)
86
  begin
87
    if rising_edge(clk_i) then
88
      addr_ff <= addr;
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
        end if;
93
        if (wren_i = '1') and (ben_i(1) = '1') then -- byte 1
94
          mem_ram_b1(to_integer(unsigned(addr))) <= data_i(15 downto 08);
95
        end if;
96
        if (wren_i = '1') and (ben_i(2) = '1') then -- byte 2
97
          mem_ram_b2(to_integer(unsigned(addr))) <= data_i(23 downto 16);
98
        end if;
99
        if (wren_i = '1') and (ben_i(3) = '1') then -- byte 3
100
          mem_ram_b3(to_integer(unsigned(addr))) <= data_i(31 downto 24);
101
        end if;
102
      end if;
103
    end if;
104
  end process mem_access;
105
 
106
  -- sync(!) read - alternative HDL style --
107
  mem_ram_b0_rd <= mem_ram_b0(to_integer(unsigned(addr_ff)));
108
  mem_ram_b1_rd <= mem_ram_b1(to_integer(unsigned(addr_ff)));
109
  mem_ram_b2_rd <= mem_ram_b2(to_integer(unsigned(addr_ff)));
110
  mem_ram_b3_rd <= mem_ram_b3(to_integer(unsigned(addr_ff)));
111
 
112
 
113
  -- Bus Feedback ---------------------------------------------------------------------------
114
  -- -------------------------------------------------------------------------------------------
115
  bus_feedback: process(clk_i)
116
  begin
117
    if rising_edge(clk_i) then
118
      rden  <= acc_en and rden_i;
119
      ack_o <= acc_en and (rden_i or wren_i);
120
    end if;
121
  end process bus_feedback;
122
 
123
  -- pack --
124
  rdata <= mem_ram_b3_rd & mem_ram_b2_rd & mem_ram_b1_rd & mem_ram_b0_rd;
125
 
126
  -- output gate --
127
  data_o <= rdata when (rden = '1') else (others => '0');
128
 
129
 
130
end neorv32_dmem_rtl;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.