1 |
128 |
jguarin200 |
--! @file memblock.vhd
|
2 |
|
|
--! @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 |
129 |
jguarin200 |
clk,dpfifo_flush,normfifo_flush,dpfifo_rd,normfifo_rd,dpfifo_wr,normfifo_wr : in std_logic;
|
41 |
|
|
dpfifo_empty, normfifo_empty, dpfifo_full, normfifo_full : out std_logic;
|
42 |
133 |
jguarin200 |
instrfifo_flush,instrfifo_rd,instrfifo_wr: in std_logic;
|
43 |
|
|
instrfifo_empty,instrfifo_full : out std_logic;
|
44 |
131 |
jguarin200 |
ext_rd,ext_wr,int_wr: in std_logic;
|
45 |
129 |
jguarin200 |
ext_wr_add : in std_logic_vector(external_writeable_widthad+widthadmemblock-1 downto 0);
|
46 |
|
|
ext_rd_add : in std_logic_vector(external_readable_widthad+widthadmemblock-1 downto 0);
|
47 |
|
|
ext_d: in std_logic_vector(width-1 downto 0);
|
48 |
|
|
int_d : in std_logic_vector(external_readable_blocks*width-1 downto 0);
|
49 |
|
|
ext_q : out std_logic_vector(width-1 downto 0);
|
50 |
|
|
int_q : out std_logic_vector(external_writeable_blocks*width-1 downto 0);
|
51 |
130 |
jguarin200 |
int_wr_add : in std_logic_vector(widthadmemblock-1 downto 0);
|
52 |
|
|
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 |
|
|
intended_device_family :string;
|
71 |
|
|
lpm_hint :string;
|
72 |
|
|
lpm_numwords :natural;
|
73 |
|
|
lpm_showahead :string;
|
74 |
|
|
lpm_type :string;
|
75 |
|
|
lpm_width :natural;
|
76 |
|
|
lpm_widthu :natural;
|
77 |
|
|
overflow_checking :string;
|
78 |
|
|
underflow_checking :string;
|
79 |
|
|
use_eab :string
|
80 |
|
|
);
|
81 |
|
|
port(
|
82 |
|
|
rdreq : in std_logic;
|
83 |
129 |
jguarin200 |
aclr : in std_logic;
|
84 |
128 |
jguarin200 |
empty : out std_logic;
|
85 |
|
|
clock : in std_logic;
|
86 |
130 |
jguarin200 |
q : out std_logic_vector(lpm_width-1 downto 0);
|
87 |
128 |
jguarin200 |
wrreq : in std_logic;
|
88 |
130 |
jguarin200 |
data : in std_logic_vector(lpm_width-1 downto 0);
|
89 |
128 |
jguarin200 |
full : out std_logic
|
90 |
|
|
);
|
91 |
|
|
end component;
|
92 |
129 |
jguarin200 |
|
93 |
|
|
component altsyncram
|
94 |
|
|
generic (
|
95 |
|
|
address_aclr_b : string;
|
96 |
|
|
address_reg_b : string;
|
97 |
|
|
clock_enable_input_a : string;
|
98 |
|
|
clock_enable_input_b : string;
|
99 |
|
|
clock_enable_output_b : string;
|
100 |
|
|
intended_device_family : string;
|
101 |
|
|
lpm_type : string;
|
102 |
|
|
numwords_a : natural;
|
103 |
|
|
numwords_b : natural;
|
104 |
|
|
operation_mode : string;
|
105 |
|
|
outdata_aclr_b : string;
|
106 |
|
|
outdata_reg_b : string;
|
107 |
|
|
power_up_uninitialized : string;
|
108 |
|
|
ram_block_type : string;
|
109 |
|
|
rdcontrol_reg_b : string;
|
110 |
|
|
read_during_write_mode_mixed_ports : string;
|
111 |
|
|
widthad_a : natural;
|
112 |
|
|
widthad_b : natural;
|
113 |
|
|
width_a : natural;
|
114 |
|
|
width_b : natural;
|
115 |
|
|
width_byteena_a : natural
|
116 |
|
|
);
|
117 |
|
|
port (
|
118 |
|
|
wren_a : in std_logic;
|
119 |
|
|
clock0 : in std_logic;
|
120 |
|
|
address_a : in std_logic_vector(widthad_a-1 downto 0);
|
121 |
|
|
address_b : in std_logic_vector(widthad_b-1 downto 0);
|
122 |
|
|
rden_b : in std_logic;
|
123 |
|
|
q_b : out std_logic_vector(width-1 downto 0);
|
124 |
|
|
data_a : in std_logic_vector(width-1 downto 0)
|
125 |
|
|
|
126 |
|
|
);
|
127 |
|
|
end component;
|
128 |
|
|
signal s0ext_wr_add_one_hot : std_logic_vector(external_writeable_blocks-1 downto 0);
|
129 |
|
|
signal s0ext_wr_add : std_logic_vector(external_writeable_widthad+widthadmemblock-1 downto 0);
|
130 |
130 |
jguarin200 |
signal s0ext_rd_add : std_logic_vector(external_readable_widthad-1 downto 0);
|
131 |
129 |
jguarin200 |
signal s0int_rd_add : std_logic_vector(widthadmemblock-1 downto 0);
|
132 |
|
|
signal s0int_wr_add : std_logic_vector(widthadmemblock-1 downto 0);
|
133 |
|
|
signal s0ext_wr : std_logic;
|
134 |
130 |
jguarin200 |
signal s0ext_d : std_logic_vector(width-1 downto 0);
|
135 |
|
|
|
136 |
|
|
signal s1ext_rd_add : std_logic_vector(external_readable_widthad-1 downto 0);
|
137 |
|
|
signal s1ext_q,sint_d : vectorblock08;
|
138 |
|
|
signal sint_rd_add : vectorblock02;
|
139 |
|
|
signal s1int_q : vectorblock12;
|
140 |
|
|
|
141 |
128 |
jguarin200 |
begin
|
142 |
|
|
|
143 |
|
|
dpfifo : scfifo
|
144 |
130 |
jguarin200 |
generic map ("OFF","Cyclone III","RAM_BLOCK_TYPE=M9K",9,"OFF","SCFIFO",64,4,"OFF","OFF","ON")
|
145 |
129 |
jguarin200 |
port map (dpfifo_rd,dpfifo_flush,dpfifo_empty,clk,dpfifo_q,dpfifo_wr,dpfifo_d,dpfifo_full);
|
146 |
128 |
jguarin200 |
normfifo : scfifo
|
147 |
130 |
jguarin200 |
generic map ("OFF","Cyclone III","RAM_BLOCK_TYPE=M9K",26,"OFF","SCFIFO",96,5,"OFF","OFF","ON")
|
148 |
129 |
jguarin200 |
port map (normfifo_rd,normfifo_flush,normfifo_empty,clk,normfifo_q,normfifo_wr,normfifo_d,normfifo_full);
|
149 |
133 |
jguarin200 |
instrfifo : scififo
|
150 |
|
|
generic map ("OFF","Cyclone III","RAM_BLOCK_TYPE_M9K",64,"OFF","SCIFIFO",32,6,"OFF","OFF","ON")
|
151 |
|
|
port map (instrfifo_rd,instrfifo_flush,instrfifo_empty,clk,instrfifo_q,instrfifo_wr,instrfifo_d,instrifo_full);
|
152 |
128 |
jguarin200 |
|
153 |
133 |
jguarin200 |
|
154 |
130 |
jguarin200 |
sint_rd_add (0)<= int_rd_add(widthadmemblock-1 downto 0);
|
155 |
|
|
sint_rd_add (1)<= int_rd_add(2*widthadmemblock-1 downto widthadmemblock);
|
156 |
|
|
|
157 |
|
|
results_blocks:
|
158 |
|
|
for i in 7 downto 0 generate
|
159 |
|
|
sint_d(i) <= int_d((i+1)*width-1 downto i*width);
|
160 |
|
|
resultsblock : altsyncram
|
161 |
|
|
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)
|
162 |
131 |
jguarin200 |
port map (int_wr,clk,int_wr_add,ext_rd_add(widthadmemblock-1 downto 0),ext_rd,s1ext_q(i),sint_d(i));
|
163 |
130 |
jguarin200 |
end generate results_blocks;
|
164 |
|
|
|
165 |
|
|
operands_blocks:
|
166 |
129 |
jguarin200 |
for i in 11 downto 0 generate
|
167 |
130 |
jguarin200 |
int_q((i+1)*width-1 downto width*i) <= s1int_q(i);
|
168 |
129 |
jguarin200 |
operandsblock : altsyncram
|
169 |
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)
|
170 |
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);
|
171 |
130 |
jguarin200 |
end generate operands_blocks;
|
172 |
128 |
jguarin200 |
|
173 |
130 |
jguarin200 |
|
174 |
|
|
operands_block_proc: process (clk)
|
175 |
129 |
jguarin200 |
begin
|
176 |
|
|
if clk'event and clk='1' then
|
177 |
130 |
jguarin200 |
--! Registro de entrada
|
178 |
129 |
jguarin200 |
s0ext_wr_add <= ext_wr_add;
|
179 |
|
|
s0ext_wr <= ext_wr;
|
180 |
130 |
jguarin200 |
s0ext_d <= ext_d;
|
181 |
|
|
--! Etapa 0: Decodificacion de las señ:ales de escritura.
|
182 |
|
|
case s0ext_wr_add(external_writeable_widthad+widthadmemblock-1 downto widthadmemblock) is
|
183 |
|
|
when x"0" => s0ext_wr_add_one_hot <= x"00"&"000"&s0ext_wr;
|
184 |
|
|
when x"1" => s0ext_wr_add_one_hot <= x"00"&"00"&s0ext_wr&'0';
|
185 |
|
|
when x"2" => s0ext_wr_add_one_hot <= x"00"&'0'&s0ext_wr&"00";
|
186 |
|
|
when x"3" => s0ext_wr_add_one_hot <= x"00"&s0ext_wr&"000";
|
187 |
|
|
when x"4" => s0ext_wr_add_one_hot <= x"0"&"000"&s0ext_wr&x"0";
|
188 |
|
|
when x"5" => s0ext_wr_add_one_hot <= x"0"&"00"&s0ext_wr&'0'&x"0";
|
189 |
|
|
when x"6" => s0ext_wr_add_one_hot <= x"0"&'0'&s0ext_wr&"00"&x"0";
|
190 |
|
|
when x"7" => s0ext_wr_add_one_hot <= x"0"&s0ext_wr&"000"&x"0";
|
191 |
|
|
when x"8" => s0ext_wr_add_one_hot <= "000"&s0ext_wr&x"00";
|
192 |
|
|
when x"9" => s0ext_wr_add_one_hot <= "00"&s0ext_wr&'0'&x"00";
|
193 |
|
|
when x"A" => s0ext_wr_add_one_hot <= '0'&s0ext_wr&"00"&x"00";
|
194 |
|
|
when others => s0ext_wr_add_one_hot <= s0ext_wr&"000"&x"00";
|
195 |
129 |
jguarin200 |
end case;
|
196 |
|
|
end if;
|
197 |
|
|
end process;
|
198 |
130 |
jguarin200 |
results_block_proc: process(clk)
|
199 |
|
|
begin
|
200 |
|
|
if clk'event and clk='1' then
|
201 |
|
|
--!Registrar entrada
|
202 |
|
|
s0ext_rd_add <= ext_rd_add(external_readable_widthad+widthadmemblock-1 downto widthadmemblock);
|
203 |
|
|
--!Etapa 0: Leer memorias
|
204 |
|
|
s1ext_rd_add <= s0ext_rd_add;
|
205 |
|
|
--!Etapa 1: Seleccionar dato a leer;
|
206 |
|
|
case '0'&s1ext_rd_add is
|
207 |
|
|
when x"0" => ext_q <= s1ext_q(0);
|
208 |
|
|
when x"1" => ext_q <= s1ext_q(1);
|
209 |
|
|
when x"2" => ext_q <= s1ext_q(2);
|
210 |
|
|
when x"3" => ext_q <= s1ext_q(3);
|
211 |
|
|
when x"4" => ext_q <= s1ext_q(4);
|
212 |
|
|
when x"5" => ext_q <= s1ext_q(5);
|
213 |
|
|
when x"6" => ext_q <= s1ext_q(6);
|
214 |
|
|
when others => ext_q <= s1ext_q(7);
|
215 |
|
|
end case;
|
216 |
|
|
end if;
|
217 |
|
|
end process;
|
218 |
128 |
jguarin200 |
end memblock_arch;
|
219 |
|
|
|