OpenCores
URL https://opencores.org/ocsvn/raytrac/raytrac/trunk

Subversion Repositories raytrac

[/] [raytrac/] [branches/] [fp_sgdma/] [raytrac.vhd] - Blame information for rev 256

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.