1 |
219 |
jguarin200 |
--! @file raytrac.vhd
|
2 |
|
|
--! @brief Sistema de Procesamiento Vectorial. La interface es compatible con el bus Avalon de Altera.
|
3 |
|
|
--! @author Julián Andrés Guarín Reyes
|
4 |
|
|
--------------------------------------------------------------
|
5 |
|
|
-- RAYTRAC
|
6 |
|
|
-- Author Julian Andres Guarin
|
7 |
|
|
-- raytrac.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 |
150 |
jguarin200 |
library ieee;
|
24 |
|
|
use ieee.std_logic_1164.all;
|
25 |
211 |
jguarin200 |
use ieee.std_logic_unsigned.all;
|
26 |
219 |
jguarin200 |
use work.arithpack.all;
|
27 |
150 |
jguarin200 |
|
28 |
211 |
jguarin200 |
library altera_mf;
|
29 |
|
|
use altera_mf.altera_mf_components.all;
|
30 |
|
|
|
31 |
|
|
library lpm;
|
32 |
|
|
use lpm.lpm_components.all;
|
33 |
|
|
|
34 |
|
|
|
35 |
217 |
jguarin200 |
entity raytrac is
|
36 |
211 |
jguarin200 |
generic (
|
37 |
|
|
wd : integer := 32;
|
38 |
|
|
fd : integer := 8; --! Result Fifo Depth = 2**fd =256
|
39 |
219 |
jguarin200 |
mb : integer := 4 --! Max Burst Length = 2**mb
|
40 |
211 |
jguarin200 |
);
|
41 |
150 |
jguarin200 |
port (
|
42 |
211 |
jguarin200 |
clk: in std_logic;
|
43 |
|
|
rst: in std_logic;
|
44 |
150 |
jguarin200 |
|
45 |
211 |
jguarin200 |
--! Avalon MM Slave
|
46 |
234 |
jguarin200 |
slave_address : in std_logic_vector(3 downto 0);
|
47 |
211 |
jguarin200 |
slave_read : in std_logic;
|
48 |
|
|
slave_write : in std_logic;
|
49 |
|
|
slave_readdata : out std_logic_vector(31 downto 0);
|
50 |
|
|
slave_writedata : in std_logic_vector(31 downto 0);
|
51 |
|
|
|
52 |
|
|
--! Avalon MM Master (Read & Write common signals)
|
53 |
|
|
master_address : out std_logic_vector(31 downto 0);
|
54 |
234 |
jguarin200 |
master_burstcount : out std_logic_vector(4 downto 0);
|
55 |
|
|
master_waitrequest : in std_logic;
|
56 |
150 |
jguarin200 |
|
57 |
211 |
jguarin200 |
--! Avalon MM Master (Read Stage)
|
58 |
|
|
master_read : out std_logic;
|
59 |
|
|
master_readdata : in std_logic_vector(31 downto 0);
|
60 |
234 |
jguarin200 |
master_readdatavalid : in std_logic;
|
61 |
202 |
jguarin200 |
|
62 |
211 |
jguarin200 |
--! Avalon MM Master (Write Stage)
|
63 |
|
|
master_write : out std_logic;
|
64 |
|
|
master_writedata : out std_logic_vector(31 downto 0);
|
65 |
150 |
jguarin200 |
|
66 |
211 |
jguarin200 |
--! Avalon IRQ
|
67 |
|
|
irq : out std_logic
|
68 |
150 |
jguarin200 |
|
69 |
211 |
jguarin200 |
|
70 |
|
|
|
71 |
150 |
jguarin200 |
);
|
72 |
|
|
end entity;
|
73 |
|
|
|
74 |
|
|
|
75 |
217 |
jguarin200 |
architecture raytrac_arch of raytrac is
|
76 |
211 |
jguarin200 |
|
77 |
229 |
jguarin200 |
|
78 |
211 |
jguarin200 |
--! Altera Compiler Directive, to avoid m9k autoinferring thanks to the guys at http://www.alteraforum.com/forum/archive/index.php/t-30784.html ....
|
79 |
230 |
jguarin200 |
attribute altera_attribute : string;
|
80 |
|
|
attribute altera_attribute of raytrac_arch : architecture is "-name AUTO_SHIFT_REGISTER_RECOGNITION OFF";
|
81 |
161 |
jguarin200 |
|
82 |
211 |
jguarin200 |
|
83 |
219 |
jguarin200 |
type registerblock is array (15 downto 0) of xfloat32;
|
84 |
211 |
jguarin200 |
type transferState is (IDLE,SINK,SOURCE);
|
85 |
231 |
jguarin200 |
type upload_chain is (UPVX,UPVY,UPVZ,SC,DMA);
|
86 |
219 |
jguarin200 |
type download_chain is (DWAX,DWAY,DWAZ,DWBX,DWBY,DWBZ,DWAXBX,DWAYBY,DWAZBZ);
|
87 |
202 |
jguarin200 |
|
88 |
211 |
jguarin200 |
constant reg_ctrl : integer:=00;
|
89 |
231 |
jguarin200 |
constant reg_vz : integer:=01;
|
90 |
|
|
constant reg_vy : integer:=02;
|
91 |
|
|
constant reg_vx : integer:=03;
|
92 |
|
|
constant reg_scalar : integer:=04;
|
93 |
|
|
constant reg_nfetch : integer:=05;
|
94 |
211 |
jguarin200 |
constant reg_outputcounter : integer:=06;
|
95 |
|
|
constant reg_inputcounter : integer:=07;
|
96 |
|
|
constant reg_fetchstart : integer:=08;
|
97 |
|
|
constant reg_sinkstart : integer:=09;
|
98 |
231 |
jguarin200 |
constant reg_ax : integer:=10;
|
99 |
|
|
constant reg_ay : integer:=11;
|
100 |
|
|
constant reg_az : integer:=12;
|
101 |
|
|
constant reg_bx : integer:=13;
|
102 |
|
|
constant reg_by : integer:=14;
|
103 |
|
|
constant reg_bz : integer:=15;
|
104 |
211 |
jguarin200 |
|
105 |
|
|
|
106 |
172 |
jguarin200 |
|
107 |
211 |
jguarin200 |
constant reg_ctrl_cmb : integer:=00; --! CMB bit : Combinatorial Instruction.
|
108 |
231 |
jguarin200 |
constant reg_ctrl_s : integer:=01; --! S bit of the DCS field.
|
109 |
|
|
constant reg_ctrl_c : integer:=02; --! C bit of the DCS field.
|
110 |
|
|
constant reg_ctrl_d : integer:=03; --! D bit of the DCS field.
|
111 |
202 |
jguarin200 |
|
112 |
211 |
jguarin200 |
constant reg_ctrl_sc : integer:=04; --! SC bit of the VTSC field.
|
113 |
|
|
constant reg_ctrl_vt : integer:=05; --! VT bit of the VTSC field.
|
114 |
217 |
jguarin200 |
constant reg_ctrl_dma : integer:=06; --! DMA bit.
|
115 |
211 |
jguarin200 |
constant reg_ctrl_flags_fc : integer:=07; --! Flood Condition Flag.
|
116 |
202 |
jguarin200 |
|
117 |
211 |
jguarin200 |
constant reg_ctrl_flags_dc : integer:=08; --! Drain Condition Flag.
|
118 |
|
|
constant reg_ctrl_flags_wp : integer:=09; --! Write on Memory Pending Flag.
|
119 |
|
|
constant reg_ctrl_flags_pp : integer:=10; --! Pipeline Pending Flag.
|
120 |
|
|
constant reg_ctrl_flags_pl : integer:=11; --! Load Parameter Pending Flag.
|
121 |
202 |
jguarin200 |
|
122 |
211 |
jguarin200 |
constant reg_ctrl_flags_dp : integer:=12; --! Data Pending flag.
|
123 |
|
|
constant reg_ctrl_flags_ap : integer:=13; --! Address Pending Flag.
|
124 |
|
|
constant reg_ctrl_rlsc : integer:=14; --! RLSC bit : Reload Load Sync Chain.
|
125 |
|
|
constant reg_ctrl_rom : integer:=15; --! ROM bit : Read Only Mode bit.
|
126 |
202 |
jguarin200 |
|
127 |
229 |
jguarin200 |
constant reg_ctrl_alb : integer:=16; --! Conditional Writing. A<B.
|
128 |
|
|
constant reg_ctrl_aeb : integer:=17; --! A==B.
|
129 |
|
|
constant reg_ctrl_ageb : integer:=18; --! A>=B.
|
130 |
211 |
jguarin200 |
constant reg_ctrl_irq : integer:=31; --! IRQ bit : Interrupt Request Signal.
|
131 |
231 |
jguarin200 |
|
132 |
|
|
--! Nfetch Reg Mask
|
133 |
|
|
constant reg_nfetch_high : integer:=11; --! NFETCH_HIGH : Higher bit to program the number of addresses to load in the interconnection.
|
134 |
211 |
jguarin200 |
|
135 |
|
|
|
136 |
|
|
--! Avalon MM Slave
|
137 |
229 |
jguarin200 |
|
138 |
211 |
jguarin200 |
signal sreg_block : registerblock;
|
139 |
|
|
signal sslave_read : std_logic;
|
140 |
|
|
signal sslave_write : std_logic;
|
141 |
219 |
jguarin200 |
signal sslave_writedata : std_logic_vector (wd-1 downto 0);
|
142 |
|
|
signal sslave_address : std_logic_vector (3 downto 0);
|
143 |
211 |
jguarin200 |
signal sslave_waitrequest : std_logic;
|
144 |
217 |
jguarin200 |
|
145 |
211 |
jguarin200 |
--! Avalon MM Master
|
146 |
|
|
signal smaster_write : std_logic;
|
147 |
|
|
signal smaster_read : std_logic;
|
148 |
202 |
jguarin200 |
|
149 |
211 |
jguarin200 |
--! State Machine and event signaling
|
150 |
|
|
signal sm : transferState;
|
151 |
|
|
|
152 |
230 |
jguarin200 |
signal sr_e : std_logic;
|
153 |
229 |
jguarin200 |
signal sr_ack : std_logic;
|
154 |
211 |
jguarin200 |
signal soutb_ack : std_logic;
|
155 |
|
|
|
156 |
|
|
|
157 |
229 |
jguarin200 |
|
158 |
211 |
jguarin200 |
signal soutb_d : std_logic_vector(wd-1 downto 0);
|
159 |
|
|
|
160 |
|
|
|
161 |
|
|
signal soutb_w : std_logic;
|
162 |
|
|
|
163 |
|
|
signal soutb_e : std_logic;
|
164 |
|
|
signal soutb_ae : std_logic;
|
165 |
|
|
signal soutb_af : std_logic;
|
166 |
|
|
signal soutb_usedw : std_logic_vector(fd-1 downto 0);
|
167 |
|
|
|
168 |
|
|
signal ssync_chain_1 : std_logic;
|
169 |
229 |
jguarin200 |
|
170 |
211 |
jguarin200 |
signal ssync_chain_pending : std_logic;
|
171 |
|
|
signal sfetch_data_pending : std_logic;
|
172 |
|
|
signal sload_add_pending : std_logic;
|
173 |
|
|
signal spipeline_pending : std_logic;
|
174 |
|
|
signal swrite_pending : std_logic;
|
175 |
|
|
signal sparamload_pending : std_logic;
|
176 |
|
|
signal sZeroTransit : std_logic;
|
177 |
|
|
|
178 |
|
|
|
179 |
|
|
--!Unload Control
|
180 |
|
|
signal supload_chain : upload_chain;
|
181 |
|
|
signal supload_start : upload_chain;
|
182 |
202 |
jguarin200 |
|
183 |
211 |
jguarin200 |
--!Señales de apoyo:
|
184 |
|
|
signal zero : std_logic_vector(31 downto 0);
|
185 |
|
|
|
186 |
|
|
--!High Register Bank Control Signals or AKA Load Sync Chain Control
|
187 |
|
|
signal sdownload_chain : download_chain;
|
188 |
|
|
signal sdownload_start : download_chain;
|
189 |
|
|
signal srestart_chain : std_logic;
|
190 |
|
|
--!State Machine Hysteresis Control Signals
|
191 |
|
|
signal sdrain_condition : std_logic;
|
192 |
|
|
signal sdrain_burstcount : std_logic_vector(mb downto 0);
|
193 |
231 |
jguarin200 |
signal sdata_fetch_counter : std_logic_vector(reg_nfetch_high downto 0);
|
194 |
211 |
jguarin200 |
signal sburstcount_sink : std_logic_vector(mb downto 0);
|
195 |
|
|
|
196 |
|
|
signal sflood_condition : std_logic;
|
197 |
|
|
signal sflood_burstcount : std_logic_vector(mb downto 0);
|
198 |
177 |
jguarin200 |
|
199 |
243 |
jguarin200 |
signal sp0,sp1,sp2 : std_logic_vector(31 downto 0);
|
200 |
219 |
jguarin200 |
--! Arithmetic Pipeline and Data Path Control
|
201 |
|
|
component ap_n_dpc
|
202 |
|
|
port (
|
203 |
243 |
jguarin200 |
|
204 |
|
|
p0,p1,p2 : out std_logic_vector(31 downto 0);
|
205 |
219 |
jguarin200 |
clk : in std_logic;
|
206 |
|
|
rst : in std_logic;
|
207 |
229 |
jguarin200 |
ax : in std_logic_vector(31 downto 0);
|
208 |
|
|
ay : in std_logic_vector(31 downto 0);
|
209 |
|
|
az : in std_logic_vector(31 downto 0);
|
210 |
|
|
bx : in std_logic_vector(31 downto 0);
|
211 |
|
|
by : in std_logic_vector(31 downto 0);
|
212 |
|
|
bz : in std_logic_vector(31 downto 0);
|
213 |
|
|
vx : out std_logic_vector(31 downto 0);
|
214 |
|
|
vy : out std_logic_vector(31 downto 0);
|
215 |
|
|
vz : out std_logic_vector(31 downto 0);
|
216 |
|
|
sc : out std_logic_vector(31 downto 0);
|
217 |
|
|
ack : in std_logic;
|
218 |
|
|
empty : out std_logic;
|
219 |
|
|
dcs : in std_logic_vector(2 downto 0); --! Bit con el identificador del bloque AB vs CD e identificador del sub bloque (A/B) o (C/D).
|
220 |
219 |
jguarin200 |
sync_chain_1 : in std_logic; --! Señal de dato valido que se va por toda la cadena de sincronizacion.
|
221 |
229 |
jguarin200 |
pipeline_pending : out std_logic --! Señal para indicar si hay datos en el pipeline aritmético.
|
222 |
219 |
jguarin200 |
);
|
223 |
|
|
end component;
|
224 |
|
|
|
225 |
230 |
jguarin200 |
--! Nets para la salida de la cola de resultados y entrada del multiplexor del upload state machine.
|
226 |
229 |
jguarin200 |
signal svx,svy,svz,ssc : std_logic_vector(31 downto 0);
|
227 |
219 |
jguarin200 |
|
228 |
211 |
jguarin200 |
begin
|
229 |
|
|
|
230 |
219 |
jguarin200 |
--!Zero agreggate
|
231 |
211 |
jguarin200 |
zero <= (others => '0');
|
232 |
|
|
|
233 |
|
|
|
234 |
219 |
jguarin200 |
--! *************************************************************************************************************************************************************************************************************************************************************
|
235 |
|
|
--! ARITHMETIC PIPELINE AND DATA PATH INSTANTIATION => => => => => => => => => => => => => => => => => => => => => => => => => => => => => => => => => => => => => => => => => => => => =>
|
236 |
|
|
--! *************************************************************************************************************************************************************************************************************************************************************
|
237 |
211 |
jguarin200 |
|
238 |
219 |
jguarin200 |
--! Arithpipeline and Datapath Control Instance
|
239 |
|
|
arithmetic_pipeline_and_datapath_controller : ap_n_dpc
|
240 |
|
|
port map (
|
241 |
243 |
jguarin200 |
p0 => sp0,
|
242 |
|
|
p1 => sp1,
|
243 |
|
|
p2 => sp2,
|
244 |
219 |
jguarin200 |
clk => clk,
|
245 |
|
|
rst => rst,
|
246 |
229 |
jguarin200 |
ax => sreg_block(reg_ax),
|
247 |
|
|
ay => sreg_block(reg_ay),
|
248 |
|
|
az => sreg_block(reg_az),
|
249 |
|
|
bx => sreg_block(reg_bx),
|
250 |
|
|
by => sreg_block(reg_by),
|
251 |
|
|
bz => sreg_block(reg_bz),
|
252 |
|
|
vx => svx,
|
253 |
|
|
vy => svy,
|
254 |
|
|
vz => svz,
|
255 |
|
|
sc => ssc,
|
256 |
|
|
ack => sr_ack,
|
257 |
|
|
empty => sr_e,
|
258 |
|
|
dcs => sreg_block(reg_ctrl)(reg_ctrl_d downto reg_ctrl_s),
|
259 |
219 |
jguarin200 |
sync_chain_1 => ssync_chain_1,
|
260 |
229 |
jguarin200 |
pipeline_pending => spipeline_pending
|
261 |
219 |
jguarin200 |
);
|
262 |
211 |
jguarin200 |
|
263 |
|
|
|
264 |
|
|
--! ******************************************************************************************************************************************************
|
265 |
|
|
--! TRANSFER CONTROL RTL CODE
|
266 |
|
|
--! ******************************************************************************************************************************************************
|
267 |
|
|
TRANSFER_CONTROL:
|
268 |
229 |
jguarin200 |
process(clk,rst,master_waitrequest,sm,soutb_ae,soutb_usedw,spipeline_pending,soutb_e,zero,soutb_af,sfetch_data_pending,sreg_block,sslave_write,sslave_address,sslave_writedata,ssync_chain_pending,smaster_read,smaster_write,sdata_fetch_counter,sload_add_pending,swrite_pending,sdownload_chain)
|
269 |
211 |
jguarin200 |
begin
|
270 |
202 |
jguarin200 |
|
271 |
211 |
jguarin200 |
--! Conexióln a señales externas.
|
272 |
|
|
irq <= sreg_block(reg_ctrl)(reg_ctrl_irq);
|
273 |
|
|
master_read <= smaster_read;
|
274 |
|
|
master_write <= smaster_write;
|
275 |
202 |
jguarin200 |
|
276 |
217 |
jguarin200 |
--! Direct Memory Access Selector.
|
277 |
150 |
jguarin200 |
|
278 |
217 |
jguarin200 |
|
279 |
|
|
|
280 |
211 |
jguarin200 |
--! ZERO_TRANSIT: Cuando todos los elementos de sincronización están en cero menos la cola de sincronización de carga de parametros.
|
281 |
|
|
sZeroTransit <= not(sload_add_pending or sfetch_data_pending or spipeline_pending or swrite_pending);
|
282 |
202 |
jguarin200 |
|
283 |
211 |
jguarin200 |
--! ELEMENTO DE SINCRONIZACION OUT QUEUE: Datos pendientes por cargar a la memoria a través de la interconexión
|
284 |
|
|
swrite_pending <= not(soutb_e);
|
285 |
202 |
jguarin200 |
|
286 |
|
|
|
287 |
211 |
jguarin200 |
--! ELEMENTO DE SINCRONIZACION DESCARGA DE DATOS: Hay datos pendientes por descargar desde la memoria a través de la interconexión.
|
288 |
231 |
jguarin200 |
if sdata_fetch_counter=zero(reg_nfetch_high downto 0) then
|
289 |
211 |
jguarin200 |
sfetch_data_pending <= '0';
|
290 |
|
|
else
|
291 |
|
|
sfetch_data_pending <= '1';
|
292 |
|
|
end if;
|
293 |
|
|
|
294 |
|
|
--! ELEMENTO DE SINCRONIZACION CARGA DE DIRECCIONES: Hay direcciones pendientes por cargar a la interconexión?
|
295 |
231 |
jguarin200 |
if sreg_block(reg_nfetch)(reg_nfetch_high downto 0)=zero(reg_nfetch_high downto 0) then
|
296 |
211 |
jguarin200 |
sload_add_pending <= '0';
|
297 |
|
|
else
|
298 |
|
|
sload_add_pending <= '1';
|
299 |
|
|
end if;
|
300 |
202 |
jguarin200 |
|
301 |
211 |
jguarin200 |
--! ELEMENTO DE SINCRONIZACION CARGA DE OPERANDOS: Se están cargando los operandos que serán operados en el pipeline aritmético.
|
302 |
219 |
jguarin200 |
if sdownload_chain /= DWAX and sdownload_chain /= DWAXBX then
|
303 |
211 |
jguarin200 |
sparamload_pending <= '1';
|
304 |
|
|
else
|
305 |
|
|
sparamload_pending <= '0';
|
306 |
|
|
end if;
|
307 |
|
|
|
308 |
|
|
--! Se debe iniciar una transacción de descarga de datos desde la memoria externa?
|
309 |
|
|
if soutb_af='0' and sload_add_pending='1' then
|
310 |
|
|
--! Flow Control : La saturación de la cola de resultados continuará si no está tan llena y además hay pendientes datos por ser descargados.
|
311 |
|
|
sflood_condition <= '1';
|
312 |
|
|
else
|
313 |
|
|
--! Flow Control : La saturación de la cola de resultados debe parar porque está casí llena.
|
314 |
|
|
sflood_condition <= '0';
|
315 |
|
|
end if;
|
316 |
237 |
jguarin200 |
|
317 |
|
|
if sreg_block(reg_nfetch)(reg_nfetch_high downto mb)/=zero(reg_nfetch_high downto mb) then
|
318 |
211 |
jguarin200 |
--! Flow Control: Si el número de descargas pendientes es mayor o igual al max burst length, entonces cargar max burst en el contador.
|
319 |
|
|
sflood_burstcount <= '1'&zero(mb-1 downto 0);
|
320 |
|
|
else
|
321 |
|
|
--! Flow Control: Si le número de descargas pendientes es inferior a Max Burst Count entonces cargar los bits menos significativos del registro de descargas pendientes.
|
322 |
237 |
jguarin200 |
sflood_burstcount <= '0'&sreg_block(reg_nfetch)(mb-1 downto 0);
|
323 |
211 |
jguarin200 |
end if;
|
324 |
202 |
jguarin200 |
|
325 |
211 |
jguarin200 |
--! Se debe iniciar una transacción de carga de datos hacia la memoria externa?
|
326 |
|
|
if soutb_ae='1' then
|
327 |
|
|
--! Flow Control : Cuando se esté drenando la cola de resultados, si la cola está casí vac&iaute;a, la longitud del burst serán los bits menos significativos del contador de la cola.
|
328 |
|
|
sdrain_burstcount <= soutb_usedw(mb downto 0);
|
329 |
|
|
--! Flow Control: El drenado de datos continuará si el número de datos en la cola bajo y no hay datos transitando por el pipeline, ni datos pendientes por cargar desde la memoria.
|
330 |
|
|
sdrain_condition <= not(sload_add_pending) and not(sfetch_data_pending) and not(spipeline_pending) and swrite_pending;
|
331 |
|
|
else
|
332 |
|
|
--! Flow Control: Cuando se esté drenando la cola de resultados, si la cola de tiene una cantidad de datos mayor al burst count entonces se hará una transacción de longitud equivalente al burst count.
|
333 |
|
|
sdrain_burstcount <= '1'&zero(mb-1 downto 0);
|
334 |
|
|
--! Flow Control: El drenado de datos continuará si el número de datos en la cola es mayor o igual a 2**mb O si hay muy pocos datos y no hay datos transitando por el pipeline.
|
335 |
|
|
sdrain_condition <= '1';
|
336 |
|
|
end if;
|
337 |
202 |
jguarin200 |
|
338 |
211 |
jguarin200 |
--! Restart param load chain
|
339 |
|
|
srestart_chain <= sreg_block(reg_ctrl)(reg_ctrl_irq) and sreg_block(reg_ctrl)(reg_ctrl_rlsc);
|
340 |
202 |
jguarin200 |
|
341 |
217 |
jguarin200 |
--! Data dumpster: Descaratar dato de upload una vez la interconexión haya enganchado el dato.
|
342 |
211 |
jguarin200 |
if sm=SINK and master_waitrequest='0' and smaster_write='1' then
|
343 |
|
|
soutb_ack <= '1';
|
344 |
|
|
else
|
345 |
|
|
soutb_ack <= '0';
|
346 |
|
|
end if;
|
347 |
202 |
jguarin200 |
|
348 |
217 |
jguarin200 |
|
349 |
|
|
|
350 |
211 |
jguarin200 |
--! Flow Control State Machine.
|
351 |
|
|
if rst=rstMasterValue then
|
352 |
|
|
|
353 |
|
|
--! State Machine
|
354 |
|
|
sm <= IDLE;
|
355 |
|
|
|
356 |
|
|
|
357 |
|
|
--! Master Write & Read Common Signals Reset Value
|
358 |
|
|
master_burstcount <= (others => '0');
|
359 |
|
|
master_address <= (others => '0');
|
360 |
|
|
sdata_fetch_counter <= (others => '0');
|
361 |
|
|
sburstcount_sink <= (others => '0');
|
362 |
150 |
jguarin200 |
|
363 |
211 |
jguarin200 |
--! Master Read Only Signals Reset Value
|
364 |
|
|
smaster_read <= '0';
|
365 |
|
|
|
366 |
|
|
--! Master Write Only Signals
|
367 |
|
|
smaster_write <= '0';
|
368 |
|
|
|
369 |
|
|
--! Reg Ctrl & Fetch address and writeaddress
|
370 |
|
|
--! Sinking address
|
371 |
|
|
sreg_block(reg_sinkstart) <= (others => '0');
|
372 |
|
|
--! Sourcing address
|
373 |
|
|
sreg_block(reg_fetchstart) <= (others => '0');
|
374 |
|
|
--! Control and Status Register
|
375 |
|
|
sreg_block(reg_ctrl) <= (others => '0');
|
376 |
|
|
--! Contador Overall
|
377 |
|
|
sreg_block(reg_inputcounter) <= (others => '0');
|
378 |
|
|
sreg_block(reg_outputcounter) <= (others => '0');
|
379 |
231 |
jguarin200 |
--! Address Fetch Counter
|
380 |
|
|
sreg_block(reg_nfetch) <= (others => '0');
|
381 |
211 |
jguarin200 |
|
382 |
|
|
|
383 |
|
|
elsif clk'event and clk='1' then
|
384 |
150 |
jguarin200 |
|
385 |
211 |
jguarin200 |
--! Nevermind the State, discount the incoming valid data counter.
|
386 |
|
|
sdata_fetch_counter <= sdata_fetch_counter-master_readdatavalid;
|
387 |
|
|
|
388 |
|
|
--! Debug Counter.
|
389 |
|
|
sreg_block(reg_inputcounter) <= sreg_block(reg_inputcounter) + master_readdatavalid;
|
390 |
|
|
sreg_block(reg_outputcounter) <= sreg_block(reg_outputcounter) + soutb_ack;
|
391 |
152 |
jguarin200 |
|
392 |
211 |
jguarin200 |
--! Flags
|
393 |
|
|
|
394 |
|
|
|
395 |
|
|
case sm is
|
396 |
|
|
when SOURCE =>
|
397 |
|
|
--! ******************************************************************************************************************************************************
|
398 |
|
|
--! Flooding the pipeline ........
|
399 |
|
|
--! ******************************************************************************************************************************************************
|
400 |
|
|
if smaster_read='0' then
|
401 |
|
|
if sflood_condition = '1' then
|
402 |
|
|
--! Flow Control: Hay suficiente espacio en el buffer de salida y hay descargas pendientes por hacer
|
403 |
|
|
smaster_read <= '1';
|
404 |
|
|
master_address <= sreg_block(reg_fetchstart);
|
405 |
|
|
master_burstcount <= sflood_burstcount;
|
406 |
|
|
sdata_fetch_counter <= sdata_fetch_counter+sflood_burstcount-master_readdatavalid;
|
407 |
|
|
--! Context Saving:
|
408 |
|
|
sreg_block(reg_fetchstart) <= sreg_block(reg_fetchstart) + (sflood_burstcount&"00");
|
409 |
231 |
jguarin200 |
sreg_block(reg_nfetch)(reg_nfetch_high downto 0) <= sreg_block(reg_nfetch)(reg_nfetch_high downto 0) - sflood_burstcount;
|
410 |
211 |
jguarin200 |
else
|
411 |
|
|
--! Flow Control : Cambiar al estado SINK, porque o está muy llena la cola de salida o no hay descargas pendientes por realizar.
|
412 |
|
|
sm <= SINK;
|
413 |
|
|
end if;
|
414 |
|
|
else --master_read=1;
|
415 |
|
|
if master_waitrequest='0' then
|
416 |
|
|
--! Las direcciones de lectura están cargadas. Terminar la transferencia.
|
417 |
|
|
smaster_read <= '0';
|
418 |
|
|
end if;
|
419 |
|
|
end if;
|
420 |
|
|
when SINK =>
|
421 |
|
|
|
422 |
|
|
--! ******************************************************************************************************************************************************
|
423 |
|
|
--! Draining the pipeline ........
|
424 |
|
|
--! ******************************************************************************************************************************************************
|
425 |
|
|
if smaster_write='0' then
|
426 |
|
|
|
427 |
|
|
if sdrain_condition='1' then
|
428 |
|
|
--! Flow Control : Hay muchos datos aun en la cola de resultados Ó la cola de resultados está casí vacía y no hay datos transitando en el pipeline aritm&eetico.
|
429 |
|
|
smaster_write <= '1';
|
430 |
|
|
master_address <= sreg_block(reg_sinkstart);
|
431 |
|
|
master_burstcount <= sdrain_burstcount;
|
432 |
150 |
jguarin200 |
|
433 |
211 |
jguarin200 |
--!Context Saving
|
434 |
|
|
sreg_block(reg_sinkstart) <= sreg_block(reg_sinkstart) + (sdrain_burstcount&"00");
|
435 |
|
|
sburstcount_sink <= sdrain_burstcount-1;
|
436 |
|
|
else
|
437 |
|
|
--! Flow Control: Son muy pocos los datos que hay en el buffer de salida y existen aun datos transitando en el resto del pipe ir al estado SOURCE.
|
438 |
|
|
if sZeroTransit='1' then
|
439 |
|
|
|
440 |
|
|
--! Flow Control: Finalizada la instrucción, generar una interrupción e ir al estado IDLE.
|
441 |
|
|
sm <= IDLE;
|
442 |
|
|
sreg_block(reg_ctrl)(reg_ctrl_irq) <= '1';
|
443 |
|
|
sreg_block(reg_ctrl)(reg_ctrl_rom) <= '0';
|
444 |
217 |
jguarin200 |
sreg_block(reg_ctrl)(reg_ctrl_flags_dc downto reg_ctrl_flags_fc) <= sdrain_condition & sflood_condition;
|
445 |
211 |
jguarin200 |
sreg_block(reg_ctrl)(reg_ctrl_flags_ap downto reg_ctrl_flags_wp) <= sload_add_pending & sfetch_data_pending & sparamload_pending & spipeline_pending & swrite_pending;
|
446 |
229 |
jguarin200 |
|
447 |
211 |
jguarin200 |
else
|
448 |
|
|
|
449 |
|
|
--! Flow Control: Cambiar a Source porque aun hay elementos transitando.
|
450 |
|
|
sm <= SOURCE;
|
451 |
|
|
end if;
|
452 |
|
|
|
453 |
|
|
end if;
|
454 |
|
|
else --!smaster_write=1
|
455 |
|
|
if master_waitrequest = '0' then
|
456 |
|
|
|
457 |
|
|
--! Descartar datos : revisar antes de este proceso secuencial la parte combinatoria (Data Dumpster).
|
458 |
|
|
|
459 |
|
|
|
460 |
|
|
if sburstcount_sink/=zero(mb downto 0) then
|
461 |
|
|
|
462 |
|
|
--! Datos pendientes por transmitir aun en el burst. Restar uno
|
463 |
|
|
sburstcount_sink <= sburstcount_sink-1;
|
464 |
|
|
else
|
465 |
|
|
|
466 |
|
|
--! No escribir mas. Finalizar la transmisión
|
467 |
|
|
smaster_write <= '0';
|
468 |
|
|
|
469 |
|
|
--! Si no hay transito de dato se con terminada la instrucción siempre que el estado de control de flujo esté sidera
|
470 |
|
|
if sZeroTransit='1' then
|
471 |
|
|
|
472 |
|
|
--! Flow Control: Finalizada la instrucción, generar una interrupción e ir al estado IDLE.
|
473 |
|
|
sm <= IDLE;
|
474 |
|
|
sreg_block(reg_ctrl)(reg_ctrl_irq) <= '1';
|
475 |
|
|
sreg_block(reg_ctrl)(reg_ctrl_rom) <= '0';
|
476 |
217 |
jguarin200 |
sreg_block(reg_ctrl)(reg_ctrl_flags_dc downto reg_ctrl_flags_fc) <= sdrain_condition & sflood_condition;
|
477 |
211 |
jguarin200 |
sreg_block(reg_ctrl)(reg_ctrl_flags_ap downto reg_ctrl_flags_wp) <= sload_add_pending & sfetch_data_pending & sparamload_pending & spipeline_pending & swrite_pending;
|
478 |
|
|
|
479 |
|
|
end if;
|
480 |
|
|
end if;
|
481 |
|
|
end if;
|
482 |
|
|
end if;
|
483 |
|
|
|
484 |
237 |
jguarin200 |
when IDLE =>
|
485 |
|
|
|
486 |
211 |
jguarin200 |
--! ******************************************************************************************************************************************************
|
487 |
|
|
--! Programming the pipeline
|
488 |
|
|
--! ******************************************************************************************************************************************************
|
489 |
|
|
--! El registro de control en sus campos fetch e irq, es escribile solo cuando estamos en estado IDLE.
|
490 |
|
|
if sslave_write='1' then
|
491 |
|
|
case sslave_address is
|
492 |
|
|
when x"0" =>
|
493 |
|
|
--! Solo se permitira escribir en el registro de control si no hay una interrupción activa o si la hay solamente si se esta intentando desactivar la interrupci´n
|
494 |
|
|
if sreg_block(reg_ctrl)(reg_ctrl_irq)='0' or sslave_writedata(reg_ctrl_irq)='0' then
|
495 |
237 |
jguarin200 |
sreg_block(reg_ctrl)<= sslave_writedata;
|
496 |
211 |
jguarin200 |
end if;
|
497 |
231 |
jguarin200 |
when x"5" => sreg_block(reg_nfetch) <= sslave_writedata;
|
498 |
211 |
jguarin200 |
when x"6" => sreg_block(reg_outputcounter) <= sslave_writedata;
|
499 |
|
|
when x"7" => sreg_block(reg_inputcounter) <= sslave_writedata;
|
500 |
|
|
when x"8" => sreg_block(reg_fetchstart) <= sslave_writedata;
|
501 |
|
|
when x"9" => sreg_block(reg_sinkstart) <= sslave_writedata;
|
502 |
|
|
when others => null;
|
503 |
|
|
end case;
|
504 |
|
|
else
|
505 |
|
|
|
506 |
|
|
if sZeroTransit='0' then
|
507 |
|
|
|
508 |
|
|
|
509 |
|
|
--! Flow Control: Existe un número de descargas programadas por el sistema, comenzar a realizarlas.
|
510 |
|
|
--! Ir al estado Source.
|
511 |
|
|
sm <= SOURCE;
|
512 |
|
|
sreg_block(reg_ctrl)(reg_ctrl_rom) <= '1';
|
513 |
219 |
jguarin200 |
|
514 |
|
|
else
|
515 |
|
|
sreg_block(reg_ctrl)(reg_ctrl_rom) <= '0';
|
516 |
|
|
|
517 |
211 |
jguarin200 |
end if;
|
518 |
|
|
end if;
|
519 |
|
|
end case;
|
520 |
|
|
end if;
|
521 |
|
|
end process;
|
522 |
|
|
--! ******************************************************************************************************************************************************
|
523 |
|
|
--! FLOW CONTROL RTL CODE
|
524 |
|
|
--! ******************************************************************************************************************************************************
|
525 |
229 |
jguarin200 |
--! buffer de salida
|
526 |
211 |
jguarin200 |
--! ******************************************************************************************************************************************************
|
527 |
|
|
output_buffer:scfifo
|
528 |
|
|
generic map (almost_empty_value => 2**mb,almost_full_value => (2**fd)-52, lpm_widthu => fd, lpm_numwords => 2**fd, lpm_showahead => "ON", lpm_width => 32, overflow_checking => "ON", underflow_checking => "ON", use_eab => "ON")
|
529 |
|
|
port map (empty => soutb_e, aclr => '0', clock => clk, rdreq => soutb_ack, wrreq => soutb_w, q => master_writedata, usedw => soutb_usedw, almost_full => soutb_af, almost_empty => soutb_ae, data => soutb_d);
|
530 |
|
|
--! ******************************************************************************************************************************************************
|
531 |
|
|
--! PROCESO DE CONTROL DE FLUJO ENTRE EL BUFFER DE RESULTADOS Y EL BUFFER DE SALIDA
|
532 |
|
|
--! ******************************************************************************************************************************************************
|
533 |
|
|
|
534 |
|
|
FLOW_CONTROL_OUTPUT_STAGE:
|
535 |
229 |
jguarin200 |
process (clk,rst,master_readdata, master_readdatavalid,sr_e,sreg_block(reg_ctrl)(reg_ctrl_vt downto reg_ctrl_sc),sm,supload_chain,zero,ssync_chain_pending,supload_start)
|
536 |
211 |
jguarin200 |
begin
|
537 |
|
|
|
538 |
|
|
|
539 |
|
|
--! Compute initial State.
|
540 |
|
|
|
541 |
|
|
--! Escribir en el output buffer.
|
542 |
217 |
jguarin200 |
if supload_chain=DMA then
|
543 |
|
|
--! Modo DMA escribir los datos de entrada directamente en el buffer.
|
544 |
|
|
soutb_w <= master_readdatavalid;
|
545 |
|
|
else
|
546 |
|
|
--!Modo Arithmetic Pipeline
|
547 |
229 |
jguarin200 |
soutb_w <= not(sr_e);
|
548 |
217 |
jguarin200 |
end if;
|
549 |
211 |
jguarin200 |
|
550 |
|
|
--! Control de lectura de la cola de resultados.
|
551 |
229 |
jguarin200 |
if sr_e='0' then
|
552 |
211 |
jguarin200 |
--!Hay datos en la cola de resultados.
|
553 |
219 |
jguarin200 |
if (supload_chain=UPVZ and sreg_block(reg_ctrl)(reg_ctrl_sc)='0') or supload_chain=SC then
|
554 |
211 |
jguarin200 |
--!Se transfiere el ultimo componente vectorial y no se estan cargando resultados escalares.
|
555 |
229 |
jguarin200 |
sr_ack <= '1';
|
556 |
219 |
jguarin200 |
else
|
557 |
229 |
jguarin200 |
sr_ack <= '0';
|
558 |
211 |
jguarin200 |
end if;
|
559 |
|
|
else
|
560 |
229 |
jguarin200 |
sr_ack <= '0';
|
561 |
211 |
jguarin200 |
end if;
|
562 |
|
|
|
563 |
217 |
jguarin200 |
|
564 |
211 |
jguarin200 |
--! Decodificar que salida de la cola de resultados se conecta a la entrada del otput buffer
|
565 |
217 |
jguarin200 |
--! DMA Path Control: Si se encuentra habilitado el modo dma entonces conectar la entrada del buffer de salida a la interconexión
|
566 |
211 |
jguarin200 |
case supload_chain is
|
567 |
219 |
jguarin200 |
when UPVX =>
|
568 |
229 |
jguarin200 |
soutb_d <= svx;
|
569 |
219 |
jguarin200 |
when UPVY =>
|
570 |
229 |
jguarin200 |
soutb_d <= svy;
|
571 |
219 |
jguarin200 |
when UPVZ =>
|
572 |
229 |
jguarin200 |
soutb_d <= svz;
|
573 |
211 |
jguarin200 |
when SC =>
|
574 |
229 |
jguarin200 |
soutb_d <= ssc;
|
575 |
217 |
jguarin200 |
when DMA =>
|
576 |
|
|
soutb_d <= master_readdata;
|
577 |
211 |
jguarin200 |
end case;
|
578 |
|
|
|
579 |
|
|
|
580 |
|
|
case sreg_block(reg_ctrl)(reg_ctrl_vt downto reg_ctrl_sc) is
|
581 |
|
|
when "01" =>
|
582 |
|
|
supload_start <= SC;
|
583 |
|
|
when others =>
|
584 |
219 |
jguarin200 |
supload_start <= UPVX;
|
585 |
211 |
jguarin200 |
end case;
|
586 |
|
|
|
587 |
|
|
|
588 |
|
|
--! Máquina de estados para el width adaptation RES(128) -> OUTPUTBUFFER(32).
|
589 |
|
|
if rst=rstMasterValue then
|
590 |
219 |
jguarin200 |
supload_chain <= UPVX;
|
591 |
217 |
jguarin200 |
elsif clk'event and clk='1' and sreg_block(reg_ctrl)(reg_ctrl_dma)='0' then
|
592 |
|
|
--! Modo de operación normal.
|
593 |
211 |
jguarin200 |
case supload_chain is
|
594 |
219 |
jguarin200 |
when UPVX =>
|
595 |
229 |
jguarin200 |
if sr_e='1' then
|
596 |
211 |
jguarin200 |
supload_chain <= supload_start;
|
597 |
|
|
else
|
598 |
219 |
jguarin200 |
supload_chain <= UPVY;
|
599 |
211 |
jguarin200 |
end if;
|
600 |
219 |
jguarin200 |
when UPVY =>
|
601 |
|
|
supload_chain <= UPVZ;
|
602 |
|
|
when UPVZ =>
|
603 |
211 |
jguarin200 |
if sreg_block(reg_ctrl)(reg_ctrl_sc)='0' then
|
604 |
219 |
jguarin200 |
supload_chain <= UPVX;
|
605 |
211 |
jguarin200 |
else
|
606 |
|
|
supload_chain <= SC;
|
607 |
|
|
end if;
|
608 |
217 |
jguarin200 |
when SC|DMA =>
|
609 |
211 |
jguarin200 |
supload_chain <= supload_start;
|
610 |
217 |
jguarin200 |
|
611 |
211 |
jguarin200 |
end case;
|
612 |
217 |
jguarin200 |
|
613 |
|
|
elsif clk'event and clk='1' then
|
614 |
|
|
--! Modo DMA
|
615 |
|
|
supload_chain <= DMA;
|
616 |
211 |
jguarin200 |
end if;
|
617 |
|
|
|
618 |
|
|
|
619 |
|
|
end process;
|
620 |
|
|
--! ******************************************************************************************************************************************************
|
621 |
|
|
--! PROCESO DE CONTROL DE FLUJO ENTRE LA ENTRADA DESDE LA INTERCONEXI&OACUTE;N Y LOS PARAMETROS DE ENTRADA EN EL PIPELINE ARITMETICO
|
622 |
|
|
--! ******************************************************************************************************************************************************
|
623 |
|
|
FLOW_CONTROL_INPUT_STAGE:
|
624 |
217 |
jguarin200 |
process(clk,rst,master_readdatavalid,master_readdata,sreg_block(reg_ctrl)(reg_ctrl_dma downto reg_ctrl_s),sslave_write,sslave_address,supload_chain)
|
625 |
211 |
jguarin200 |
begin
|
626 |
|
|
--! Está ocurriendo un evento de transición del estado TX al estado FETCH: Programar el enganche de parámetros que vienen de la interconexión.
|
627 |
219 |
jguarin200 |
--! Mirar como es la carga inicial. Si es Normalizacion o Magnitud (dcs=110) entonces cargar DWAXBX de lo contrario solo DWAX.
|
628 |
211 |
jguarin200 |
case sreg_block(reg_ctrl)(reg_ctrl_d downto reg_ctrl_s) is
|
629 |
221 |
jguarin200 |
when "110" => sdownload_start <= DWAXBX;
|
630 |
|
|
when others => sdownload_start <= DWAX;
|
631 |
211 |
jguarin200 |
end case;
|
632 |
|
|
if rst=rstMasterValue then
|
633 |
|
|
ssync_chain_1 <= '0';
|
634 |
219 |
jguarin200 |
sdownload_chain <= DWAX;
|
635 |
211 |
jguarin200 |
for i in reg_bz downto reg_ax loop
|
636 |
|
|
sreg_block(i) <= (others => '0');
|
637 |
|
|
end loop;
|
638 |
|
|
elsif clk'event and clk='1' then
|
639 |
|
|
ssync_chain_1 <= '0';
|
640 |
217 |
jguarin200 |
if master_readdatavalid='1' and sreg_block(reg_ctrl)(reg_ctrl_dma)='0' then
|
641 |
211 |
jguarin200 |
--! El dato en la interconexión es valido, se debe enganchar.
|
642 |
|
|
case sdownload_chain is
|
643 |
219 |
jguarin200 |
when DWAX | DWAXBX =>
|
644 |
211 |
jguarin200 |
--! Cargar el operando correspondiente al componente "X" del vector "A"
|
645 |
|
|
ssync_chain_1 <= '0';
|
646 |
|
|
sreg_block(reg_ax) <= master_readdata;
|
647 |
219 |
jguarin200 |
if sdownload_start = DWAXBX then
|
648 |
211 |
jguarin200 |
--! Operación Unaria por ejemplo magnitud de un vector
|
649 |
|
|
--! Escribir en el registro bx adicionalmente.
|
650 |
|
|
sreg_block(reg_bx) <= master_readdata;
|
651 |
|
|
--! El siguiente estado es cargar el componente "Y" de del operando a ejecutar.
|
652 |
219 |
jguarin200 |
sdownload_chain <= DWAYBY;
|
653 |
211 |
jguarin200 |
else
|
654 |
|
|
--! Operación de dos operandos. Por ejemplo Producto Cruz.
|
655 |
|
|
--! El siguiente estado es cargar el vector "Y" del operando "A".
|
656 |
219 |
jguarin200 |
sdownload_chain <= DWAY;
|
657 |
211 |
jguarin200 |
end if;
|
658 |
219 |
jguarin200 |
when DWAY | DWAYBY =>
|
659 |
211 |
jguarin200 |
sreg_block(reg_ay) <= master_readdata;
|
660 |
|
|
ssync_chain_1 <= '0';
|
661 |
219 |
jguarin200 |
if sdownload_chain = DWAYBY then
|
662 |
211 |
jguarin200 |
sreg_block(reg_by) <= master_readdata;
|
663 |
219 |
jguarin200 |
sdownload_chain <= DWAZBZ;
|
664 |
211 |
jguarin200 |
else
|
665 |
219 |
jguarin200 |
sdownload_chain <= DWAZ;
|
666 |
211 |
jguarin200 |
end if;
|
667 |
219 |
jguarin200 |
when DWAZ | DWAZBZ =>
|
668 |
211 |
jguarin200 |
sreg_block(reg_az) <= master_readdata;
|
669 |
219 |
jguarin200 |
if sdownload_chain=DWAZBZ then
|
670 |
211 |
jguarin200 |
ssync_chain_1 <= '1';
|
671 |
|
|
sreg_block(reg_bz) <= master_readdata;
|
672 |
219 |
jguarin200 |
sdownload_chain <= DWAXBX;
|
673 |
211 |
jguarin200 |
else
|
674 |
|
|
ssync_chain_1 <= '0';
|
675 |
219 |
jguarin200 |
sdownload_chain <= DWBX;
|
676 |
211 |
jguarin200 |
end if;
|
677 |
219 |
jguarin200 |
when DWBX =>
|
678 |
211 |
jguarin200 |
ssync_chain_1 <= '0';
|
679 |
|
|
sreg_block(reg_bx) <= master_readdata;
|
680 |
219 |
jguarin200 |
sdownload_chain <= DWBY;
|
681 |
|
|
when DWBY =>
|
682 |
211 |
jguarin200 |
ssync_chain_1 <= '0';
|
683 |
|
|
sreg_block(reg_by) <= master_readdata;
|
684 |
219 |
jguarin200 |
sdownload_chain <= DWBZ;
|
685 |
|
|
when DWBZ =>
|
686 |
211 |
jguarin200 |
sreg_block(reg_bz) <= master_readdata;
|
687 |
|
|
ssync_chain_1 <= '1';
|
688 |
|
|
if sreg_block(reg_ctrl)(reg_ctrl_cmb)='1' then
|
689 |
219 |
jguarin200 |
sdownload_chain <= DWBX;
|
690 |
211 |
jguarin200 |
else
|
691 |
219 |
jguarin200 |
sdownload_chain <= DWAX;
|
692 |
211 |
jguarin200 |
end if;
|
693 |
|
|
when others =>
|
694 |
|
|
null;
|
695 |
|
|
end case;
|
696 |
|
|
|
697 |
|
|
if srestart_chain='1' then
|
698 |
|
|
sdownload_chain <= sdownload_start;
|
699 |
|
|
end if;
|
700 |
|
|
|
701 |
|
|
end if;
|
702 |
|
|
end if;
|
703 |
|
|
end process;
|
704 |
|
|
--! *************************************************************************************************************************************************************************************************************************************************************
|
705 |
|
|
--! AVALON MEMORY MAPPED MASTER FINISHED
|
706 |
|
|
--! *************************************************************************************************************************************************************************************************************************************************************
|
707 |
|
|
--! *************************************************************************************************************************************************************************************************************************************************************
|
708 |
|
|
--! AVALON MEMORY MAPPED SLAVE BEGINS => => => => => => => => => => => => => => => => => => => => => => => => => => => => => => => => => => => => => => => => => => => => => => =>
|
709 |
|
|
--! *************************************************************************************************************************************************************************************************************************************************************
|
710 |
|
|
--! Master Slave Process: Proceso para la escritura y lectura de registros desde el NIOS II.
|
711 |
|
|
low_register_bank:
|
712 |
229 |
jguarin200 |
process (clk,rst,sreg_block,soutb_w,supload_chain)
|
713 |
211 |
jguarin200 |
begin
|
714 |
|
|
if rst=rstMasterValue then
|
715 |
231 |
jguarin200 |
for i in reg_scalar downto reg_vz loop
|
716 |
211 |
jguarin200 |
sreg_block(i) <= (others => '0');
|
717 |
|
|
end loop;
|
718 |
|
|
|
719 |
|
|
slave_readdata <= (others => '0');
|
720 |
|
|
sslave_address <= (others => '0');
|
721 |
|
|
sslave_writedata <= (others => '0');
|
722 |
|
|
sslave_write <= '0';
|
723 |
|
|
sslave_read <= '0';
|
724 |
|
|
elsif clk'event and clk='1' then
|
725 |
|
|
|
726 |
|
|
|
727 |
|
|
sslave_address <= slave_address;
|
728 |
|
|
sslave_write <= slave_write;
|
729 |
|
|
sslave_read <= slave_read;
|
730 |
|
|
sslave_writedata <= slave_writedata;
|
731 |
229 |
jguarin200 |
|
732 |
243 |
jguarin200 |
sreg_block(reg_vz) <= sp0;
|
733 |
|
|
sreg_block(reg_vy) <= sp1;
|
734 |
|
|
sreg_block(reg_vx) <= sp2;
|
735 |
|
|
for i in reg_scalar downto reg_scalar loop
|
736 |
211 |
jguarin200 |
if sslave_address=i then
|
737 |
|
|
if sslave_write='1' then
|
738 |
|
|
sreg_block(i) <= sslave_writedata;
|
739 |
|
|
end if;
|
740 |
|
|
end if;
|
741 |
|
|
end loop;
|
742 |
|
|
for i in 15 downto 0 loop
|
743 |
|
|
if sslave_address=i then
|
744 |
|
|
if sslave_read='1' then
|
745 |
|
|
slave_readdata <= sreg_block(i);
|
746 |
|
|
end if;
|
747 |
|
|
end if;
|
748 |
|
|
end loop;
|
749 |
|
|
end if;
|
750 |
|
|
end process;
|
751 |
243 |
jguarin200 |
|
752 |
211 |
jguarin200 |
--! *************************************************************************************************************************************************************************************************************************************************************
|
753 |
|
|
--! AVALON MEMORY MAPPED SLAVE FINISHED
|
754 |
|
|
--! *************************************************************************************************************************************************************************************************************************************************************
|
755 |
|
|
--!---------|-----------|-------------------------------------------------------------------------------------------------------------------
|
756 |
217 |
jguarin200 |
--! Control Register (reg_ctrl) BASE_ADDRESS + 0x0 |
|
757 |
211 |
jguarin200 |
--!---------|-----------|-------------------------------------------------------------------------------------------------------------------
|
758 |
|
|
--! Bit No. | Nombre | Descripción |
|
759 |
|
|
--!---------|-----------|-------------------------------------------------------------------------------------------------------------------
|
760 |
217 |
jguarin200 |
--! 0 | cmb (rw) | 1: La operación es combinatoria, por lo tanto cargan los primeros 3 valores en el Operando A y el |
|
761 |
|
|
--! | | de vectores en el operando B. |
|
762 |
211 |
jguarin200 |
--! | | 0: La operación no es combinatoria, se cargan vectores en los operandos A y B. |
|
763 |
|
|
--!---------|-----------|-------------------------------------------------------------------------------------------------------------------|
|
764 |
|
|
--! | | Configuración del Datapath, Interconexión del Pipeline Aritmético y Cadena de Carga |
|
765 |
|
|
--! | | Dependiendo del valor de estos 3 bits se configura la operación a ejecutar. |
|
766 |
|
|
--! | | |
|
767 |
|
|
--! [3:1] | dcs (rw) | 011: Producto Cruz |
|
768 |
|
|
--! | | 000: Suma Vectorial |
|
769 |
|
|
--! | | 001: Resta Vectorial |
|
770 |
|
|
--! | | 110: Normalización Vectorial y cálculo de Magnitud Vectorial |
|
771 |
|
|
--! | | 100: Producto Punto |
|
772 |
|
|
--! | | 111: Producto Simple |
|
773 |
|
|
--!---------|-----------|-------------------------------------------------------------------------------------------------------------------|
|
774 |
|
|
--! [5:4] | vtsc (rw) | 00: Solo leer los resultados vectoriales. |
|
775 |
|
|
--! | | 01: Solo leer los resultados escalares. |
|
776 |
|
|
--! | | 10: Solo leer los resultados vectoriales. |
|
777 |
|
|
--! | | 11: Leer los resultados escalares y vectoriales. |
|
778 |
|
|
--!---------|-----------|-------------------------------------------------------------------------------------------------------------------|
|
779 |
217 |
jguarin200 |
--! 6 | dma (rw) | 1: Modo DMA: Los datos que ingresan se leen desde la dirección FETCHSTART (BASE+0x08) y se escriben en |
|
780 |
|
|
--! | | la dirección SINKSTART (BASE+0x09). |
|
781 |
|
|
--! | | 0: Modo Arithmetic Pipeline: Los datos ingresan en grupos de a 6 valores para 2 vectores de 3 valores cada uno,|
|
782 |
|
|
--! | | cuando se usa en modo uno a uno (cmb=1), ó en grupos de 3 valores para 1 vector de 3 valores, |
|
783 |
|
|
--! | | pero con el operando A fijado con el valor de la primera carga de valores en modo combinatorio (cmb=1). |
|
784 |
|
|
--! | | De la misma manera que en modo DMA se cargan los operandos en la dirección FETCHSTART y se escriben |
|
785 |
|
|
--! | | los resultados en la dirección SINKSTART. |
|
786 |
|
|
--!---------|-----------|-------------------------------------------------------------------------------------------------------------------|
|
787 |
|
|
--! 7 | flag_fc(r)| 1: Al momento de generar una interrupción este bit se coloca en 1 si se cumplen las condiciones de |
|
788 |
|
|
--! | | descarga de datos de la memoria (revisar el net signal sflood_condition). Si se encuentra en uno se |
|
789 |
|
|
--! | | trataría de una inconsistencia puesto que la interrupción se dispara una vez se ha terminado |
|
790 |
|
|
--! | | de ejecutar una instrucción y el que la bandera este en uno significa que hay transacciones de |
|
791 |
|
|
--! | | descarga de datos desde la memoria pendientes. |
|
792 |
|
|
--! | | |
|
793 |
|
|
--! | | En general que cualquiera de estas banderas se coloque en uno es una señalizacion de error, puesto |
|
794 |
|
|
--! | | que una vez se ha terminado de ejecutar una instrucción no deben haber transacciones pendientes. |
|
795 |
|
|
--! | | La razón de ser de estas banderas es hacer depuración del hardware mas que del software. |
|
796 |
|
|
--! | | |
|
797 |
|
|
--! | | 0: Flood Condition off. |
|
798 |
|
|
--!---------|-----------|-------------------------------------------------------------------------------------------------------------------|
|
799 |
|
|
--! 8 | flag_dc(r)| 1: Error, la instrucción ya se ejecutó y hay datos transitando en el buffer de salida aun. |
|
800 |
|
|
--! | | 0: Drain Condition off. |
|
801 |
|
|
--!---------|-----------|-------------------------------------------------------------------------------------------------------------------|
|
802 |
|
|
--! 9 | wp(r) | 1: Error, la instrucción ya se ejecutó y hay datos transitando en el buffer de salida aun. |
|
803 |
|
|
--! | | 0: Write on Memory not pending. |
|
804 |
|
|
--!---------|-----------|-------------------------------------------------------------------------------------------------------------------|
|
805 |
|
|
--! 10 | pp(r) | 1: Error, la instrucción ya se ejecutón y hay datos transitando el pipeline aritmético. |
|
806 |
|
|
--! | | 0: Pipeline not pending. |
|
807 |
|
|
--!---------|-----------|-------------------------------------------------------------------------------------------------------------------|
|
808 |
|
|
--! 11 | pl(r) | 1: La carga de parametros no se completó. Esto por lo general pasa cuando uno va a realizar una |
|
809 |
|
|
--! | | operaci´n combinatoria y solo cargo el primer operando, el A, esto puede ocurrir porque por ejemplo |
|
810 |
|
|
--! | | se puede desear sumar un conjunto de vectores a un vector de referencia. Este vector de referencia puede |
|
811 |
|
|
--! | | estar en un area de memoria distinta, que el resto de los vectores. Por lo tanto el pseudo codigo para |
|
812 |
|
|
--! | | ejecutar una operación de este tipo seria: |
|
813 |
|
|
--! | | |
|
814 |
|
|
--! | | ld vect,add,cmb; //Resultados solo vectoriales, ejecutar operación suma en modo combinatorio |
|
815 |
|
|
--! | | ld &A; //Cargar la direccion del Vector A. |
|
816 |
|
|
--! | | ld 3; //Cargar 3 valores, o sea el Vector A. |
|
817 |
|
|
--! | | wait int; //Esperar a que se ejecute la interrupcion. Una vez se termine de ejecutar si la bandera|
|
818 |
|
|
--! | | //pl está en uno se vuelve a comenzar y se deshecha el dato que hay como |
|
819 |
|
|
--! | | //parámetro. Para este ejemplo se asume que está en uno |
|
820 |
|
|
--! | | ld &B; //Cargar la dirección donde se encuentran los vectores B |
|
821 |
|
|
--! | | ld &C; //Cargar la dirección donde se exribiran los resultados. |
|
822 |
|
|
--! | | ld 24; //Cargar los siguientes 24 valores a partir de &B correspondiente a 8 vectores |
|
823 |
|
|
--! | | //ejecutando 8 sumas vectoriales que se escribirín a apartir de &C |
|
824 |
|
|
--! | | wait int; //Esperar a que termine la ejecución de las sumas. |
|
825 |
|
|
--! | | |
|
826 |
|
|
--! | | 0: Los operandos se cargaron integros se cargo del todo y no hubo que desechar parametros. |
|
827 |
|
|
--!---------|-----------|-------------------------------------------------------------------------------------------------------------------|
|
828 |
|
|
--! 12 | dp (r) | 1: Error, la instrucción se termino y aun hay datos pendientes por ser descargados |
|
829 |
|
|
--! | | 0: No hay datos pendientes por ser descargados. |
|
830 |
|
|
--!---------|-----------|-------------------------------------------------------------------------------------------------------------------|
|
831 |
|
|
--! 13 | ap (r) | 1: Carga de direcciones en la interconexión aún está pendiente y la instrucció ya |
|
832 |
|
|
--! | | se ejecutó |
|
833 |
|
|
--! | | 0: No hay direcciones pendientes por cargar. |
|
834 |
|
|
--!---------|-----------|-------------------------------------------------------------------------------------------------------------------|
|
835 |
211 |
jguarin200 |
--! 14 | rlsc (rw) | 1: El sistema está configurado para resetear la recarga sincronizada de parámetros una vez |
|
836 |
|
|
--! | | concluya la instrucción |
|
837 |
|
|
--! | | |
|
838 |
217 |
jguarin200 |
--! | | 0: El sistema está configurado para no resetear la cadena de sincronización de carga. |
|
839 |
211 |
jguarin200 |
--!---------|-----------|-------------------------------------------------------------------------------------------------------------------|
|
840 |
217 |
jguarin200 |
--! 15 | rom (r) | 1: Los registros solo se pueden leer no se pueden escribir. Etsado SINK y SOURCE |
|
841 |
211 |
jguarin200 |
--! | | 0: Los registros se pueden leer y escribir. |
|
842 |
|
|
--!---------|-----------|-------------------------------------------------------------------------------------------------------------------|
|
843 |
|
|
--! [30:16] | nfetch(rw)| Cantidad de direcciones a cargar en la interconexón para realizar la posterior descarga de datos de la |
|
844 |
|
|
--! | | memoria al RayTrac.
|
845 |
|
|
--!---------|-----------|-------------------------------------------------------------------------------------------------------------------|
|
846 |
|
|
--! 31 | irq | 1: Evento de interrupción. El usuario debe hacer clear de este bit para dar la interrupci&o;n por |
|
847 |
|
|
--! | | por atendida. Este bit se pone en uno cuando el sistema pasa de estado TX a FETCH o FETCH a TX. |
|
848 |
|
|
--! | | |
|
849 |
|
|
--! | | 0: El RayTrac se encuentra en operación Normal. |
|
850 |
|
|
--!---------|-----------|-------------------------------------------------------------------------------------------------------------------
|
851 |
217 |
jguarin200 |
--! Result Vector Z component (reg_vz) BASE_ADDRESS + 0x4 |
|
852 |
211 |
jguarin200 |
--!---------|-----------|-------------------------------------------------------------------------------------------------------------------|
|
853 |
217 |
jguarin200 |
--! Result Vector Y component (reg_vy) BASE_ADDRESS + 0x8 |
|
854 |
211 |
jguarin200 |
--!---------|-----------|-------------------------------------------------------------------------------------------------------------------|
|
855 |
217 |
jguarin200 |
--! Result Vector X component (reg_vx) BASE_ADDRESS + 0xC |
|
856 |
211 |
jguarin200 |
--!---------|-----------|-------------------------------------------------------------------------------------------------------------------|
|
857 |
217 |
jguarin200 |
--! Result Vector Scalar component (reg_scalar) BASE_ADDRESS + 0x10 |
|
858 |
211 |
jguarin200 |
--!---------|-----------|-------------------------------------------------------------------------------------------------------------------|
|
859 |
231 |
jguarin200 |
--! Scratch Vector 00 (reg_nfetch) BASE_ADDRESS + 0x14 |
|
860 |
211 |
jguarin200 |
--!---------|-----------|-------------------------------------------------------------------------------------------------------------------|
|
861 |
217 |
jguarin200 |
--! output Data Counter (reg_outputcounter) BASE_ADDRESS + 0x18 |
|
862 |
211 |
jguarin200 |
--!---------|-----------|-------------------------------------------------------------------------------------------------------------------|
|
863 |
217 |
jguarin200 |
--! Input Data Counter (reg_inputcounter) BASE_ADDRESS + 0x1C |
|
864 |
|
|
--!---------|-----------|-------------------------------------------------------------------------------------------------------------------|
|
865 |
|
|
--! Data Fetch Start Address (reg_fetchstart) BASE_ADDRESS + 0x20 |
|
866 |
|
|
--!---------|-----------|-------------------------------------------------------------------------------------------------------------------|
|
867 |
|
|
--! Data Write Start Address (reg_sinkstart) BASE_ADDRESS + 0x24 |
|
868 |
|
|
--!---------|-----------|-------------------------------------------------------------------------------------------------------------------|
|
869 |
219 |
jguarin200 |
--! Parameter AX component (reg_ax) BASE_ADDRESS + 0x28 |
|
870 |
217 |
jguarin200 |
--!---------|-----------|-------------------------------------------------------------------------------------------------------------------|
|
871 |
|
|
--! Parameter Ay component (reg_ay) BASE_ADDRESS + 0x2C |
|
872 |
|
|
--!---------|-----------|-------------------------------------------------------------------------------------------------------------------|
|
873 |
|
|
--! Parameter Az component (reg_az) BASE_ADDRESS + 0x30 |
|
874 |
|
|
--!---------|-----------|-------------------------------------------------------------------------------------------------------------------|
|
875 |
|
|
--! Parameter Bx component (reg_bx) BASE_ADDRESS + 0x34 |
|
876 |
|
|
--!---------|-----------|-------------------------------------------------------------------------------------------------------------------|
|
877 |
|
|
--! Parameter By component (reg_by) BASE_ADDRESS + 0x38 |
|
878 |
|
|
--!---------|-----------|-------------------------------------------------------------------------------------------------------------------|
|
879 |
|
|
--! Parameter Bz component (reg_bz) BASE_ADDRESS + 0x3C |
|
880 |
|
|
--!---------|-----------|-------------------------------------------------------------------------------------------------------------------|
|
881 |
|
|
|
882 |
|
|
|
883 |
|
|
|
884 |
|
|
|
885 |
|
|
|
886 |
|
|
|
887 |
|
|
end architecture;
|
888 |
|
|
|