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

Subversion Repositories neo430

[/] [neo430/] [trunk/] [neo430/] [rtl/] [fpga_specific/] [lattice_ice40up/] [neo430_imem.ice40up_spram.vhd] - Blame information for rev 199

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 198 zero_gravi
-- #################################################################################################
2
-- #  << NEO430 - Instruction memory ("IMEM") for Lattice ice40 UltraPlus >>                       #
3
-- # ********************************************************************************************* #
4
-- # This memory includes the in-place executable image of the application. See the                #
5
-- # processor's documentary to get more information.                                              #
6
-- # Note: IMEM is split up into two 8-bit memories - some EDA tools have problems to synthesize   #
7
-- # a pre-initialized 16-bit memory with byte-enable signals.                                     #
8
-- # ********************************************************************************************* #
9
-- # BSD 3-Clause License                                                                          #
10
-- #                                                                                               #
11
-- # Copyright (c) 2020, Stephan Nolting. All rights reserved.                                     #
12
-- #                                                                                               #
13
-- # Redistribution and use in source and binary forms, with or without modification, are          #
14
-- # permitted provided that the following conditions are met:                                     #
15
-- #                                                                                               #
16
-- # 1. Redistributions of source code must retain the above copyright notice, this list of        #
17
-- #    conditions and the following disclaimer.                                                   #
18
-- #                                                                                               #
19
-- # 2. Redistributions in binary form must reproduce the above copyright notice, this list of     #
20
-- #    conditions and the following disclaimer in the documentation and/or other materials        #
21
-- #    provided with the distribution.                                                            #
22
-- #                                                                                               #
23
-- # 3. Neither the name of the copyright holder nor the names of its contributors may be used to  #
24
-- #    endorse or promote products derived from this software without specific prior written      #
25
-- #    permission.                                                                                #
26
-- #                                                                                               #
27
-- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS   #
28
-- # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF               #
29
-- # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE    #
30
-- # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,     #
31
-- # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE #
32
-- # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED    #
33
-- # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING     #
34
-- # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED  #
35
-- # OF THE POSSIBILITY OF SUCH DAMAGE.                                                            #
36
-- # ********************************************************************************************* #
37
-- # The NEO430 Processor - https://github.com/stnolting/neo430                                    #
38
-- #################################################################################################
39
 
40
library ieee;
41
use ieee.std_logic_1164.all;
42
use ieee.numeric_std.all;
43
 
44
library neo430;
45
use neo430.neo430_package.all;
46
use neo430.neo430_application_image.all; -- this file is generated by the image generator
47
 
48
library iCE40UP;
49
use iCE40UP.components.all;
50
 
51
entity neo430_imem is
52
  generic (
53
    IMEM_SIZE   : natural := 4*1024; -- internal IMEM size in bytes
54
    IMEM_AS_ROM : boolean := false;  -- implement IMEM as read-only memory?
55
    BOOTLD_USE  : boolean := true    -- implement and use bootloader?
56
  );
57
  port (
58
    clk_i  : in  std_ulogic; -- global clock line
59
    rden_i : in  std_ulogic; -- read enable
60
    wren_i : in  std_ulogic_vector(01 downto 0); -- write enable
61
    upen_i : in  std_ulogic; -- update enable
62
    addr_i : in  std_ulogic_vector(15 downto 0); -- address
63
    data_i : in  std_ulogic_vector(15 downto 0); -- data in
64
    data_o : out std_ulogic_vector(15 downto 0)  -- data out
65
  );
66
end neo430_imem;
67
 
68
architecture neo430_imem_rtl of neo430_imem is
69
 
70 199 zero_gravi
  -- advanced configuration ------------------------------------------------------------------------------------
71
  constant spram_sleep_mode_en_c : boolean := false; -- put IMEM into sleep mode when idle (for low power)
72
  -- -------------------------------------------------------------------------------------------------------
73
 
74 198 zero_gravi
  -- ROM types --
75
  type imem_file8_t is array (0 to IMEM_SIZE/2-1) of std_ulogic_vector(07 downto 0);
76
 
77
  -- init function and split 1x16-bit memory into 2x8-bit memories --
78
  impure function init_imem(hilo : std_ulogic; init : application_init_image_t) return imem_file8_t is
79
    variable mem_v : imem_file8_t;
80
  begin
81
    for i in 0 to IMEM_SIZE/2-1 loop
82
      if (hilo = '0') then -- low byte
83
        mem_v(i) := init(i)(07 downto 00);
84
      else -- high byte
85
        mem_v(i) := init(i)(15 downto 08);
86
      end if;
87
    end loop; -- i
88
    return mem_v;
89
  end function init_imem;
90
 
91
  -- local signals --
92 199 zero_gravi
  signal acc_en  : std_ulogic;
93
  signal mem_cs  : std_ulogic;
94
  signal rdata   : std_ulogic_vector(15 downto 0);
95
  signal rden    : std_ulogic;
96
  signal mem_sel : std_ulogic;
97
  signal addr    : integer;
98 198 zero_gravi
 
99
  -- internal "RAM" type - implemented if bootloader is used and IMEM is RAM and initialized with app code --
100
  signal imem_file_init_ram_l : imem_file8_t := init_imem('0', application_init_image);
101
  signal imem_file_init_ram_h : imem_file8_t := init_imem('1', application_init_image);
102
 
103
  -- internal "ROM" type - implemented if bootloader is NOT used; always initialize with app code --
104
  constant imem_file_rom_l : imem_file8_t := init_imem('0', application_init_image);
105
  constant imem_file_rom_h : imem_file8_t := init_imem('1', application_init_image);
106
 
107
  -- internal "RAM" type - implemented if bootloader is used and IMEM is RAM --
108
  signal imem_file_ram_l : imem_file8_t;
109
  signal imem_file_ram_h : imem_file8_t;
110
 
111
  -- RAM attribute to inhibit bypass-logic - Intel only! --
112
  attribute ramstyle : string;
113
  attribute ramstyle of imem_file_init_ram_l : signal is "no_rw_check";
114
  attribute ramstyle of imem_file_init_ram_h : signal is "no_rw_check";
115
  attribute ramstyle of imem_file_ram_l : signal is "no_rw_check";
116
  attribute ramstyle of imem_file_ram_h : signal is "no_rw_check";
117
 
118
  -- RAM attribute to inhibit bypass-logic - Lattice only! --
119
  attribute syn_ramstyle : string;
120
  attribute syn_ramstyle of imem_file_init_ram_l : signal is "no_rw_check";
121
  attribute syn_ramstyle of imem_file_init_ram_h : signal is "no_rw_check";
122
  attribute syn_ramstyle of imem_file_ram_l : signal is "no_rw_check";
123
  attribute syn_ramstyle of imem_file_ram_h : signal is "no_rw_check";
124
 
125
  -- SPRAM signals --
126 199 zero_gravi
  signal spram_clk   : std_logic;
127
  signal spram_addr  : std_logic_vector(13 downto 0);
128
  signal spram_di    : std_logic_vector(15 downto 0);
129
  signal spram_do_lo : std_logic_vector(15 downto 0);
130
  signal spram_do_hi : std_logic_vector(15 downto 0);
131
  signal spram_be    : std_logic_vector(03 downto 0);
132
  signal spram_we    : std_logic;
133
  signal spram_pwr_n : std_logic;
134
  signal spram_cs    : std_logic_vector(01 downto 0);
135 198 zero_gravi
 
136
begin
137
 
138
  -- Access Control -----------------------------------------------------------
139
  -- -----------------------------------------------------------------------------
140
  acc_en <= '1' when (addr_i >= imem_base_c) and (addr_i < std_ulogic_vector(unsigned(imem_base_c) + IMEM_SIZE)) else '0';
141
  addr   <= to_integer(unsigned(addr_i(index_size_f(IMEM_SIZE/2) downto 1))); -- word aligned
142 199 zero_gravi
  mem_cs <= acc_en and (rden_i or wren_i(1) or wren_i(0));
143 198 zero_gravi
 
144
 
145
  -- Memory Access ------------------------------------------------------------
146
  -- -----------------------------------------------------------------------------
147
  imem_spram_lo_inst : SP256K
148
  port map (
149
    AD       => spram_addr,  -- I
150 199 zero_gravi
    DI       => spram_di,    -- I
151
    MASKWE   => spram_be,    -- I
152
    WE       => spram_we,    -- I
153
    CS       => spram_cs(0), -- I
154
    CK       => spram_clk,   -- I
155
    STDBY    => '0',         -- I
156
    SLEEP    => spram_pwr_n, -- I
157
    PWROFF_N => '1',         -- I
158
    DO       => spram_do_lo  -- O
159 198 zero_gravi
  );
160
 
161 199 zero_gravi
  -- instantiate second SPRAM if IMEM size > 32kB --
162
  imem_spram_hi_bank:
163
  if (IMEM_SIZE > 32*1024) generate
164
    imem_spram_hi_inst : SP256K
165
    port map (
166
      AD       => spram_addr,  -- I
167
      DI       => spram_di,    -- I
168
      MASKWE   => spram_be,    -- I
169
      WE       => spram_we,    -- I
170
      CS       => spram_cs(1), -- I
171
      CK       => spram_clk,   -- I
172
      STDBY    => '0',         -- I
173
      SLEEP    => spram_pwr_n, -- I
174
      PWROFF_N => '1',         -- I
175
      DO       => spram_do_hi  -- O
176
    );
177
  end generate;
178 198 zero_gravi
 
179 199 zero_gravi
  -- access logic and signal type conversion --
180
  spram_clk   <= std_logic(clk_i);
181
  spram_addr  <= std_logic_vector(addr_i(13+1 downto 0+1));
182
  spram_di    <= std_logic_vector(data_i(15 downto 0));
183
  spram_we    <= '1' when ((acc_en and upen_i and (wren_i(0) or wren_i(1))) = '1') else '0'; -- global write enable
184
  rdata       <= std_ulogic_vector(spram_do_lo) when (mem_sel = '0') else std_ulogic_vector(spram_do_hi); -- lo/hi memory bank
185
  spram_cs(0) <= '1' when (addr_i(15) = '0') else '0'; -- low memory bank
186
  spram_cs(1) <= '1' when (addr_i(15) = '1') else '0'; -- high memory bank
187
 
188 198 zero_gravi
  spram_be(1 downto 0) <= "11" when (wren_i(0) = '1') else "00"; -- low byte write enable
189
  spram_be(3 downto 2) <= "11" when (wren_i(1) = '1') else "00"; -- high byte write enable
190
 
191 199 zero_gravi
  spram_pwr_n <= '0' when ((spram_sleep_mode_en_c = false) or (mem_cs = '1')) else '1'; -- LP mode disabled or IMEM selected
192
 
193 198 zero_gravi
  buffer_ff: process(clk_i)
194
  begin
195
    -- sanity check --
196
    if (IMEM_AS_ROM = true) or (BOOTLD_USE = false) then
197
      assert false report "ICE40 Ultra Plus SPRAM cannot be initialized by bitstream!" severity error;
198
    end if;
199 199 zero_gravi
    if (IMEM_SIZE > 48*1024) then
200
      assert false report "I-mem size out of range! Max 48kB!" severity error;
201 198 zero_gravi
    end if;
202
    -- buffer --
203
    if rising_edge(clk_i) then
204 199 zero_gravi
      mem_sel <= addr_i(15);
205
      rden    <= rden_i and acc_en;
206 198 zero_gravi
    end if;
207
  end process buffer_ff;
208
 
209
  -- output gate --
210
  data_o <= rdata when (rden = '1') else (others => '0');
211
 
212
 
213
end neo430_imem_rtl;

powered by: WebSVN 2.1.0

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