1 |
139 |
jguarin200 |
--! @file memblock.vhd
|
2 |
128 |
jguarin200 |
--! @brief Bloque de memoria.
|
3 |
|
|
--! @author Julián Andrés Guarín Reyes
|
4 |
|
|
--------------------------------------------------------------
|
5 |
|
|
-- RAYTRAC
|
6 |
|
|
-- Author Julian Andres Guarin
|
7 |
|
|
-- memblock.vhd
|
8 |
|
|
-- This file is part of raytrac.
|
9 |
|
|
--
|
10 |
|
|
-- raytrac is free software: you can redistribute it and/or modify
|
11 |
|
|
-- it under the terms of the GNU General Public License as published by
|
12 |
|
|
-- the Free Software Foundation, either version 3 of the License, or
|
13 |
|
|
-- (at your option) any later version.
|
14 |
|
|
--
|
15 |
|
|
-- raytrac is distributed in the hope that it will be useful,
|
16 |
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18 |
|
|
-- GNU General Public License for more details.
|
19 |
|
|
--
|
20 |
|
|
-- You should have received a copy of the GNU General Public License
|
21 |
|
|
-- along with raytrac. If not, see <http://www.gnu.org/licenses/>.
|
22 |
|
|
|
23 |
|
|
library ieee;
|
24 |
|
|
use ieee.std_logic_1164.all;
|
25 |
129 |
jguarin200 |
|
26 |
128 |
jguarin200 |
entity memblock is
|
27 |
|
|
generic (
|
28 |
129 |
jguarin200 |
|
29 |
|
|
width : integer := 32;
|
30 |
|
|
blocksize : integer := 512;
|
31 |
|
|
widthadmemblock : integer :=9;
|
32 |
|
|
|
33 |
|
|
external_writeable_blocks : integer := 12;
|
34 |
|
|
external_readable_blocks : integer := 8;
|
35 |
|
|
external_readable_widthad : integer := 3;
|
36 |
|
|
external_writeable_widthad : integer := 4
|
37 |
128 |
jguarin200 |
);
|
38 |
|
|
port (
|
39 |
|
|
|
40 |
138 |
jguarin200 |
clk,ena,dpfifo_flush,normfifo_flush,dpfifo_rd,normfifo_rd,dpfifo_wr,normfifo_wr : in std_logic;
|
41 |
129 |
jguarin200 |
dpfifo_empty, normfifo_empty, dpfifo_full, normfifo_full : out std_logic;
|
42 |
138 |
jguarin200 |
instrfifo_flush,instrfifo_rd,instrfifo_wr,resultfifo_flush,resultfifo_wr: in std_logic;
|
43 |
|
|
instrfifo_empty,instrfifo_full: out std_logic;
|
44 |
|
|
ext_rd,ext_wr: in std_logic;
|
45 |
129 |
jguarin200 |
ext_wr_add : in std_logic_vector(external_writeable_widthad+widthadmemblock-1 downto 0);
|
46 |
138 |
jguarin200 |
ext_rd_add : in std_logic_vector(external_readable_widthad-1 downto 0);
|
47 |
129 |
jguarin200 |
ext_d: in std_logic_vector(width-1 downto 0);
|
48 |
138 |
jguarin200 |
resultfifo_full,resultfifo_empty : out std_logic_vector(external_readable_blocks-1 downto 0);
|
49 |
129 |
jguarin200 |
int_d : in std_logic_vector(external_readable_blocks*width-1 downto 0);
|
50 |
138 |
jguarin200 |
ext_q,instrfifo_q : out std_logic_vector(width-1 downto 0);
|
51 |
129 |
jguarin200 |
int_q : out std_logic_vector(external_writeable_blocks*width-1 downto 0);
|
52 |
130 |
jguarin200 |
int_rd_add : in std_logic_vector(2*widthadmemblock-1 downto 0);
|
53 |
133 |
jguarin200 |
instrfifo_d : in std_logic_vector(width-1 downto 0);
|
54 |
129 |
jguarin200 |
dpfifo_d : in std_logic_vector(width*2-1 downto 0);
|
55 |
|
|
normfifo_d : in std_logic_vector(width*3-1 downto 0);
|
56 |
|
|
dpfifo_q : out std_logic_vector(width*2-1 downto 0);
|
57 |
|
|
normfifo_q : out std_logic_vector(width*3-1 downto 0)
|
58 |
128 |
jguarin200 |
);
|
59 |
|
|
end memblock;
|
60 |
|
|
|
61 |
|
|
architecture memblock_arch of memblock is
|
62 |
|
|
|
63 |
130 |
jguarin200 |
type vectorblock12 is array (11 downto 0) of std_logic_vector(width-1 downto 0);
|
64 |
|
|
type vectorblock08 is array (07 downto 0) of std_logic_vector(width-1 downto 0);
|
65 |
|
|
type vectorblock02 is array (01 downto 0) of std_logic_vector(widthadmemblock-1 downto 0);
|
66 |
129 |
jguarin200 |
|
67 |
128 |
jguarin200 |
component scfifo
|
68 |
|
|
generic (
|
69 |
|
|
add_ram_output_register :string;
|
70 |
138 |
jguarin200 |
almost_full_value :natural;
|
71 |
|
|
allow_wrcycle_when_full :string;
|
72 |
128 |
jguarin200 |
intended_device_family :string;
|
73 |
|
|
lpm_hint :string;
|
74 |
|
|
lpm_numwords :natural;
|
75 |
|
|
lpm_showahead :string;
|
76 |
|
|
lpm_type :string;
|
77 |
|
|
lpm_width :natural;
|
78 |
|
|
lpm_widthu :natural;
|
79 |
|
|
overflow_checking :string;
|
80 |
|
|
underflow_checking :string;
|
81 |
|
|
use_eab :string
|
82 |
|
|
);
|
83 |
|
|
port(
|
84 |
138 |
jguarin200 |
rdreq : in std_logic;
|
85 |
|
|
aclr : in std_logic;
|
86 |
|
|
empty : out std_logic;
|
87 |
|
|
clock : in std_logic;
|
88 |
|
|
q : out std_logic_vector(lpm_width-1 downto 0);
|
89 |
|
|
wrreq : in std_logic;
|
90 |
|
|
data : in std_logic_vector(lpm_width-1 downto 0);
|
91 |
|
|
almost_full : out std_logic;
|
92 |
|
|
full : out std_logic
|
93 |
128 |
jguarin200 |
);
|
94 |
|
|
end component;
|
95 |
129 |
jguarin200 |
|
96 |
|
|
component altsyncram
|
97 |
|
|
generic (
|
98 |
|
|
address_aclr_b : string;
|
99 |
|
|
address_reg_b : string;
|
100 |
|
|
clock_enable_input_a : string;
|
101 |
|
|
clock_enable_input_b : string;
|
102 |
|
|
clock_enable_output_b : string;
|
103 |
|
|
intended_device_family : string;
|
104 |
|
|
lpm_type : string;
|
105 |
|
|
numwords_a : natural;
|
106 |
|
|
numwords_b : natural;
|
107 |
|
|
operation_mode : string;
|
108 |
|
|
outdata_aclr_b : string;
|
109 |
|
|
outdata_reg_b : string;
|
110 |
|
|
power_up_uninitialized : string;
|
111 |
|
|
ram_block_type : string;
|
112 |
|
|
rdcontrol_reg_b : string;
|
113 |
|
|
read_during_write_mode_mixed_ports : string;
|
114 |
|
|
widthad_a : natural;
|
115 |
|
|
widthad_b : natural;
|
116 |
|
|
width_a : natural;
|
117 |
|
|
width_b : natural;
|
118 |
|
|
width_byteena_a : natural
|
119 |
|
|
);
|
120 |
|
|
port (
|
121 |
|
|
wren_a : in std_logic;
|
122 |
|
|
clock0 : in std_logic;
|
123 |
|
|
address_a : in std_logic_vector(widthad_a-1 downto 0);
|
124 |
|
|
address_b : in std_logic_vector(widthad_b-1 downto 0);
|
125 |
|
|
rden_b : in std_logic;
|
126 |
|
|
q_b : out std_logic_vector(width-1 downto 0);
|
127 |
|
|
data_a : in std_logic_vector(width-1 downto 0)
|
128 |
|
|
|
129 |
|
|
);
|
130 |
|
|
end component;
|
131 |
140 |
jguarin200 |
signal s0ext_wr_add_one_hot : std_logic_vector(external_writeable_blocks-1+1 downto 0); --! La se ñal extra es para la escritura de la cola de instrucciones.
|
132 |
129 |
jguarin200 |
signal s0ext_wr_add : std_logic_vector(external_writeable_widthad+widthadmemblock-1 downto 0);
|
133 |
130 |
jguarin200 |
signal s0ext_rd_add : std_logic_vector(external_readable_widthad-1 downto 0);
|
134 |
129 |
jguarin200 |
signal s0int_rd_add : std_logic_vector(widthadmemblock-1 downto 0);
|
135 |
138 |
jguarin200 |
signal s0ext_wr,s0ext_rd : std_logic;
|
136 |
130 |
jguarin200 |
signal s0ext_d : std_logic_vector(width-1 downto 0);
|
137 |
138 |
jguarin200 |
signal s0ext_rd_ack : std_logic_vector(external_readable_blocks-1 downto 0);
|
138 |
|
|
signal s0ext_q,sint_d : vectorblock08;
|
139 |
130 |
jguarin200 |
signal sint_rd_add : vectorblock02;
|
140 |
138 |
jguarin200 |
signal s1int_q : vectorblock12;
|
141 |
130 |
jguarin200 |
|
142 |
128 |
jguarin200 |
begin
|
143 |
|
|
|
144 |
140 |
jguarin200 |
--! Cola interna de producto punto, ubicada entre el pipe line aritméco.
|
145 |
|
|
q0q1 : scfifo --! Debe ir registrada la salida.
|
146 |
|
|
generic map ("ON",8,"OFF","Cyclone III","RAM_BLOCK_TYPE=M9K",16,"OFF","SCFIFO",64,4,"OFF","OFF","ON")
|
147 |
129 |
jguarin200 |
port map (dpfifo_rd,dpfifo_flush,dpfifo_empty,clk,dpfifo_q,dpfifo_wr,dpfifo_d,dpfifo_full);
|
148 |
140 |
jguarin200 |
|
149 |
|
|
--! Cola interna de normalización de vectores, ubicada entre el pipeline aritmé
|
150 |
|
|
qxqyqz : scfifo
|
151 |
138 |
jguarin200 |
generic map ("ON",23,"OFF","Cyclone III","RAM_BLOCK_TYPE=M9K",32,"OFF","SCFIFO",96,5,"OFF","OFF","ON")
|
152 |
129 |
jguarin200 |
port map (normfifo_rd,normfifo_flush,normfifo_empty,clk,normfifo_q,normfifo_wr,normfifo_d,normfifo_full);
|
153 |
140 |
jguarin200 |
|
154 |
|
|
--! Cola de instrucciones
|
155 |
|
|
qi : scfifo
|
156 |
138 |
jguarin200 |
generic map ("ON",31,"ON","Cyclone III","RAM_BLOCK_TYPE_M9K",32,"OFF","SCIFIFO",32,5,"ON","OFF","ON")
|
157 |
|
|
port map (instrfifo_rd,instrfifo_flush,instrfifo_empty,clk,instrfifo_q,instrfifo_wr,instrfifo_d,instrfifo_full);
|
158 |
128 |
jguarin200 |
|
159 |
140 |
jguarin200 |
--! Conectar los registros de lectura interna del bloque de operandos a los arreglos > abstracció:n de código, no influye en la sintesis del circuito.
|
160 |
130 |
jguarin200 |
sint_rd_add (0)<= int_rd_add(widthadmemblock-1 downto 0);
|
161 |
|
|
sint_rd_add (1)<= int_rd_add(2*widthadmemblock-1 downto widthadmemblock);
|
162 |
|
|
|
163 |
140 |
jguarin200 |
--! Instanciación de la cola de resultados.
|
164 |
130 |
jguarin200 |
results_blocks:
|
165 |
|
|
for i in 7 downto 0 generate
|
166 |
|
|
sint_d(i) <= int_d((i+1)*width-1 downto i*width);
|
167 |
138 |
jguarin200 |
resultsfifo : scfifo
|
168 |
|
|
generic map ("ON",511,"ON","Cyclone III","RAM_BLOCK_TYPE_M9K",512,"OFF","SCIFIFO",32,9,"ON","OFF","ON")
|
169 |
|
|
port map (s0ext_rd_ack(i),resultfifo_flush,resultfifo_empty(i),clk,s0ext_q(i),resultfifo_wr,sint_d(i),open,resultfifo_full(i));
|
170 |
130 |
jguarin200 |
end generate results_blocks;
|
171 |
|
|
|
172 |
140 |
jguarin200 |
--! Instanciación de la cola de resultados de salida.
|
173 |
130 |
jguarin200 |
operands_blocks:
|
174 |
129 |
jguarin200 |
for i in 11 downto 0 generate
|
175 |
130 |
jguarin200 |
int_q((i+1)*width-1 downto width*i) <= s1int_q(i);
|
176 |
129 |
jguarin200 |
operandsblock : altsyncram
|
177 |
130 |
jguarin200 |
generic map ("NONE","CLOCK0","BYPASS","BYPASS","BYPASS","Cyclone III","altsyncram",2**widthadmemblock,2**widthadmemblock,"DUAL_PORT","NONE","CLOCK0","FALSE","M9K","CLOCK0","OLD_DATA",widthadmemblock,widthadmemblock,width,width,1)
|
178 |
131 |
jguarin200 |
port map (s0ext_wr_add_one_hot(i),clk,s0ext_wr_add(widthadmemblock-1 downto 0),sint_rd_add((i/3) mod 2),'1',s1int_q(i),s0ext_d);
|
179 |
130 |
jguarin200 |
end generate operands_blocks;
|
180 |
128 |
jguarin200 |
|
181 |
140 |
jguarin200 |
--! Escritura en registros de operandos de entrada.
|
182 |
138 |
jguarin200 |
operands_block_proc: process (clk,ena)
|
183 |
129 |
jguarin200 |
begin
|
184 |
138 |
jguarin200 |
if clk'event and clk='1' and ena='1' then
|
185 |
130 |
jguarin200 |
--! Registro de entrada
|
186 |
129 |
jguarin200 |
s0ext_wr_add <= ext_wr_add;
|
187 |
|
|
s0ext_wr <= ext_wr;
|
188 |
138 |
jguarin200 |
s0ext_d <= ext_d;
|
189 |
129 |
jguarin200 |
end if;
|
190 |
|
|
end process;
|
191 |
140 |
jguarin200 |
|
192 |
|
|
--! Decodificación de señal escritura x bloque de memoria, selecciona la memoria en la que se va a escribir a partir de la dirección de entrada.
|
193 |
138 |
jguarin200 |
operands_block_comb: process (s0ext_wr_add,s0ext_wr)
|
194 |
130 |
jguarin200 |
begin
|
195 |
138 |
jguarin200 |
|
196 |
140 |
jguarin200 |
--! Etapa 0: Decodificacion de las señ:ales de escritura.Revisar el capitulo de bloques de memoria para chequear como está el pool de direcciones por bloques de vectores.
|
197 |
138 |
jguarin200 |
case s0ext_wr_add(external_writeable_widthad+widthadmemblock-1 downto widthadmemblock) is
|
198 |
140 |
jguarin200 |
when x"0" => s0ext_wr_add_one_hot <= '0'&x"00"&"000"&s0ext_wr;
|
199 |
|
|
when x"1" => s0ext_wr_add_one_hot <= '0'&x"00"&"00"&s0ext_wr&'0';
|
200 |
|
|
when x"2" => s0ext_wr_add_one_hot <= '0'&x"00"&'0'&s0ext_wr&"00";
|
201 |
|
|
when x"4" => s0ext_wr_add_one_hot <= '0'&x"00"&s0ext_wr&"000";
|
202 |
|
|
when x"5" => s0ext_wr_add_one_hot <= '0'&x"0"&"000"&s0ext_wr&x"0";
|
203 |
|
|
when x"6" => s0ext_wr_add_one_hot <= '0'&x"0"&"00"&s0ext_wr&'0'&x"0";
|
204 |
|
|
when x"8" => s0ext_wr_add_one_hot <= '0'&x"0"&'0'&s0ext_wr&"00"&x"0";
|
205 |
|
|
when x"9" => s0ext_wr_add_one_hot <= '0'&x"0"&s0ext_wr&"000"&x"0";
|
206 |
|
|
when x"A" => s0ext_wr_add_one_hot <= '0'&"000"&s0ext_wr&x"00";
|
207 |
|
|
when x"C" => s0ext_wr_add_one_hot <= '0'&"00"&s0ext_wr&'0'&x"00";
|
208 |
|
|
when x"D" => s0ext_wr_add_one_hot <= '0'&'0'&s0ext_wr&"00"&x"00";
|
209 |
|
|
when x"E" => s0ext_wr_add_one_hot <= '0'&s0ext_wr&"000"&x"00";
|
210 |
|
|
when others => s0ext_wr_add_one_hot <= '1'&x"000";
|
211 |
138 |
jguarin200 |
end case;
|
212 |
|
|
|
213 |
|
|
end process;
|
214 |
140 |
jguarin200 |
|
215 |
|
|
--! Decodificación para seleccionar que cola de resultados se conectar´ a la salida del RayTrac.
|
216 |
138 |
jguarin200 |
results_block_proc: process(clk,ena)
|
217 |
|
|
begin
|
218 |
|
|
if clk'event and clk='1' and ena='1' then
|
219 |
130 |
jguarin200 |
--!Registrar entrada
|
220 |
138 |
jguarin200 |
s0ext_rd_add <= ext_rd_add;
|
221 |
|
|
s0ext_rd <= ext_rd;
|
222 |
|
|
--!Etapa 0: Decodificar la cola que se va a mover (rdack! fifo showahead mode) y por ende leer ese dato.
|
223 |
|
|
case '0'&s0ext_rd_add is
|
224 |
|
|
when x"0" => ext_q <= s0ext_q(0);
|
225 |
|
|
when x"1" => ext_q <= s0ext_q(1);
|
226 |
|
|
when x"2" => ext_q <= s0ext_q(2);
|
227 |
|
|
when x"3" => ext_q <= s0ext_q(3);
|
228 |
|
|
when x"4" => ext_q <= s0ext_q(4);
|
229 |
|
|
when x"5" => ext_q <= s0ext_q(5);
|
230 |
|
|
when x"6" => ext_q <= s0ext_q(6);
|
231 |
|
|
when others => ext_q <= s0ext_q(7);
|
232 |
130 |
jguarin200 |
end case;
|
233 |
|
|
end if;
|
234 |
|
|
end process;
|
235 |
140 |
jguarin200 |
|
236 |
|
|
--! rdack decoder para las colas de resultados de salida.
|
237 |
138 |
jguarin200 |
results_block_proc_combinatorial_stage: process(s0ext_rd,s0ext_rd_add)
|
238 |
|
|
begin
|
239 |
|
|
case '0'&s0ext_rd_add is
|
240 |
|
|
when x"0" => s0ext_rd_ack <= x"0"&"000"&s0ext_rd;
|
241 |
|
|
when x"1" => s0ext_rd_ack <= x"0"&"00"&s0ext_rd&'0';
|
242 |
|
|
when x"2" => s0ext_rd_ack <= x"0"&"0"&s0ext_rd&"00";
|
243 |
|
|
when x"3" => s0ext_rd_ack <= x"0"&s0ext_rd&"000";
|
244 |
|
|
when x"4" => s0ext_rd_ack <= "000"&s0ext_rd&x"0";
|
245 |
|
|
when x"5" => s0ext_rd_ack <= "00"&s0ext_rd&'0'&x"0";
|
246 |
|
|
when x"6" => s0ext_rd_ack <= "0"&s0ext_rd&"00"&x"0";
|
247 |
|
|
when others => s0ext_rd_ack <= s0ext_rd&"000"&x"0";
|
248 |
|
|
end case;
|
249 |
|
|
end process;
|
250 |
128 |
jguarin200 |
end memblock_arch;
|
251 |
|
|
|