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

Subversion Repositories raytrac

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

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 150 jguarin200
library ieee;
2
use ieee.std_logic_1164.all;
3 211 jguarin200
use ieee.std_logic_unsigned.all;
4 150 jguarin200
 
5 211 jguarin200
library altera_mf;
6
use altera_mf.altera_mf_components.all;
7
 
8
library lpm;
9
use lpm.lpm_components.all;
10
 
11
 
12
entity slave_template is
13
        generic (
14
                wd      :       integer := 32;
15
                sl      :       integer := 5;   --! Arith Sync Chain Long 2**sl
16
                ln      :       integer := 12;  --! Max Transfer Length = 2**ln = n_outputbuffers * 256
17
                fd      :       integer := 8;   --! Result Fifo Depth = 2**fd =256
18
                mb      :       integer := 4;   --! Max Burst Length = 2**mb            
19
                nr      :       integer := 4    --! Number of Registers = 2**nr
20
        );
21 150 jguarin200
        port (
22 211 jguarin200
                clk:    in std_logic;
23
                rst:    in std_logic;
24 150 jguarin200
 
25 211 jguarin200
                --! Avalon MM Slave
26
                slave_address                   :       in      std_logic_vector(3 downto 0);
27
                slave_read                              :       in      std_logic;
28
                slave_write                             :       in      std_logic;
29
                slave_readdata                  :       out std_logic_vector(31 downto 0);
30
                slave_writedata                 :       in      std_logic_vector(31 downto 0);
31
 
32
                --! Avalon MM Master (Read & Write common signals)      
33
                master_address                  :       out std_logic_vector(31 downto 0);
34
                master_burstcount               :       out std_logic_vector(4 downto 0);
35
                master_waitrequest              :       in      std_logic;
36 150 jguarin200
 
37 211 jguarin200
                --! Avalon MM Master (Read Stage)
38
                master_read                             :       out     std_logic;
39
                master_readdata                 :       in      std_logic_vector(31 downto 0);
40
                master_readdatavalid    :       in      std_logic;
41 202 jguarin200
 
42 211 jguarin200
                --! Avalon MM Master (Write Stage)
43
                master_write                    :       out     std_logic;
44
                master_writedata                :       out std_logic_vector(31 downto 0);
45 150 jguarin200
 
46 211 jguarin200
                --! Avalon IRQ
47
                irq                                             :       out std_logic
48 150 jguarin200
 
49 211 jguarin200
 
50
 
51 150 jguarin200
        );
52
end entity;
53
 
54
 
55 211 jguarin200
architecture slave_template_arch of slave_template is
56
 
57
        --! Altera Compiler Directive, to avoid m9k autoinferring thanks to the guys at http://www.alteraforum.com/forum/archive/index.php/t-30784.html .... 
58
        attribute altera_attribute : string;
59
        attribute altera_attribute of slave_template_arch : architecture is "-name AUTO_SHIFT_REGISTER_RECOGNITION OFF";
60 161 jguarin200
 
61 211 jguarin200
 
62
        subtype xfloat32                is std_logic_vector(wd-1 downto 0);
63
        type    registerblock   is array ((2**nr)-1 downto 0) of xfloat32;
64
        type    transferState   is (IDLE,SINK,SOURCE);
65 202 jguarin200
 
66 211 jguarin200
        constant rstMasterValue : std_logic :='0';
67 202 jguarin200
 
68
 
69 211 jguarin200
        constant reg_ctrl                               :       integer:=00;
70
        constant reg_vz                                 :       integer:=01;
71
        constant reg_vy                                 :       integer:=02;
72
        constant reg_vx                                 :       integer:=03;
73
        constant reg_scalar                             :       integer:=04;
74
        constant reg_scratch00                  :       integer:=05;
75
        constant reg_outputcounter              :       integer:=06;
76
        constant reg_inputcounter               :       integer:=07;
77
        constant reg_fetchstart                 :       integer:=08;
78
        constant reg_sinkstart                  :       integer:=09;
79
        constant reg_ax                                 :       integer:=10;
80
        constant reg_ay                                 :       integer:=11;
81
        constant reg_az                                 :       integer:=12;
82
        constant reg_bx                                 :       integer:=13;
83
        constant reg_by                                 :       integer:=14;
84
        constant reg_bz                                 :       integer:=15;
85
 
86
 
87 172 jguarin200
 
88 211 jguarin200
        constant reg_ctrl_cmb                   :       integer:=00;    --! CMB bit : Combinatorial Instruction.
89
        constant reg_ctrl_s                             :       integer:=01;    --! S bit of the DCS field.
90
        constant reg_ctrl_c                             :       integer:=02;    --! C bit of the DCS field.
91
        constant reg_ctrl_d                             :       integer:=03;    --! D bit of the DCS field.
92 202 jguarin200
 
93 211 jguarin200
        constant reg_ctrl_sc                    :       integer:=04;    --! SC bit of the VTSC field.
94
        constant reg_ctrl_vt                    :       integer:=05;    --! VT bit of the VTSC field.
95
        constant reg_ctrl_flags_ae              :       integer:=06;    --! Almost Empty Flag.
96
        constant reg_ctrl_flags_fc              :       integer:=07;    --! Flood Condition Flag.
97 202 jguarin200
 
98 211 jguarin200
        constant reg_ctrl_flags_dc              :       integer:=08;    --! Drain Condition Flag.       
99
        constant reg_ctrl_flags_wp              :       integer:=09;    --! Write on Memory Pending Flag.
100
        constant reg_ctrl_flags_pp              :       integer:=10;    --! Pipeline Pending Flag.
101
        constant reg_ctrl_flags_pl              :       integer:=11;    --! Load Parameter Pending Flag.
102 202 jguarin200
 
103 211 jguarin200
        constant reg_ctrl_flags_dp              :       integer:=12;    --! Data Pending flag.
104
        constant reg_ctrl_flags_ap              :       integer:=13;    --! Address Pending Flag.
105
        constant reg_ctrl_rlsc                  :       integer:=14;    --! RLSC bit : Reload Load Sync Chain.
106
        constant reg_ctrl_rom                   :       integer:=15;    --! ROM bit : Read Only Mode bit.
107 202 jguarin200
 
108 211 jguarin200
        constant reg_ctrl_nfetch_low    :       integer:=16;    --! NFETCH_LOW : Lower bit to program the number of addresses to load in the interconnection.
109
        constant reg_ctrl_nfetch_high   :       integer:=30;    --! NFETCH_HIGH : Higher bit to program the number of addresses to load in the interconnection. 
110
        constant reg_ctrl_irq                   :       integer:=31;    --! IRQ bit : Interrupt Request Signal.
111
 
112
 
113
        --! Avalon MM Slave
114
        signal  sreg_block                      :       registerblock;
115
        signal  sslave_read                     :       std_logic;
116
        signal  sslave_write            :       std_logic;
117
        signal  sslave_writedata        :       xfloat32;
118
        signal  sslave_address          :       std_logic_vector        (nr-1 downto 0);
119
        signal  sslave_waitrequest      :       std_logic;
120
        --! Avalon MM Master
121
        signal  smaster_write           :       std_logic;
122
        signal  smaster_read            :       std_logic;
123 202 jguarin200
 
124 211 jguarin200
 
125
        --! State Machine and event signaling
126
        signal sm                                       :       transferState;
127
 
128
        signal sres_ack                         :       std_logic;
129
        signal soutb_ack                        :       std_logic;
130
 
131
        signal sres_q                           :       std_logic_vector(4*wd-1 downto 0);
132
 
133
        signal sres_d                           :       std_logic_vector(4*wd-1 downto 0);
134
        signal soutb_d                          :       std_logic_vector(wd-1 downto 0);
135
 
136
 
137
        signal sres_w                           :       std_logic;
138
        signal soutb_w                          :       std_logic;
139
 
140
        signal sres_e                           :       std_logic;
141
        signal soutb_e                          :       std_logic;
142
        signal soutb_ae                         :       std_logic;
143
        signal soutb_af                         :       std_logic;
144
 
145
        signal soutb_usedw                      :       std_logic_vector(fd-1 downto 0);
146
 
147
        signal ssync_chain_1            :       std_logic;
148
        signal ssync_chain_pending      :       std_logic;
149
        signal sfetch_data_pending      :       std_logic;
150
        signal sload_add_pending        :       std_logic;
151
        signal spipeline_pending        :       std_logic;
152
        signal swrite_pending           :   std_logic;
153
        signal sparamload_pending       :       std_logic;
154
        signal sZeroTransit                     :       std_logic;
155
 
156
 
157
        --!Unload Control
158
        type upload_chain is (VX,VY,VZ,SC);
159
        signal supload_chain    : upload_chain;
160
        signal supload_start    : upload_chain;
161 202 jguarin200
 
162 211 jguarin200
        --!Señales de apoyo:
163
        signal zero : std_logic_vector(31 downto 0);
164
 
165
        --!High Register Bank Control Signals or AKA Load Sync Chain Control
166
        type download_chain is (AX,AY,AZ,BX,BY,BZ,AXBX,AYBY,AZBZ);
167
        signal sdownload_chain  : download_chain;
168
        signal sdownload_start  : download_chain;
169
        signal srestart_chain   : std_logic;
170
        --!State Machine Hysteresis Control Signals
171
        signal sdrain_condition         : std_logic;
172
        signal sdrain_burstcount        : std_logic_vector(mb downto 0);
173
        signal sdata_fetch_counter      : std_logic_vector(reg_ctrl_nfetch_high downto reg_ctrl_nfetch_low);
174
        signal sburstcount_sink         : std_logic_vector(mb downto 0);
175
 
176
        signal sflood_condition         : std_logic;
177
        signal sflood_burstcount        : std_logic_vector(mb downto 0);
178 177 jguarin200
 
179 211 jguarin200
 
180
begin
181
 
182
        --! Unos y ceros
183
        zero    <= (others => '0');
184
 
185
        --! Salidas no asignadas
186
 
187
        --! Mientras tanto
188
        ssync_chain_pending <= ssync_chain_1;
189
        sres_d ((wd*1)-1 downto wd*0)<= sreg_block(reg_bz) ;
190
        sres_d ((wd*2)-1 downto wd*1)<= sreg_block(reg_by) ;
191
        sres_d ((wd*3)-1 downto wd*2)<= sreg_block(reg_bx) ;
192
        sres_d ((wd*4)-1 downto wd*3)<= sreg_block(reg_ax) ;
193
        sres_w <= ssync_chain_1;
194
 
195
 
196
 
197
--! *************************************************************************************************************************************************************************************************************************************************************
198
--! AVALON MEMORY MAPPED MASTER INTERFACE BEGIN  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  => 
199
--! *************************************************************************************************************************************************************************************************************************************************************
200
--! ******************************************************************************************************************************************************                                              
201
--! TRANSFER CONTROL RTL CODE
202
--! ******************************************************************************************************************************************************                                              
203
        TRANSFER_CONTROL:
204
        process(clk,rst,master_waitrequest,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,sres_e,smaster_read,smaster_write,sdata_fetch_counter,sload_add_pending,swrite_pending,sdownload_chain)
205
        begin
206 202 jguarin200
 
207 211 jguarin200
                --! Conexi&oacuteln a se&ntilde;ales externas. 
208
                irq <= sreg_block(reg_ctrl)(reg_ctrl_irq);
209
                master_read <= smaster_read;
210
                master_write <= smaster_write;
211 202 jguarin200
 
212 150 jguarin200
 
213 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.
214
                sZeroTransit <= not(sload_add_pending or sfetch_data_pending or spipeline_pending or swrite_pending);
215 202 jguarin200
 
216 211 jguarin200
                --! ELEMENTO DE SINCRONIZACION OUT QUEUE: Datos pendientes por cargar a la memoria a trav&eacute;s de la interconexi&oacute;n
217
                swrite_pending <= not(soutb_e);
218 202 jguarin200
 
219 211 jguarin200
                --! ELEMENTO DE SINCRONIZACION ARITH PIPELINE: Hay datos transitando por el pipeline aritm&eacute;tico.
220
                if ssync_chain_pending='1' or sres_e='0' then
221
                        spipeline_pending <= '1';
222
                else
223
                        spipeline_pending <= '0';
224
                end if;
225 202 jguarin200
 
226 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.
227
                if sdata_fetch_counter=zero(reg_ctrl_nfetch_high downto reg_ctrl_nfetch_low) then
228
                        sfetch_data_pending <= '0';
229
                else
230
                        sfetch_data_pending <= '1';
231
                end if;
232
 
233
                --! ELEMENTO DE SINCRONIZACION CARGA DE DIRECCIONES: Hay direcciones pendientes por cargar a la interconexi&oacute;n?
234
                if sreg_block(reg_ctrl)(reg_ctrl_nfetch_high downto reg_ctrl_nfetch_low)=zero(reg_ctrl_nfetch_high downto reg_ctrl_nfetch_low) then
235
                        sload_add_pending <= '0';
236
                else
237
                        sload_add_pending <= '1';
238
                end if;
239 202 jguarin200
 
240 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.
241
                if sdownload_chain /= AX and sdownload_chain /= AXBX then
242
                        sparamload_pending <= '1';
243
                else
244
                        sparamload_pending <= '0';
245
                end if;
246
 
247
                --! Se debe iniciar una transacci&oacute;n de descarga de datos desde la memoria externa?
248
                if soutb_af='0' and sload_add_pending='1' then
249
                        --! 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.
250
                        sflood_condition <= '1';
251
                else
252
                        --! Flow Control : La saturaci&oacute;n de la cola de resultados debe parar porque est&aacute; cas&iacute; llena.       
253
                        sflood_condition <= '0';
254
                end if;
255
                if sreg_block(reg_ctrl)(reg_ctrl_nfetch_high downto reg_ctrl_nfetch_low+mb)/=zero(reg_ctrl_nfetch_high downto reg_ctrl_nfetch_low+mb) then
256
                        --! 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.
257
                        sflood_burstcount <= '1'&zero(mb-1 downto 0);
258
                else
259
                        --! 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.
260
                        sflood_burstcount <= '0'&sreg_block(reg_ctrl)(reg_ctrl_nfetch_low+mb-1 downto reg_ctrl_nfetch_low);
261
                end if;
262 202 jguarin200
 
263 211 jguarin200
                --! Se debe iniciar una transacci&oacute;n de carga de datos hacia la memoria externa?
264
                if soutb_ae='1' then
265
                        --! 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.  
266
                        sdrain_burstcount <= soutb_usedw(mb downto 0);
267
                        --! 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.   
268
                        sdrain_condition <= not(sload_add_pending) and not(sfetch_data_pending) and not(spipeline_pending) and swrite_pending;
269
                else
270
                        --! 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.
271
                        sdrain_burstcount <= '1'&zero(mb-1 downto 0);
272
                        --! 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.   
273
                        sdrain_condition <= '1';
274
                end if;
275 202 jguarin200
 
276 211 jguarin200
                --! Restart param load chain
277
                srestart_chain <= sreg_block(reg_ctrl)(reg_ctrl_irq) and sreg_block(reg_ctrl)(reg_ctrl_rlsc);
278 202 jguarin200
 
279 211 jguarin200
                --! Data dumpster: Dump data once the interconeection has loaded the data to write.
280
                if sm=SINK and master_waitrequest='0' and smaster_write='1' then
281
                        soutb_ack <= '1';
282
                else
283
                        soutb_ack <= '0';
284
                end if;
285 202 jguarin200
 
286 211 jguarin200
                --! Flow Control State Machine.
287
                if rst=rstMasterValue then
288
 
289
                        --! State Machine 
290
                        sm <= IDLE;
291
 
292
 
293
                        --! Master Write & Read Common Signals Reset Value
294
                        master_burstcount       <= (others => '0');
295
                        master_address          <= (others => '0');
296
                        sdata_fetch_counter     <= (others => '0');
297
                        sburstcount_sink        <= (others => '0');
298 150 jguarin200
 
299 211 jguarin200
                        --! Master Read Only Signals Reset Value
300
                        smaster_read            <= '0';
301
 
302
                        --! Master Write Only Signals
303
                        smaster_write           <= '0';
304
 
305
                        --! Reg Ctrl & Fetch address and writeaddress
306
                        --! Sinking address
307
                        sreg_block(reg_sinkstart) <= (others => '0');
308
                        --! Sourcing address
309
                        sreg_block(reg_fetchstart) <= (others => '0');
310
                        --! Control and Status Register
311
                        sreg_block(reg_ctrl) <= (others => '0');
312
                        --! Contador Overall
313
                        sreg_block(reg_inputcounter) <= (others => '0');
314
                        sreg_block(reg_outputcounter) <= (others => '0');
315
 
316
 
317
                elsif clk'event and clk='1' then
318 150 jguarin200
 
319 211 jguarin200
                        --! Nevermind the State, discount the incoming valid data counter.
320
                        sdata_fetch_counter <= sdata_fetch_counter-master_readdatavalid;
321
 
322
                        --! Debug Counter.
323
                        sreg_block(reg_inputcounter) <= sreg_block(reg_inputcounter) + master_readdatavalid;
324
                        sreg_block(reg_outputcounter) <= sreg_block(reg_outputcounter) + soutb_ack;
325 152 jguarin200
 
326 211 jguarin200
                        --! Flags
327
 
328
 
329
                        case sm is
330
                                when SOURCE =>
331
                                        --! ******************************************************************************************************************************************************                                              
332
                                        --! Flooding the pipeline ........
333
                                        --! ******************************************************************************************************************************************************                                              
334
                                        if smaster_read='0' then
335
                                                if sflood_condition = '1' then
336
                                                        --! Flow Control: Hay suficiente espacio en el buffer de salida y hay descargas pendientes por hacer
337
                                                        smaster_read <= '1';
338
                                                        master_address <= sreg_block(reg_fetchstart);
339
                                                        master_burstcount <= sflood_burstcount;
340
                                                        sdata_fetch_counter <= sdata_fetch_counter+sflood_burstcount-master_readdatavalid;
341
                                                        --! Context Saving:
342
                                                        sreg_block(reg_fetchstart) <= sreg_block(reg_fetchstart) + (sflood_burstcount&"00");
343
                                                        sreg_block(reg_ctrl)(reg_ctrl_nfetch_high downto reg_ctrl_nfetch_low) <= sreg_block(reg_ctrl)(reg_ctrl_nfetch_high downto reg_ctrl_nfetch_low) - sflood_burstcount;
344
                                                else
345
                                                        --! Flow Control : Cambiar al estado SINK, porque o est&aacute; muy llena la cola de salida o no hay descargas pendientes por realizar.
346
                                                        sm <= SINK;
347
                                                end if;
348
                                        else --master_read=1;
349
                                                if master_waitrequest='0' then
350
                                                        --! Las direcciones de lectura est&aacute;n cargadas. Terminar la transferencia.
351
                                                        smaster_read <= '0';
352
                                                end if;
353
                                        end if;
354
                                when SINK =>
355
 
356
                                        --! ******************************************************************************************************************************************************                                              
357
                                        --! Draining the pipeline ........
358
                                        --! ******************************************************************************************************************************************************                                              
359
                                        if smaster_write='0' then
360
 
361
                                                if sdrain_condition='1' then
362
                                                        --! 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.
363
                                                        smaster_write <= '1';
364
                                                        master_address <= sreg_block(reg_sinkstart);
365
                                                        master_burstcount <= sdrain_burstcount;
366 150 jguarin200
 
367 211 jguarin200
                                                        --!Context Saving
368
                                                        sreg_block(reg_sinkstart) <= sreg_block(reg_sinkstart) + (sdrain_burstcount&"00");
369
                                                        sburstcount_sink <= sdrain_burstcount-1;
370
                                                else
371
                                                        --! 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.
372
                                                        if sZeroTransit='1' then
373
 
374
                                                                --! Flow Control: Finalizada la instrucci&oacute;n, generar una interrupci&oacute;n e ir al estado IDLE.
375
                                                                sm <= IDLE;
376
                                                                sreg_block(reg_ctrl)(reg_ctrl_irq) <= '1';
377
                                                                sreg_block(reg_ctrl)(reg_ctrl_rom) <= '0';
378
                                                                sreg_block(reg_ctrl)(reg_ctrl_flags_dc downto reg_ctrl_flags_ae) <= sdrain_condition & sflood_condition & soutb_ae;
379
                                                                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;
380
 
381
                                                        else
382
 
383
                                                                --! Flow Control: Cambiar a Source porque aun hay elementos transitando.
384
                                                                sm <= SOURCE;
385
                                                        end if;
386
 
387
                                                end if;
388
                                        else --!smaster_write=1 
389
                                                if master_waitrequest = '0' then
390
 
391
                                                        --! Descartar datos : revisar antes de este proceso secuencial la parte combinatoria (Data Dumpster).
392
 
393
 
394
                                                        if sburstcount_sink/=zero(mb downto 0) then
395
 
396
                                                                --! Datos pendientes por transmitir aun en el burst. Restar uno 
397
                                                                sburstcount_sink <= sburstcount_sink-1;
398
                                                        else
399
 
400
                                                                --! No escribir mas. Finalizar la transmisi&oacute;n
401
                                                                smaster_write <= '0';
402
 
403
                                                                --! Si no hay transito de dato se con terminada la instrucci&oacute;n siempre que el estado de control de flujo est&eacute; sidera  
404
                                                                if sZeroTransit='1' then
405
 
406
                                                                        --! Flow Control: Finalizada la instrucci&oacute;n, generar una interrupci&oacute;n e ir al estado IDLE.
407
                                                                        sm <= IDLE;
408
                                                                        sreg_block(reg_ctrl)(reg_ctrl_irq) <= '1';
409
                                                                        sreg_block(reg_ctrl)(reg_ctrl_rom) <= '0';
410
                                                                        sreg_block(reg_ctrl)(reg_ctrl_flags_dc downto reg_ctrl_flags_ae) <= sdrain_condition & sflood_condition & soutb_ae;
411
                                                                        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;
412
 
413
                                                                end if;
414
                                                        end if;
415
                                                end if;
416
                                        end if;
417
 
418
                                when IDLE =>
419
                                        --! ******************************************************************************************************************************************************                                              
420
                                        --! Programming the pipeline
421
                                        --! ******************************************************************************************************************************************************                                              
422
                                        --! El registro de control en sus campos fetch e irq, es escribile solo cuando estamos en estado IDLE.           
423
                                        if sslave_write='1' then
424
                                                case sslave_address is
425
                                                        when x"0" =>
426
                                                                --! 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 
427
                                                                if sreg_block(reg_ctrl)(reg_ctrl_irq)='0' or sslave_writedata(reg_ctrl_irq)='0' then
428
                                                                        sreg_block(reg_ctrl)(reg_ctrl_irq downto reg_ctrl_nfetch_low) <= sslave_writedata(reg_ctrl_irq downto reg_ctrl_nfetch_low);
429
                                                                        sreg_block(reg_ctrl)(reg_ctrl_flags_wp-1 downto reg_ctrl_cmb) <= sslave_writedata(reg_ctrl_flags_wp-1 downto reg_ctrl_cmb);
430
                                                                end if;
431
                                                        when x"6" => sreg_block(reg_outputcounter) <= sslave_writedata;
432
                                                        when x"7" => sreg_block(reg_inputcounter) <= sslave_writedata;
433
                                                        when x"8" => sreg_block(reg_fetchstart) <= sslave_writedata;
434
                                                        when x"9" => sreg_block(reg_sinkstart) <= sslave_writedata;
435
                                                        when others => null;
436
                                                end case;
437
                                        else
438
 
439
                                                if sZeroTransit='0' then
440
 
441
 
442
                                                        --! Flow Control: Existe un n&uacute;mero de descargas programadas por el sistema, comenzar a realizarlas.
443
                                                        --! Ir al estado Source.
444
                                                        sm <= SOURCE;
445
                                                        sreg_block(reg_ctrl)(reg_ctrl_rom) <= '1';
446
 
447
                                                end if;
448
                                        end if;
449
                                when others =>
450
                                        null;
451
                        end case;
452
                end if;
453
        end process;
454
--! ******************************************************************************************************************************************************                                              
455
--! FLOW CONTROL RTL CODE
456
--! ******************************************************************************************************************************************************                                              
457
--! Colas de resultados y buffer de salida
458
--! ******************************************************************************************************************************************************                                              
459
        res:scfifo
460
        generic map     (lpm_numwords => 2**fd, lpm_showahead => "ON", lpm_width => 128, lpm_widthu     => fd, overflow_checking => "ON", underflow_checking => "ON", use_eab => "ON")
461
        port map        (rdreq => sres_ack, aclr => '0', empty => sres_e, clock => clk, q => sres_q,     wrreq => sres_w, data => sres_d);
462
        output_buffer:scfifo
463
        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")
464
        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);
465
--! ******************************************************************************************************************************************************                                              
466
--! PROCESO DE CONTROL DE FLUJO ENTRE EL BUFFER DE RESULTADOS Y EL BUFFER DE SALIDA
467
--! ******************************************************************************************************************************************************                                              
468
 
469
        FLOW_CONTROL_OUTPUT_STAGE:
470
        process (clk,rst,sres_e,sreg_block(reg_ctrl)(reg_ctrl_vt downto reg_ctrl_sc),sm,supload_chain,zero,ssync_chain_pending,sres_q,supload_start)
471
        begin
472
 
473
 
474
                --! Compute initial State.
475
 
476
                --! Escribir en el output buffer.
477
                soutb_w <= not(sres_e);
478
 
479
                --! Control de lectura de la cola de resultados.
480
                if sres_e='0' then
481
                        --!Hay datos en la cola de resultados.
482
                        if (supload_chain=VZ and sreg_block(reg_ctrl)(reg_ctrl_sc)='0') or supload_chain=SC then
483
                                --!Se transfiere el ultimo componente vectorial y no se estan cargando resultados escalares.
484
                                sres_ack <= '1';
485
                        end if;
486
                else
487
                        sres_ack <= '0';
488
                end if;
489
 
490
                --! Decodificar que salida de la cola de resultados se conecta a la entrada del otput buffer
491
                case supload_chain is
492
                        when VX =>
493
                                soutb_d <= sres_q ((wd*1)-1 downto wd*0);
494
                        when VY =>
495
                                soutb_d <= sres_q ((wd*2)-1 downto wd*1);
496
                        when VZ =>
497
                                soutb_d <= sres_q ((wd*3)-1 downto wd*2);
498
                        when SC =>
499
                                soutb_d <= sres_q ((wd*4)-1 downto wd*3);
500
                end case;
501
 
502
 
503
                case sreg_block(reg_ctrl)(reg_ctrl_vt downto reg_ctrl_sc) is
504
                        when "01" =>
505
                                supload_start <= SC;
506
                        when others =>
507
                                supload_start <= VX;
508
                end case;
509
 
510
 
511
                --! M&aacute;quina de estados para el width adaptation RES(128) -> OUTPUTBUFFER(32).    
512
                if rst=rstMasterValue then
513
                        supload_chain <= VX;
514
                elsif clk'event and clk='1' then
515
                        case supload_chain is
516
                                when VX =>
517
                                        if sres_e='1' then
518
                                                supload_chain <= supload_start;
519
                                        else
520
                                                supload_chain <= VY;
521
                                        end if;
522
                                when VY =>
523
                                        supload_chain <= VZ;
524
                                when VZ =>
525
                                        if sreg_block(reg_ctrl)(reg_ctrl_sc)='0' then
526
                                                supload_chain <= VX;
527
                                        else
528
                                                supload_chain <= SC;
529
                                        end if;
530
                                when SC =>
531
                                        supload_chain <= supload_start;
532
                        end case;
533
                end if;
534
 
535
 
536
        end process;
537
--! ******************************************************************************************************************************************************                                              
538
--! PROCESO DE CONTROL DE FLUJO ENTRE LA ENTRADA DESDE LA INTERCONEXI&OACUTE;N Y LOS PARAMETROS DE ENTRADA EN EL PIPELINE ARITMETICO
539
--! ******************************************************************************************************************************************************                                              
540
        FLOW_CONTROL_INPUT_STAGE:
541
        process(clk,rst,master_readdatavalid,master_readdata,sreg_block(reg_ctrl)(reg_ctrl_d downto reg_ctrl_s),sslave_write,sslave_address)
542
        begin
543
                --! 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.
544
                --! Mirar como es la carga inicial. Si es Normalizacion o Magnitud (dcs=110) entonces cargar AXBX de lo contrario solo AX.
545
                case sreg_block(reg_ctrl)(reg_ctrl_d downto reg_ctrl_s) is
546
                        when "110" | "100"      =>      sdownload_start <= AXBX;
547
                        when others                     =>      sdownload_start <= AX;
548
                end case;
549
                if rst=rstMasterValue then
550
                        ssync_chain_1 <= '0';
551
                        sdownload_chain <= AX;
552
                        for i in reg_bz downto reg_ax loop
553
                                sreg_block(i) <= (others => '0');
554
                        end loop;
555
                elsif clk'event and clk='1' then
556
                        ssync_chain_1   <= '0';
557
                        if master_readdatavalid='1' then
558
                                --! El dato en la interconexi&oacute;n es valido, se debe enganchar. 
559
                                case sdownload_chain is
560
                                        when AX | AXBX  =>
561
                                                --! Cargar el operando correspondiente al componente "X" del vector "A" 
562
                                                ssync_chain_1 <= '0';
563
                                                sreg_block(reg_ax) <= master_readdata;
564
                                                if sdownload_start = AXBX then
565
                                                        --! Operaci&oacute;n Unaria por ejemplo magnitud de un vector
566
                                                        --! Escribir en el registro bx adicionalmente. 
567
                                                        sreg_block(reg_bx) <= master_readdata;
568
                                                        --! El siguiente estado es cargar el componente "Y" de del operando a ejecutar. 
569
                                                        sdownload_chain <= AYBY;
570
                                                else
571
                                                        --! Operaci&oacute;n de dos operandos. Por ejemplo Producto Cruz.
572
                                                        --! El siguiente estado es cargar el vector "Y" del operando "A".
573
                                                        sdownload_chain <= AY;
574
                                                end if;
575
                                        when AY | AYBY =>
576
                                                sreg_block(reg_ay) <= master_readdata;
577
                                                ssync_chain_1 <= '0';
578
                                                if sdownload_chain = AYBY then
579
                                                        sreg_block(reg_by) <= master_readdata;
580
                                                        sdownload_chain <= AZBZ;
581
                                                else
582
                                                        sdownload_chain <= AZ;
583
                                                end if;
584
                                        when AZ  | AZBZ =>
585
                                                sreg_block(reg_az) <= master_readdata;
586
                                                if sdownload_chain=AZBZ then
587
                                                        ssync_chain_1 <= '1';
588
                                                        sreg_block(reg_bz) <= master_readdata;
589
                                                        sdownload_chain <= AXBX;
590
                                                else
591
                                                        ssync_chain_1 <= '0';
592
                                                        sdownload_chain <= BX;
593
                                                end if;
594
                                        when BX  =>
595
                                                ssync_chain_1 <= '0';
596
                                                sreg_block(reg_bx) <= master_readdata;
597
                                                sdownload_chain <= BY;
598
                                        when BY =>
599
                                                ssync_chain_1 <= '0';
600
                                                sreg_block(reg_by) <= master_readdata;
601
                                                sdownload_chain <= BZ;
602
                                        when BZ =>
603
                                                sreg_block(reg_bz) <= master_readdata;
604
                                                ssync_chain_1 <= '1';
605
                                                if sreg_block(reg_ctrl)(reg_ctrl_cmb)='1' then
606
                                                        sdownload_chain <= BX;
607
                                                else
608
                                                        sdownload_chain <= AX;
609
                                                end if;
610
                                        when others =>
611
                                                null;
612
                                end case;
613
 
614
                                if srestart_chain='1' then
615
                                        sdownload_chain <= sdownload_start;
616
                                end if;
617
 
618
                        end if;
619
                end if;
620
        end process;
621
--! *************************************************************************************************************************************************************************************************************************************************************
622
--! AVALON MEMORY MAPPED MASTER FINISHED
623
--! *************************************************************************************************************************************************************************************************************************************************************
624
--! *************************************************************************************************************************************************************************************************************************************************************
625
--! AVALON MEMORY MAPPED SLAVE BEGINS =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>  =>
626
--! *************************************************************************************************************************************************************************************************************************************************************
627
        --! Master Slave Process: Proceso para la escritura y lectura de registros desde el NIOS II.
628
        low_register_bank:
629
        process (clk,rst,sreg_block)
630
        begin
631
                if rst=rstMasterValue then
632
                        for i in reg_scratch00 downto reg_vz loop
633
                                sreg_block(i) <= (others => '0');
634
                        end loop;
635
 
636
                        slave_readdata <= (others => '0');
637
                        sslave_address <= (others => '0');
638
                        sslave_writedata <= (others => '0');
639
                        sslave_write <= '0';
640
                        sslave_read <= '0';
641
                elsif clk'event and clk='1' then
642
 
643
 
644
                        sslave_address          <= slave_address;
645
                        sslave_write            <= slave_write;
646
                        sslave_read                     <= slave_read;
647
                        sslave_writedata        <= slave_writedata;
648
                        for i in reg_scratch00 downto reg_vz loop
649
                                if sslave_address=i then
650
                                        if sslave_write='1' then
651
                                                sreg_block(i) <= sslave_writedata;
652
                                        end if;
653
                                end if;
654
                        end loop;
655
                        for i in 15 downto 0 loop
656
                                if sslave_address=i then
657
                                        if sslave_read='1' then
658
                                                slave_readdata <= sreg_block(i);
659
                                        end if;
660
                                end if;
661
                        end loop;
662
                end if;
663
        end process;
664
--! *************************************************************************************************************************************************************************************************************************************************************
665
--! AVALON MEMORY MAPPED SLAVE FINISHED
666
--! *************************************************************************************************************************************************************************************************************************************************************
667
 
668
 
669
 
670
 
671
 
672
 
673
 
674 150 jguarin200
end architecture;
675 211 jguarin200
 
676
        --!---------|-----------|-------------------------------------------------------------------------------------------------------------------
677
        --! Control Register (cr)       BASE_ADDRESS + 0x0                                                                                                                                                                                              |
678
        --!---------|-----------|-------------------------------------------------------------------------------------------------------------------
679
        --! Bit No.     | Nombre        | Descripci&oacute;n                                                                                                                                                                                            |
680
        --!---------|-----------|-------------------------------------------------------------------------------------------------------------------
681
        --! 0           | cmb (rw)      | 1:    La operaci&oacute;n es combinatoria, por lo tanto solo se cargan vectores en el operando B.                                     |
682
        --!                     |                       | 0:    La operaci&oacute;n no es combinatoria, se cargan vectores en los operandos A y B.                                                      |
683
        --!---------|-----------|-------------------------------------------------------------------------------------------------------------------|
684
        --!                     |                       |               Configuraci&oacute;n del Datapath, Interconexi&oacute;n del Pipeline Aritm&eacute;tico y Cadena de Carga        |
685
        --!                     |                       |               Dependiendo del valor de estos 3 bits se configura la operaci&oacute;n a ejecutar.                                                      |
686
        --!                     |                       |                                                                                                                                                                                                                                       |
687
        --! [3:1]       | dcs (rw)      | 011:  Producto Cruz                                                                                                                                                                                           |
688
        --!                     |                       | 000:  Suma Vectorial                                                                                                                                                                                          |
689
        --!                     |                       | 001:  Resta Vectorial                                                                                                                                                                                         |
690
        --!                     |                       | 110:  Normalizaci&oacute;n Vectorial y c&aacute;lculo de Magnitud Vectorial                                                                           |
691
        --!                     |                       | 100:  Producto Punto                                                                                                                                                                                          |
692
        --!                     |                       | 111:  Producto Simple                                                                                                                                                                                         |
693
        --!---------|-----------|-------------------------------------------------------------------------------------------------------------------|
694
        --!                     |                       | En el caso de que dcs sea 110 (Normalizaci&oacute;n y Magnitud Vectorial) este par de bits indica que resultados      |
695
        --!                     |                       | escribir. Si dcs tiene un valor diferente a 110 se ignora este campo.                                                                                         |
696
        --!                     |                       |                                                                                                                                                                                                                                       |
697
        --! [5:4]       | vtsc (rw)     | 00:   Solo leer los resultados vectoriales.                                                                                                                                           |
698
        --!                     |                       | 01:   Solo leer los resultados escalares.                                                                                                                                                     |
699
        --!                     |                       | 10:   Solo leer los resultados vectoriales.                                                                                                                                           |
700
        --!                     |                       | 11:   Leer los resultados escalares y vectoriales.                                                                                                                            |
701
        --!---------|-----------|-------------------------------------------------------------------------------------------------------------------|
702
        --! 14          | rlsc (rw)     | 1:    El sistema est&aacute; configurado para resetear la recarga sincronizada de par&aacute;metros una vez           |
703
        --!                     |                       |               concluya la instrucci&oacute;n                                                                                                                                                          |
704
        --!                     |                       |                                                                                                                                                                                                                                       |
705
        --!                     |                       | 0:    El sistema est&aacute; configurado para no resetear la cadena de sincronizaci&oacute;n de carga.                                                                                                                                                                                                        |
706
        --!---------|-----------|-------------------------------------------------------------------------------------------------------------------|
707
        --! 15          | rom (r)       | 1: Los registros solo se pueden leer no se pueden escribir.                                                                                                           |
708
        --!                     |                       | 0: Los registros se pueden leer y escribir.                                                                                                                                           |
709
        --!---------|-----------|-------------------------------------------------------------------------------------------------------------------|
710
        --! [30:16]     | nfetch(rw)| Cantidad de direcciones a cargar en la interconex&oacute;n para realizar la posterior descarga de datos de la     |
711
        --!                     |                       | memoria al RayTrac.
712
        --!---------|-----------|-------------------------------------------------------------------------------------------------------------------|
713
        --!     31              | irq           | 1:    Evento de interrupci&oacute;n. El usuario debe hacer clear de este bit para dar la interrupci&o;n por           |
714
        --!                     |                       |               por atendida. Este bit se pone en uno cuando el sistema pasa de estado TX a FETCH o FETCH a TX.                         |
715
        --!                     |                       |                                                                                                                                                                                                                                       |
716
        --!                     |                       | 0:    El RayTrac se encuentra en operaci&oacute;n Normal.                                                                                                                     |
717
        --!---------|-----------|-------------------------------------------------------------------------------------------------------------------
718
        --! Start Parameter Address (psadd)     BASE_ADDRESS + 0x4                                                                                                                                                                              |
719
        --!---------|-----------|-------------------------------------------------------------------------------------------------------------------|
720
        --! [31:0]      | sadd (rw) | Direcci&oacute;n de memoria donde se encuentra el primer par&aacute;metro de entrada.                                                             |
721
        --!---------|-----------|-------------------------------------------------------------------------------------------------------------------|
722
        --! Start Result Address (rsadd) BASE_ADDRESS + 0x8                                                                                                                                                                                     |
723
        --!---------|-----------|-------------------------------------------------------------------------------------------------------------------|
724
        --! [31:0]      | rsadd (rw)| Direcci&oacute;n de memoria donde se encuentra el primer par&aacute;metro de entrada.                                                             |
725
        --!---------|-----------|-------------------------------------------------------------------------------------------------------------------|
726
        --! Scratch Register (screg) BASE_ADDRESS + 0x1C                                                                                                                                                                                        |
727
        --!---------|-----------|-------------------------------------------------------------------------------------------------------------------|
728
        --! [31:0]      | screg (rw)| Direcci&oacute;n de memoria donde se pueden escribir y leer valores de 32 bits.                                                                   |
729
        --!---------|-----------|-------------------------------------------------------------------------------------------------------------------|

powered by: WebSVN 2.1.0

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