1 |
15 |
lcdsgmtr |
-- Copyright 2015, Jürgen Defurne
|
2 |
|
|
--
|
3 |
|
|
-- This file is part of the Experimental Unstable CPU System.
|
4 |
|
|
--
|
5 |
|
|
-- The Experimental Unstable CPU System Is free software: you can redistribute
|
6 |
|
|
-- it and/or modify it under the terms of the GNU Lesser General Public License
|
7 |
|
|
-- as published by the Free Software Foundation, either version 3 of the
|
8 |
|
|
-- License, or (at your option) any later version.
|
9 |
|
|
--
|
10 |
|
|
-- The Experimental Unstable CPU System is distributed in the hope that it will
|
11 |
|
|
-- be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
|
13 |
|
|
-- General Public License for more details.
|
14 |
|
|
--
|
15 |
|
|
-- You should have received a copy of the GNU Lesser General Public License
|
16 |
|
|
-- along with Experimental Unstable CPU System. If not, see
|
17 |
|
|
-- http://www.gnu.org/licenses/lgpl.txt.
|
18 |
|
|
|
19 |
|
|
|
20 |
|
|
LIBRARY ieee;
|
21 |
|
|
USE ieee.std_logic_1164.ALL;
|
22 |
|
|
USE ieee.numeric_std.ALL;
|
23 |
17 |
lcdsgmtr |
USE work.hexio.ALL;
|
24 |
15 |
lcdsgmtr |
|
25 |
|
|
PACKAGE ram_parts IS
|
26 |
|
|
|
27 |
|
|
COMPONENT RAM_GENERIC IS
|
28 |
|
|
GENERIC (
|
29 |
|
|
filename : STRING := "";
|
30 |
|
|
w_data : NATURAL RANGE 1 TO 32 := 16;
|
31 |
|
|
w_addr : NATURAL RANGE 8 TO 14 := 10);
|
32 |
|
|
PORT (
|
33 |
|
|
clk : IN STD_LOGIC;
|
34 |
|
|
we : IN STD_LOGIC;
|
35 |
|
|
a1 : IN STD_LOGIC_VECTOR(w_addr - 1 DOWNTO 0); -- Data port address
|
36 |
|
|
a2 : IN STD_LOGIC_VECTOR(w_addr - 1 DOWNTO 0); -- Instruction port address
|
37 |
|
|
d1 : IN STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0); -- Data port input
|
38 |
|
|
q1 : OUT STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0); -- Data port output
|
39 |
|
|
q2 : OUT STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0)); -- Instruction port output
|
40 |
|
|
|
41 |
|
|
END COMPONENT RAM_GENERIC;
|
42 |
|
|
|
43 |
|
|
COMPONENT RAM32K IS
|
44 |
|
|
|
45 |
|
|
GENERIC (
|
46 |
|
|
filename : STRING := "";
|
47 |
|
|
w_data : NATURAL RANGE 1 TO 32 := 16);
|
48 |
|
|
PORT (
|
49 |
|
|
clk : IN STD_LOGIC;
|
50 |
|
|
we : IN STD_LOGIC;
|
51 |
|
|
a1 : IN STD_LOGIC_VECTOR(14 DOWNTO 0); -- Data port address
|
52 |
|
|
a2 : IN STD_LOGIC_VECTOR(14 DOWNTO 0); -- Instruction port address
|
53 |
|
|
d1 : IN STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0); -- Data port input
|
54 |
|
|
q1 : OUT STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0); -- Data port output
|
55 |
|
|
q2 : OUT STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0)); -- Instruction port output
|
56 |
|
|
|
57 |
|
|
END COMPONENT RAM32K;
|
58 |
|
|
|
59 |
22 |
lcdsgmtr |
COMPONENT generic_memory_block IS
|
60 |
|
|
|
61 |
|
|
GENERIC (
|
62 |
|
|
init_data : cstr_array_type;
|
63 |
|
|
w_data : NATURAL RANGE 1 TO 32 := 16;
|
64 |
|
|
w_addr : NATURAL RANGE 8 TO 14 := 10);
|
65 |
|
|
PORT (
|
66 |
|
|
clk : IN STD_LOGIC;
|
67 |
|
|
we : IN STD_LOGIC;
|
68 |
|
|
a1 : IN STD_LOGIC_VECTOR(w_addr - 1 DOWNTO 0); -- Data port address
|
69 |
|
|
a2 : IN STD_LOGIC_VECTOR(w_addr - 1 DOWNTO 0); -- Instruction port address
|
70 |
|
|
d1 : IN STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0); -- Data port input
|
71 |
|
|
q1 : OUT STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0); -- Data port output
|
72 |
|
|
q2 : OUT STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0)); -- Instruction port output
|
73 |
|
|
|
74 |
|
|
END COMPONENT generic_memory_block;
|
75 |
|
|
|
76 |
15 |
lcdsgmtr |
END PACKAGE ram_parts;
|
77 |
|
|
|
78 |
|
|
LIBRARY ieee;
|
79 |
|
|
USE ieee.std_logic_1164.ALL;
|
80 |
|
|
USE ieee.numeric_std.ALL;
|
81 |
16 |
lcdsgmtr |
USE work.hexio.ALL;
|
82 |
15 |
lcdsgmtr |
|
83 |
|
|
ENTITY RAM_GENERIC IS
|
84 |
|
|
|
85 |
|
|
-- Memory component based upon Xilinx Spartan-6 block RAM
|
86 |
|
|
-- Maximum capacity is 16k words
|
87 |
|
|
-- This component can be initialised by passing a file name as a generic
|
88 |
|
|
-- parameter.
|
89 |
|
|
|
90 |
|
|
GENERIC (
|
91 |
|
|
filename : STRING := "";
|
92 |
|
|
w_data : NATURAL RANGE 1 TO 32 := 16;
|
93 |
|
|
w_addr : NATURAL RANGE 8 TO 14 := 10);
|
94 |
|
|
PORT (
|
95 |
|
|
clk : IN STD_LOGIC;
|
96 |
|
|
we : IN STD_LOGIC;
|
97 |
|
|
a1 : IN STD_LOGIC_VECTOR(w_addr - 1 DOWNTO 0); -- Data port address
|
98 |
|
|
a2 : IN STD_LOGIC_VECTOR(w_addr - 1 DOWNTO 0); -- Instruction port address
|
99 |
|
|
d1 : IN STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0); -- Data port input
|
100 |
|
|
q1 : OUT STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0); -- Data port output
|
101 |
|
|
q2 : OUT STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0)); -- Instruction port output
|
102 |
|
|
|
103 |
|
|
END RAM_GENERIC;
|
104 |
|
|
|
105 |
|
|
ARCHITECTURE Behavioral OF RAM_GENERIC IS
|
106 |
|
|
|
107 |
|
|
SIGNAL mem : cstr_array_type(0 TO (2**w_addr) - 1) := init_cstr(2**w_addr, filename);
|
108 |
|
|
|
109 |
|
|
SIGNAL address_reg_1 : STD_LOGIC_VECTOR(w_addr - 1 DOWNTO 0);
|
110 |
|
|
SIGNAL address_reg_2 : STD_LOGIC_VECTOR(w_addr - 1 DOWNTO 0);
|
111 |
|
|
|
112 |
|
|
BEGIN -- Behavioral
|
113 |
|
|
|
114 |
|
|
-- purpose: Try to describe a proper block ram without needing to instantiate a BRAM
|
115 |
|
|
-- type : sequential
|
116 |
|
|
-- inputs : clk, we, a1, a2, d1
|
117 |
|
|
-- outputs: q1, q2
|
118 |
|
|
MP1 : PROCESS (clk, address_reg_1, address_reg_2, mem)
|
119 |
|
|
BEGIN -- PROCESS MP1
|
120 |
|
|
|
121 |
|
|
-- Reading
|
122 |
|
|
q1 <= STD_LOGIC_VECTOR(to_unsigned(mem(to_integer(UNSIGNED(address_reg_1))), w_data));
|
123 |
|
|
q2 <= STD_LOGIC_VECTOR(to_unsigned(mem(to_integer(UNSIGNED(address_reg_2))), w_data));
|
124 |
|
|
|
125 |
|
|
IF rising_edge(clk) THEN -- rising clock edge
|
126 |
|
|
|
127 |
|
|
-- These work like the block RAM registers
|
128 |
|
|
address_reg_1 <= a1;
|
129 |
|
|
address_reg_2 <= a2;
|
130 |
|
|
|
131 |
|
|
-- Writing
|
132 |
|
|
IF we = '1' THEN
|
133 |
|
|
mem(to_integer(UNSIGNED(a1))) <= to_integer(UNSIGNED(d1));
|
134 |
|
|
END IF;
|
135 |
|
|
|
136 |
|
|
END IF;
|
137 |
|
|
|
138 |
|
|
END PROCESS MP1;
|
139 |
|
|
|
140 |
|
|
END Behavioral;
|
141 |
|
|
|
142 |
|
|
LIBRARY ieee;
|
143 |
|
|
USE ieee.std_logic_1164.ALL;
|
144 |
|
|
USE ieee.numeric_std.ALL;
|
145 |
|
|
USE work.mux_parts.ALL;
|
146 |
16 |
lcdsgmtr |
USE work.hexio.ALL;
|
147 |
22 |
lcdsgmtr |
USE work.ram_parts.all;
|
148 |
15 |
lcdsgmtr |
|
149 |
|
|
ENTITY RAM32K IS
|
150 |
|
|
|
151 |
|
|
-- This component is based upon the above defined memory
|
152 |
|
|
-- It is constructed using a 4-to-1 multiplexer and 4 8k word
|
153 |
|
|
-- memories.
|
154 |
|
|
|
155 |
|
|
GENERIC (
|
156 |
|
|
w_data : NATURAL RANGE 1 TO 32 := 16;
|
157 |
|
|
filename : STRING := "");
|
158 |
|
|
PORT (
|
159 |
|
|
clk : IN STD_LOGIC;
|
160 |
|
|
we : IN STD_LOGIC;
|
161 |
|
|
a1 : IN STD_LOGIC_VECTOR(14 DOWNTO 0); -- Data port address
|
162 |
|
|
a2 : IN STD_LOGIC_VECTOR(14 DOWNTO 0); -- Instruction port address
|
163 |
|
|
d1 : IN STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0); -- Data port input
|
164 |
|
|
q1 : OUT STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0); -- Data port output
|
165 |
|
|
q2 : OUT STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0)); -- Instruction port output
|
166 |
|
|
|
167 |
|
|
END RAM32K;
|
168 |
|
|
|
169 |
|
|
ARCHITECTURE Structural OF RAM32K IS
|
170 |
|
|
|
171 |
28 |
lcdsgmtr |
CONSTANT memory_array : B32K_array_type := init_b32k(filename);
|
172 |
17 |
lcdsgmtr |
|
173 |
15 |
lcdsgmtr |
SIGNAL data_address : STD_LOGIC_VECTOR(12 DOWNTO 0);
|
174 |
|
|
SIGNAL data_select : STD_LOGIC_VECTOR(1 DOWNTO 0);
|
175 |
|
|
SIGNAL instr_address : STD_LOGIC_VECTOR(12 DOWNTO 0);
|
176 |
|
|
SIGNAL instr_select : STD_LOGIC_VECTOR(1 DOWNTO 0);
|
177 |
|
|
|
178 |
|
|
SIGNAL wr_sel : STD_LOGIC_VECTOR(3 DOWNTO 0);
|
179 |
|
|
|
180 |
|
|
TYPE bus_array_t IS ARRAY(0 TO 3) OF STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);
|
181 |
|
|
|
182 |
|
|
SIGNAL data : bus_array_t;
|
183 |
|
|
SIGNAL inst : bus_array_t;
|
184 |
|
|
|
185 |
|
|
TYPE file_array IS ARRAY(INTEGER RANGE <>) OF STRING(1 TO 100);
|
186 |
|
|
|
187 |
|
|
BEGIN -- Structural
|
188 |
|
|
|
189 |
|
|
data_address <= a1(12 DOWNTO 0);
|
190 |
|
|
data_select <= a1(14 DOWNTO 13);
|
191 |
|
|
|
192 |
|
|
instr_address <= a2(12 DOWNTO 0);
|
193 |
|
|
instr_select <= a2(14 DOWNTO 13);
|
194 |
|
|
|
195 |
|
|
wr_sel <= "0001" WHEN data_select = "00" AND we = '1' ELSE
|
196 |
|
|
"0010" WHEN data_select = "01" AND we = '1' ELSE
|
197 |
|
|
"0100" WHEN data_select = "10" AND we = '1' ELSE
|
198 |
|
|
"1000" WHEN data_select = "11" AND we = '1' ELSE
|
199 |
|
|
"0000";
|
200 |
|
|
|
201 |
|
|
M1 : mux4to1
|
202 |
|
|
PORT MAP (
|
203 |
|
|
SEL => data_select,
|
204 |
|
|
S0 => data(0),
|
205 |
|
|
S1 => data(1),
|
206 |
|
|
S2 => data(2),
|
207 |
|
|
S3 => data(3),
|
208 |
|
|
Y => q1);
|
209 |
|
|
|
210 |
|
|
M2 : mux4to1
|
211 |
|
|
PORT MAP (
|
212 |
|
|
SEL => instr_select,
|
213 |
|
|
S0 => inst(0),
|
214 |
|
|
S1 => inst(1),
|
215 |
|
|
S2 => inst(2),
|
216 |
|
|
S3 => inst(3),
|
217 |
|
|
Y => q2);
|
218 |
|
|
|
219 |
|
|
RAM : FOR i IN 0 TO 3 GENERATE
|
220 |
|
|
|
221 |
17 |
lcdsgmtr |
R0 : generic_memory_block
|
222 |
15 |
lcdsgmtr |
GENERIC MAP (
|
223 |
17 |
lcdsgmtr |
init_data => memory_array(i),
|
224 |
|
|
w_data => w_data,
|
225 |
|
|
w_addr => 13)
|
226 |
15 |
lcdsgmtr |
PORT MAP (
|
227 |
|
|
clk => clk,
|
228 |
|
|
we => wr_sel(i),
|
229 |
|
|
a1 => data_address,
|
230 |
|
|
a2 => instr_address,
|
231 |
|
|
d1 => d1,
|
232 |
|
|
q1 => data(i),
|
233 |
|
|
q2 => inst(i));
|
234 |
|
|
|
235 |
|
|
END GENERATE RAM;
|
236 |
|
|
|
237 |
|
|
END Structural;
|
238 |
41 |
lcdsgmtr |
|
239 |
|
|
LIBRARY ieee;
|
240 |
|
|
USE ieee.std_logic_1164.ALL;
|
241 |
|
|
USE ieee.numeric_std.ALL;
|
242 |
|
|
USE work.mux_parts.ALL;
|
243 |
|
|
USE work.hexio.ALL;
|
244 |
|
|
USE work.ram_parts.all;
|
245 |
|
|
|
246 |
|
|
-- Pipelined 32k memory
|
247 |
|
|
ENTITY RAM32K_P IS
|
248 |
|
|
|
249 |
|
|
-- This component is based upon the above defined memory
|
250 |
|
|
-- It is constructed using a 4-to-1 multiplexer and 4 8k word
|
251 |
|
|
-- memories.
|
252 |
|
|
|
253 |
|
|
GENERIC (
|
254 |
|
|
w_data : NATURAL RANGE 1 TO 32 := 16;
|
255 |
|
|
filename : STRING := "");
|
256 |
|
|
PORT (
|
257 |
|
|
clk : IN STD_LOGIC;
|
258 |
|
|
we : IN STD_LOGIC;
|
259 |
|
|
a1 : IN STD_LOGIC_VECTOR(14 DOWNTO 0); -- Data port address
|
260 |
|
|
a2 : IN STD_LOGIC_VECTOR(14 DOWNTO 0); -- Instruction port address
|
261 |
|
|
d1 : IN STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0); -- Data port input
|
262 |
|
|
q1 : OUT STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0); -- Data port output
|
263 |
|
|
q2 : OUT STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0)); -- Instruction port output
|
264 |
|
|
|
265 |
|
|
END RAM32K_P;
|
266 |
|
|
|
267 |
|
|
ARCHITECTURE Structural OF RAM32K_P IS
|
268 |
|
|
|
269 |
|
|
CONSTANT memory_array : B32K_array_type := init_b32k(filename);
|
270 |
|
|
|
271 |
|
|
SIGNAL data_address : STD_LOGIC_VECTOR(12 DOWNTO 0);
|
272 |
|
|
SIGNAL data_select : STD_LOGIC_VECTOR(1 DOWNTO 0);
|
273 |
|
|
SIGNAL instr_address : STD_LOGIC_VECTOR(12 DOWNTO 0);
|
274 |
|
|
SIGNAL instr_select : STD_LOGIC_VECTOR(1 DOWNTO 0);
|
275 |
|
|
|
276 |
|
|
SIGNAL wr_sel : STD_LOGIC_VECTOR(3 DOWNTO 0);
|
277 |
|
|
|
278 |
|
|
TYPE bus_array_t IS ARRAY(0 TO 3) OF STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);
|
279 |
|
|
|
280 |
|
|
SIGNAL data : bus_array_t;
|
281 |
|
|
SIGNAL inst : bus_array_t;
|
282 |
|
|
|
283 |
|
|
TYPE file_array IS ARRAY(INTEGER RANGE <>) OF STRING(1 TO 100);
|
284 |
|
|
|
285 |
|
|
BEGIN -- Structural
|
286 |
|
|
|
287 |
|
|
data_address <= a1(12 DOWNTO 0);
|
288 |
|
|
data_select <= a1(14 DOWNTO 13);
|
289 |
|
|
|
290 |
|
|
instr_address <= a2(12 DOWNTO 0);
|
291 |
|
|
instr_select <= a2(14 DOWNTO 13);
|
292 |
|
|
|
293 |
|
|
wr_sel <= "0001" WHEN data_select = "00" AND we = '1' ELSE
|
294 |
|
|
"0010" WHEN data_select = "01" AND we = '1' ELSE
|
295 |
|
|
"0100" WHEN data_select = "10" AND we = '1' ELSE
|
296 |
|
|
"1000" WHEN data_select = "11" AND we = '1' ELSE
|
297 |
|
|
"0000";
|
298 |
|
|
|
299 |
|
|
M1 : mux4to1
|
300 |
|
|
PORT MAP (
|
301 |
|
|
SEL => data_select,
|
302 |
|
|
S0 => data(0),
|
303 |
|
|
S1 => data(1),
|
304 |
|
|
S2 => data(2),
|
305 |
|
|
S3 => data(3),
|
306 |
|
|
Y => q1);
|
307 |
|
|
|
308 |
|
|
M2 : mux4to1
|
309 |
|
|
PORT MAP (
|
310 |
|
|
SEL => instr_select,
|
311 |
|
|
S0 => inst(0),
|
312 |
|
|
S1 => inst(1),
|
313 |
|
|
S2 => inst(2),
|
314 |
|
|
S3 => inst(3),
|
315 |
|
|
Y => q2);
|
316 |
|
|
|
317 |
|
|
RAM : FOR i IN 0 TO 3 GENERATE
|
318 |
|
|
|
319 |
|
|
R0 : generic_memory_block
|
320 |
|
|
GENERIC MAP (
|
321 |
|
|
init_data => memory_array(i),
|
322 |
|
|
w_data => w_data,
|
323 |
|
|
w_addr => 13)
|
324 |
|
|
PORT MAP (
|
325 |
|
|
clk => clk,
|
326 |
|
|
we => wr_sel(i),
|
327 |
|
|
a1 => data_address,
|
328 |
|
|
a2 => instr_address,
|
329 |
|
|
d1 => d1,
|
330 |
|
|
q1 => data(i),
|
331 |
|
|
q2 => inst(i));
|
332 |
|
|
|
333 |
|
|
END GENERATE RAM;
|
334 |
|
|
|
335 |
|
|
END Structural;
|