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 198

Go to most recent revision | 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
  -- ROM types --
71
  type imem_file8_t is array (0 to IMEM_SIZE/2-1) of std_ulogic_vector(07 downto 0);
72
 
73
  -- init function and split 1x16-bit memory into 2x8-bit memories --
74
  impure function init_imem(hilo : std_ulogic; init : application_init_image_t) return imem_file8_t is
75
    variable mem_v : imem_file8_t;
76
  begin
77
    for i in 0 to IMEM_SIZE/2-1 loop
78
      if (hilo = '0') then -- low byte
79
        mem_v(i) := init(i)(07 downto 00);
80
      else -- high byte
81
        mem_v(i) := init(i)(15 downto 08);
82
      end if;
83
    end loop; -- i
84
    return mem_v;
85
  end function init_imem;
86
 
87
  -- local signals --
88
  signal acc_en : std_ulogic;
89
  signal rdata  : std_ulogic_vector(15 downto 0);
90
  signal rden   : std_ulogic;
91
  signal addr   : integer;
92
 
93
  -- internal "RAM" type - implemented if bootloader is used and IMEM is RAM and initialized with app code --
94
  signal imem_file_init_ram_l : imem_file8_t := init_imem('0', application_init_image);
95
  signal imem_file_init_ram_h : imem_file8_t := init_imem('1', application_init_image);
96
 
97
  -- internal "ROM" type - implemented if bootloader is NOT used; always initialize with app code --
98
  constant imem_file_rom_l : imem_file8_t := init_imem('0', application_init_image);
99
  constant imem_file_rom_h : imem_file8_t := init_imem('1', application_init_image);
100
 
101
  -- internal "RAM" type - implemented if bootloader is used and IMEM is RAM --
102
  signal imem_file_ram_l : imem_file8_t;
103
  signal imem_file_ram_h : imem_file8_t;
104
 
105
  -- RAM attribute to inhibit bypass-logic - Intel only! --
106
  attribute ramstyle : string;
107
  attribute ramstyle of imem_file_init_ram_l : signal is "no_rw_check";
108
  attribute ramstyle of imem_file_init_ram_h : signal is "no_rw_check";
109
  attribute ramstyle of imem_file_ram_l : signal is "no_rw_check";
110
  attribute ramstyle of imem_file_ram_h : signal is "no_rw_check";
111
 
112
  -- RAM attribute to inhibit bypass-logic - Lattice only! --
113
  attribute syn_ramstyle : string;
114
  attribute syn_ramstyle of imem_file_init_ram_l : signal is "no_rw_check";
115
  attribute syn_ramstyle of imem_file_init_ram_h : signal is "no_rw_check";
116
  attribute syn_ramstyle of imem_file_ram_l : signal is "no_rw_check";
117
  attribute syn_ramstyle of imem_file_ram_h : signal is "no_rw_check";
118
 
119
  -- SPRAM signals --
120
  signal spram_clk  : std_logic;
121
  signal spram_addr : std_logic_vector(13 downto 0);
122
  signal spram_di   : std_logic_vector(15 downto 0);
123
  signal spram_do   : std_logic_vector(15 downto 0);
124
  signal spram_be   : std_logic_vector(03 downto 0);
125
  signal spram_we   : std_logic;
126
 
127
begin
128
 
129
  -- Access Control -----------------------------------------------------------
130
  -- -----------------------------------------------------------------------------
131
  acc_en <= '1' when (addr_i >= imem_base_c) and (addr_i < std_ulogic_vector(unsigned(imem_base_c) + IMEM_SIZE)) else '0';
132
  addr   <= to_integer(unsigned(addr_i(index_size_f(IMEM_SIZE/2) downto 1))); -- word aligned
133
 
134
 
135
  -- Memory Access ------------------------------------------------------------
136
  -- -----------------------------------------------------------------------------
137
  imem_spram_lo_inst : SP256K
138
  port map (
139
    AD       => spram_addr,  -- I
140
    DI       => spram_di,  -- I
141
    MASKWE   => spram_be,  -- I
142
    WE       => spram_we,  -- I
143
    CS       => '1',  -- I
144
    CK       => spram_clk,  -- I
145
    STDBY    => '0',  -- I
146
    SLEEP    => '0',  -- I
147
    PWROFF_N => '1',  -- I
148
    DO       => spram_do   -- O
149
  );
150
 
151
  -- signal type conversion --
152
  spram_clk  <= std_logic(clk_i);
153
  spram_addr <= std_logic_vector(addr_i(13+1 downto 0+1));
154
  spram_di   <= std_logic_vector(data_i(15 downto 0));
155
  spram_we   <= '1' when ((acc_en and upen_i and (wren_i(0) or wren_i(1))) = '1') else '0'; -- global write enable
156
  rdata      <= std_ulogic_vector(spram_do);
157
 
158
  spram_be(1 downto 0) <= "11" when (wren_i(0) = '1') else "00"; -- low byte write enable
159
  spram_be(3 downto 2) <= "11" when (wren_i(1) = '1') else "00"; -- high byte write enable
160
 
161
  buffer_ff: process(clk_i)
162
  begin
163
    -- sanity check --
164
    if (IMEM_AS_ROM = true) or (BOOTLD_USE = false) then
165
      assert false report "ICE40 Ultra Plus SPRAM cannot be initialized by bitstream!" severity error;
166
    end if;
167
    if (IMEM_SIZE > 32*1024) then
168
      assert false report "I-mem size out of range! Max 32kB!" severity error;
169
    end if;
170
    -- buffer --
171
    if rising_edge(clk_i) then
172
      rden <= rden_i and acc_en;
173
    end if;
174
  end process buffer_ff;
175
 
176
  -- output gate --
177
  data_o <= rdata when (rden = '1') else (others => '0');
178
 
179
 
180
end neo430_imem_rtl;

powered by: WebSVN 2.1.0

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