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

Subversion Repositories neo430

[/] [neo430/] [trunk/] [neo430/] [rtl/] [core/] [neo430_dmem.vhd] - Blame information for rev 198

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 198 zero_gravi
-- #################################################################################################
2
-- #  << NEO430 - Data memory ("DMEM") >>                                                          #
3
-- # ********************************************************************************************* #
4
-- # BSD 3-Clause License                                                                          #
5
-- #                                                                                               #
6
-- # Copyright (c) 2020, 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 NEO430 Processor - https://github.com/stnolting/neo430                                    #
33
-- #################################################################################################
34
 
35
library ieee;
36
use ieee.std_logic_1164.all;
37
use ieee.numeric_std.all;
38
 
39
library neo430;
40
use neo430.neo430_package.all;
41
 
42
entity neo430_dmem is
43
  generic (
44
    DMEM_SIZE : natural := 2*1024 -- internal DMEM size in bytes
45
  );
46
  port (
47
    clk_i  : in  std_ulogic; -- global clock line
48
    rden_i : in  std_ulogic; -- read enable
49
    wren_i : in  std_ulogic_vector(01 downto 0); -- write enable
50
    addr_i : in  std_ulogic_vector(15 downto 0); -- address
51
    data_i : in  std_ulogic_vector(15 downto 0); -- data in
52
    data_o : out std_ulogic_vector(15 downto 0)  -- data out
53
  );
54
end neo430_dmem;
55
 
56
architecture neo430_dmem_rtl of neo430_dmem is
57
 
58
  -- local signals --
59
  signal acc_en : std_ulogic;
60
  signal rdata  : std_ulogic_vector(15 downto 0);
61
  signal rden   : std_ulogic;
62
  signal addr   : integer;
63
 
64
  -- RAM --
65
  type dmem_file_t is array (0 to DMEM_SIZE/2-1) of std_ulogic_vector(7 downto 0);
66
  signal dmem_file_l : dmem_file_t;
67
  signal dmem_file_h : dmem_file_t;
68
 
69
  -- RAM attribute to inhibit bypass-logic - Intel only! --
70
  attribute ramstyle : string;
71
  attribute ramstyle of dmem_file_l : signal is "no_rw_check";
72
  attribute ramstyle of dmem_file_h : signal is "no_rw_check";
73
 
74
  -- RAM attribute to inhibit bypass-logic - Lattice ICE40up only! --
75
  attribute syn_ramstyle : string;
76
  attribute syn_ramstyle of dmem_file_l : signal is "no_rw_check";
77
  attribute syn_ramstyle of dmem_file_h : signal is "no_rw_check";
78
 
79
begin
80
 
81
  -- Access Control -----------------------------------------------------------
82
  -- -----------------------------------------------------------------------------
83
  acc_en <= '1' when (addr_i >= dmem_base_c) and (addr_i < std_ulogic_vector(unsigned(dmem_base_c) + DMEM_SIZE)) else '0';
84
  addr <= to_integer(unsigned(addr_i(index_size_f(DMEM_SIZE/2) downto 1))); -- word aligned
85
 
86
 
87
  -- Memory Access ------------------------------------------------------------
88
  -- -----------------------------------------------------------------------------
89
  dmem_file_access: process(clk_i)
90
  begin
91
    -- check max size --
92
    if (DMEM_SIZE > dmem_max_size_c) then
93
      assert false report "D-mem size out of range! Max 12kB!" severity error;
94
    end if;
95
    if rising_edge(clk_i) then
96
      rden <= rden_i and acc_en;
97
      if (acc_en = '1') then -- reduce switching activity when not accessed
98
        if (wren_i(0) = '1') then -- write low byte
99
          dmem_file_l(addr) <= data_i(07 downto 0);
100
        end if;
101
        rdata(07 downto 0) <= dmem_file_l(addr);
102
        if (wren_i(1) = '1') then -- write high byte
103
          dmem_file_h(addr) <= data_i(15 downto 8);
104
        end if;
105
        rdata(15 downto 8) <= dmem_file_h(addr);
106
      end if;
107
    end if;
108
  end process dmem_file_access;
109
 
110
  -- output gate --
111
  data_o <= rdata when (rden = '1') else (others => '0');
112
 
113
 
114
end neo430_dmem_rtl;

powered by: WebSVN 2.1.0

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