1 |
198 |
zero_gravi |
-- #################################################################################################
|
2 |
|
|
-- # << NEO430 - Instruction memory ("IMEM") >> #
|
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 |
|
|
entity neo430_imem is
|
49 |
|
|
generic (
|
50 |
|
|
IMEM_SIZE : natural := 4*1024; -- internal IMEM size in bytes
|
51 |
|
|
IMEM_AS_ROM : boolean := false; -- implement IMEM as read-only memory?
|
52 |
|
|
BOOTLD_USE : boolean := true -- implement and use bootloader?
|
53 |
|
|
);
|
54 |
|
|
port (
|
55 |
|
|
clk_i : in std_ulogic; -- global clock line
|
56 |
|
|
rden_i : in std_ulogic; -- read enable
|
57 |
|
|
wren_i : in std_ulogic_vector(01 downto 0); -- write enable
|
58 |
|
|
upen_i : in std_ulogic; -- update enable
|
59 |
|
|
addr_i : in std_ulogic_vector(15 downto 0); -- address
|
60 |
|
|
data_i : in std_ulogic_vector(15 downto 0); -- data in
|
61 |
|
|
data_o : out std_ulogic_vector(15 downto 0) -- data out
|
62 |
|
|
);
|
63 |
|
|
end neo430_imem;
|
64 |
|
|
|
65 |
|
|
architecture neo430_imem_rtl of neo430_imem is
|
66 |
|
|
|
67 |
|
|
-- ROM types --
|
68 |
|
|
type imem_file8_t is array (0 to IMEM_SIZE/2-1) of std_ulogic_vector(07 downto 0);
|
69 |
|
|
|
70 |
|
|
-- init function and split 1x16-bit memory into 2x8-bit memories --
|
71 |
|
|
impure function init_imem(hilo : std_ulogic; init : application_init_image_t) return imem_file8_t is
|
72 |
|
|
variable mem_v : imem_file8_t;
|
73 |
|
|
begin
|
74 |
|
|
for i in 0 to IMEM_SIZE/2-1 loop
|
75 |
|
|
if (hilo = '0') then -- low byte
|
76 |
|
|
mem_v(i) := init(i)(07 downto 00);
|
77 |
|
|
else -- high byte
|
78 |
|
|
mem_v(i) := init(i)(15 downto 08);
|
79 |
|
|
end if;
|
80 |
|
|
end loop; -- i
|
81 |
|
|
return mem_v;
|
82 |
|
|
end function init_imem;
|
83 |
|
|
|
84 |
|
|
-- local signals --
|
85 |
|
|
signal acc_en : std_ulogic;
|
86 |
|
|
signal rdata : std_ulogic_vector(15 downto 0);
|
87 |
|
|
signal rden : std_ulogic;
|
88 |
|
|
signal addr : integer;
|
89 |
|
|
|
90 |
|
|
-- internal "RAM" type - implemented if bootloader is used and IMEM is RAM and initialized with app code --
|
91 |
|
|
signal imem_file_init_ram_l : imem_file8_t := init_imem('0', application_init_image);
|
92 |
|
|
signal imem_file_init_ram_h : imem_file8_t := init_imem('1', application_init_image);
|
93 |
|
|
|
94 |
|
|
-- internal "ROM" type - implemented if bootloader is NOT used; always initialize with app code --
|
95 |
|
|
constant imem_file_rom_l : imem_file8_t := init_imem('0', application_init_image);
|
96 |
|
|
constant imem_file_rom_h : imem_file8_t := init_imem('1', application_init_image);
|
97 |
|
|
|
98 |
|
|
-- internal "RAM" type - implemented if bootloader is used and IMEM is RAM --
|
99 |
|
|
signal imem_file_ram_l : imem_file8_t;
|
100 |
|
|
signal imem_file_ram_h : imem_file8_t;
|
101 |
|
|
|
102 |
|
|
-- RAM attribute to inhibit bypass-logic - Intel only! --
|
103 |
|
|
attribute ramstyle : string;
|
104 |
|
|
attribute ramstyle of imem_file_init_ram_l : signal is "no_rw_check";
|
105 |
|
|
attribute ramstyle of imem_file_init_ram_h : signal is "no_rw_check";
|
106 |
|
|
attribute ramstyle of imem_file_ram_l : signal is "no_rw_check";
|
107 |
|
|
attribute ramstyle of imem_file_ram_h : signal is "no_rw_check";
|
108 |
|
|
|
109 |
|
|
-- RAM attribute to inhibit bypass-logic - Lattice only! --
|
110 |
|
|
attribute syn_ramstyle : string;
|
111 |
|
|
attribute syn_ramstyle of imem_file_init_ram_l : signal is "no_rw_check";
|
112 |
|
|
attribute syn_ramstyle of imem_file_init_ram_h : signal is "no_rw_check";
|
113 |
|
|
attribute syn_ramstyle of imem_file_ram_l : signal is "no_rw_check";
|
114 |
|
|
attribute syn_ramstyle of imem_file_ram_h : signal is "no_rw_check";
|
115 |
|
|
|
116 |
|
|
begin
|
117 |
|
|
|
118 |
|
|
-- Access Control -----------------------------------------------------------
|
119 |
|
|
-- -----------------------------------------------------------------------------
|
120 |
|
|
acc_en <= '1' when (addr_i >= imem_base_c) and (addr_i < std_ulogic_vector(unsigned(imem_base_c) + IMEM_SIZE)) else '0';
|
121 |
|
|
addr <= to_integer(unsigned(addr_i(index_size_f(IMEM_SIZE/2) downto 1))); -- word aligned
|
122 |
|
|
|
123 |
|
|
|
124 |
|
|
-- Memory Access ------------------------------------------------------------
|
125 |
|
|
-- -----------------------------------------------------------------------------
|
126 |
|
|
imem_file_access: process(clk_i)
|
127 |
|
|
begin
|
128 |
|
|
-- check max size --
|
129 |
|
|
if (IMEM_SIZE > imem_max_size_c) then
|
130 |
|
|
assert false report "I-mem size out of range! Max 48kB!" severity error;
|
131 |
|
|
end if;
|
132 |
|
|
-- actual memory access --
|
133 |
|
|
if rising_edge(clk_i) then
|
134 |
|
|
rden <= rden_i and acc_en;
|
135 |
|
|
if (acc_en = '1') then -- reduce switching activity when not accessed
|
136 |
|
|
if (IMEM_AS_ROM = true) then -- implement IMEM as true ROM
|
137 |
|
|
rdata(07 downto 0) <= imem_file_rom_l(addr);
|
138 |
|
|
rdata(15 downto 8) <= imem_file_rom_h(addr);
|
139 |
|
|
|
140 |
|
|
elsif (BOOTLD_USE = true) then -- implement IMEM as non-initialized RAM
|
141 |
|
|
if (wren_i(0) = '1') and (upen_i = '1') then
|
142 |
|
|
imem_file_ram_l(addr) <= data_i(07 downto 0);
|
143 |
|
|
end if;
|
144 |
|
|
rdata(07 downto 0) <= imem_file_ram_l(addr);
|
145 |
|
|
if (wren_i(1) = '1') and (upen_i = '1') then
|
146 |
|
|
imem_file_ram_h(addr) <= data_i(15 downto 8);
|
147 |
|
|
end if;
|
148 |
|
|
rdata(15 downto 8) <= imem_file_ram_h(addr);
|
149 |
|
|
|
150 |
|
|
else -- implement IMEM as PRE-INITIALIZED RAM
|
151 |
|
|
if (wren_i(0) = '1') and (upen_i = '1') then
|
152 |
|
|
imem_file_init_ram_l(addr) <= data_i(07 downto 0);
|
153 |
|
|
end if;
|
154 |
|
|
rdata(07 downto 0) <= imem_file_init_ram_l(addr);
|
155 |
|
|
if (wren_i(1) = '1') and (upen_i = '1') then
|
156 |
|
|
imem_file_init_ram_h(addr) <= data_i(15 downto 8);
|
157 |
|
|
end if;
|
158 |
|
|
rdata(15 downto 8) <= imem_file_init_ram_h(addr);
|
159 |
|
|
end if;
|
160 |
|
|
end if;
|
161 |
|
|
end if;
|
162 |
|
|
end process imem_file_access;
|
163 |
|
|
|
164 |
|
|
-- output gate --
|
165 |
|
|
data_o <= rdata when (rden = '1') else (others => '0');
|
166 |
|
|
|
167 |
|
|
|
168 |
|
|
end neo430_imem_rtl;
|