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

Subversion Repositories raytrac

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

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

Line No. Rev Author Line
1 151 jguarin200
library ieee;
2
use ieee.std_logic_1164.all;
3 153 jguarin200
use ieee.std_logic_arith.all;
4
use ieee.math_real.all;
5 151 jguarin200
 
6 153 jguarin200
library std;
7
use std.textio.all;
8
 
9 159 jguarin200
 
10
 
11 151 jguarin200
--! Memory Compiler Library
12 159 jguarin200
library altera_mf;
13
use altera_mf.all;
14 151 jguarin200
library lpm;
15
use lpm.all;
16
 
17
 
18
 
19
package arithpack is
20
        --! Estados para la maquina de estados.
21
        type macState is (LOAD_INSTRUCTION,FLUSH_ARITH_PIPELINE,EXECUTE_INSTRUCTION);
22
        --! Estados para el controlador de interrupciones.
23 181 jguarin200
        type iCtrlState is (WAITING_FOR_A_RFULL_EVENT,INHIBIT_RFULL_INT);
24 152 jguarin200
 
25
        --! Float data blocks
26
        constant floatwidth : integer := 32;
27 189 jguarin200
 
28
        --! Control de tamaños de memoria.
29 152 jguarin200
        constant widthadmemblock : integer := 9;
30
 
31 189 jguarin200
        --! Reducci&oacute de memoria por mitades
32
        constant memoryreduction : integer := 1;
33 156 jguarin200
 
34
        subtype xfloat32 is std_logic_vector(31 downto 0);
35
        type    v3f     is array(02 downto 0) of xfloat32;
36
 
37
        --! Constantes para definir 
38
 
39
        --!type vectorblock12 is array (11 downto 0) of std_logic_vector(floatwidth-1 downto 0);
40
        type    vectorblock12 is array (11 downto 0) of xfloat32;
41
 
42
        type    vectorblock08 is array (07 downto 0) of xfloat32;
43 152 jguarin200
        type    vectorblock06 is array (05 downto 0) of std_logic_vector(floatwidth-1 downto 0);
44
        type    vectorblock04 is array (03 downto 0) of std_logic_vector(floatwidth-1 downto 0);
45
        type    vectorblock03 is array (02 downto 0) of std_logic_vector(floatwidth-1 downto 0);
46
        type    vectorblock02 is array (01 downto 0) of std_logic_vector(floatwidth-1 downto 0);
47 189 jguarin200
        type    vectorblockadd02 is array (01 downto 0) of std_logic_vector(widthadmemblock-1-memoryreduction downto 0);
48 152 jguarin200
 
49 151 jguarin200
        --! Constante de reseteo
50
        constant rstMasterValue : std_logic :='0';
51 168 jguarin200
 
52 151 jguarin200
        --! Constantes periodicas.
53
        constant tclk   : time := 20 ns;
54
        constant tclk_2 : time := tclk/2;
55
        constant tclk_4 : time := tclk/4;
56
 
57 152 jguarin200
 
58
        component raytrac
59
        port (
60
 
61
                clk : in std_logic;
62
                rst : in std_logic;
63
 
64
                --! Señal de lectura de alguna de las colas de resultados.
65
                rd      : in std_logic;
66
 
67
                --! Señal de escritura en alguno de los bloques de memoria de operandos o en la cola de instrucciones.
68
                wr      : in std_logic;
69
 
70
                --! Direccion de escritura o lectura
71
                add : in std_logic_vector (12 downto 0);
72
 
73
                --! datos de entrada
74
                d       : in std_logic_vector (31 downto 0);
75
 
76
                --! Interrupciones
77 181 jguarin200
                int     : out std_logic;
78 152 jguarin200
 
79
                --! Salidas
80
                q : out std_logic_vector (31 downto 0)
81
 
82
 
83
 
84
        );
85
        end component;
86
 
87
        --! Componentes Aritméticos
88
 
89
        component fadd32
90
        port (
91
                clk : in std_logic;
92
                dpc : in std_logic;
93 158 jguarin200
                a32 : in xfloat32;
94
                b32 : in xfloat32;
95
                c32 : out xfloat32
96 152 jguarin200
        );
97
        end component;
98
        component fmul32
99
        port (
100
                clk : in std_logic;
101 158 jguarin200
                a32 : in xfloat32;
102
                b32 : in xfloat32;
103
                p32 : out xfloat32
104 152 jguarin200
        );
105
        end component;
106
 
107
 
108
        --! Contadores para la máquina de estados.
109
 
110 151 jguarin200
        component customCounter
111
        generic (
112
                EOBFLAG         : string ;
113
                ZEROFLAG        : string ;
114
                BACKWARDS       : string ;
115
                EQUALFLAG       : string ;
116
                subwidth        : integer;
117
                width           : integer
118
 
119
        );
120
        port (
121
                clk,rst,go,set  : in std_logic;
122
                setValue,cmpBlockValue          : in std_Logic_vector(width-1 downto subwidth);
123
                zero_flag,eob_flag,eq_flag      : out std_logic;
124
                count                   : out std_logic_vector(width-1 downto 0)
125
        );
126
        end component;
127
 
128 155 jguarin200
        --! LPM_MULTIPLIER
129
        component lpm_mult
130
        generic (
131
                lpm_hint                        : string;
132
                lpm_pipeline            : natural;
133
                lpm_representation      : string;
134
                lpm_type                        : string;
135
                lpm_widtha                      : natural;
136
                lpm_widthb                      : natural;
137
                lpm_widthp                      : natural
138
        );
139
        port (
140
                dataa   : in std_logic_vector ( lpm_widtha-1 downto 0 );
141
                datab   : in std_logic_vector ( lpm_widthb-1 downto 0 );
142
                result  : out std_logic_vector( lpm_widthp-1 downto 0 )
143
        );
144
        end component;
145 151 jguarin200
        --! LPM Memory Compiler.
146
        component scfifo
147
        generic (
148
                add_ram_output_register :string;
149
                almost_full_value               :natural;
150 159 jguarin200
                allow_rwcycle_when_full :string;
151 151 jguarin200
                intended_device_family  :string;
152
                lpm_hint                                :string;
153
                lpm_numwords                    :natural;
154
                lpm_showahead                   :string;
155
                lpm_type                                :string;
156
                lpm_width                               :natural;
157
                lpm_widthu                              :natural;
158
                overflow_checking               :string;
159
                underflow_checking              :string;
160
                use_eab                                 :string
161
        );
162
        port(
163
                rdreq           : in std_logic;
164
                aclr            : in std_logic;
165
                empty           : out std_logic;
166
                clock           : in std_logic;
167
                q                       : out std_logic_vector(lpm_width-1 downto 0);
168
                wrreq           : in std_logic;
169
                data            : in std_logic_vector(lpm_width-1 downto 0);
170
                almost_full : out std_logic;
171
                full            : out std_logic
172
        );
173
        end component;
174
 
175
 
176
        component altsyncram
177
        generic (
178
                address_aclr_b                  : string;
179
                address_reg_b                   : string;
180
                clock_enable_input_a    : string;
181
                clock_enable_input_b    : string;
182
                clock_enable_output_b   : string;
183
                intended_device_family  : string;
184
                lpm_type                                : string;
185
                numwords_a                              : natural;
186
                numwords_b                              : natural;
187
                operation_mode                  : string;
188
                outdata_aclr_b                  : string;
189
                outdata_reg_b                   : string;
190
                power_up_uninitialized  : string;
191
                ram_block_type                  : string;
192
                rdcontrol_reg_b                 : string;
193
                read_during_write_mode_mixed_ports      : string;
194
                widthad_a                               : natural;
195
                widthad_b                               : natural;
196
                width_a                                 : natural;
197
                width_b                                 : natural;
198
                width_byteena_a                 : natural
199
        );
200
        port (
201
                wren_a          : in std_logic;
202
                clock0          : in std_logic;
203 189 jguarin200
                address_a       : in std_logic_vector(widthadmemblock-1-memoryreduction downto 0);
204
                address_b       : in std_logic_vector(widthadmemblock-1-memoryreduction downto 0);
205 151 jguarin200
                rden_b          : in std_logic;
206
                q_b                     : out std_logic_vector(31 downto 0);
207
                data_a          : in std_logic_vector(31 downto 0)
208
 
209
        );
210
        end component;
211
 
212
        --! Maquina de Estados.
213
        component sm
214 152 jguarin200
 
215 151 jguarin200
        port (
216
 
217
                --! Señales normales de secuencia.
218
                clk,rst:                        in std_logic;
219 152 jguarin200
                --! Vector con las instrucción codficada
220 151 jguarin200
                instrQq:in std_logic_vector(31 downto 0);
221 152 jguarin200
                --! Señal de cola vacia.
222 151 jguarin200
                instrQ_empty:in std_logic;
223
                adda,addb:out std_logic_vector (8 downto 0);
224
                sync_chain_0,instrRdAckd:out std_logic;
225
                full_r:         in std_logic;   --! Indica que la cola de resultados no puede aceptar mas de 32 elementos.
226
                --! End Of Instruction Event
227
                eoi     : out std_logic;
228
 
229
                --! DataPath Control uca code.
230
                dpc_uca : out std_logic_vector (2 downto 0);
231
                state   : out macState
232
        );
233
        end component;
234
        --! Maquina de Interrupciones
235
        component im
236
        generic (
237
                num_events : integer ;
238
                cycles_to_wait : integer
239
        );
240
        port (
241
                clk,rst:                in std_logic;
242 181 jguarin200
                rfull_event:    in std_logic;   --! full results queue events
243
                eoi_event:              in std_logic;   --! end of instruction related events
244
                int:                    out std_logic;
245 151 jguarin200
                state:                  out iCtrlState
246
        );
247
        end component;
248
        --! Bloque de memorias
249
        component memblock
250
        port (
251
 
252
 
253
                clk,rst,dpfifo_rd,normfifo_rd,dpfifo_wr,normfifo_wr : in std_logic;
254
                instrfifo_rd : in std_logic;
255 158 jguarin200
                resultfifo_wr: in std_logic_vector(8-1 downto 0);
256 151 jguarin200
                instrfifo_empty: out std_logic; ext_rd,ext_wr: in std_logic;
257 181 jguarin200
                ext_wr_add : in std_logic_vector(4+widthadmemblock-1 downto 0);
258
                ext_rd_add : in std_logic_vector(3 downto 0);
259 152 jguarin200
                ext_d: in std_logic_vector(floatwidth-1 downto 0);
260 158 jguarin200
                int_d : in vectorblock08;
261 181 jguarin200
 
262
                status_register : in std_logic_vector(3 downto 0);
263
 
264 151 jguarin200
                resultfifo_full  : out std_logic_vector(3 downto 0);
265 152 jguarin200
                ext_q,instrfifo_q : out std_logic_vector(floatwidth-1 downto 0);
266 158 jguarin200
                int_q : out vectorblock12;
267 151 jguarin200
                int_rd_add : in std_logic_vector(2*widthadmemblock-1 downto 0);
268 152 jguarin200
                dpfifo_d : in std_logic_vector(floatwidth*2-1 downto 0);
269
                normfifo_d : in std_logic_vector(floatwidth*3-1 downto 0);
270
                dpfifo_q : out std_logic_vector(floatwidth*2-1 downto 0);
271
                normfifo_q : out std_logic_vector(floatwidth*3-1 downto 0)
272 151 jguarin200
        );
273
        end component;
274
        --! Bloque decodificacion DataPath Control.
275
        component dpc
276
        port (
277
                clk,rst                                 : in    std_logic;
278 196 jguarin200
                paraminput                              : in    vectorblock06;  --! Vectores A,B
279 158 jguarin200
                prd32blko                               : in    vectorblock06;  --! Salidas de los 6 multiplicadores.
280 196 jguarin200
                add32blko                               : in    vectorblock03;  --! Salidas de los 4 sumadores.
281
                sqr32blko,inv32blko             : in    std_logic_vector (floatwidth-1 downto 0);        --! Salidas de la raiz cuadradas y el inversor.
282
                fifo32x19_q                             : in    std_logic_vector (03*floatwidth-1 downto 0);--! Salida de la cola intermedia.
283
                fifo32x09_q                             : in    std_logic_vector (floatwidth-1 downto 0);--! Salida de las colas de producto punto. 
284
                d,c,s                                   : in    std_logic;              --! Bit con el identificador del bloque AB vs CD e identificador del sub bloque (A/B) o (C/D). 
285
                sync_chain_0                    : in    std_logic;              --! Señal de dato valido que se va por toda la cadena de sincronizacion.
286 152 jguarin200
                sqr32blki,inv32blki             : out   std_logic_vector (floatwidth-1 downto 0);                --! Salidas de las 2 raices cuadradas y los 2 inversores.
287 196 jguarin200
                fifo32x19_d                             : out   std_logic_vector (03*floatwidth-1 downto 0);             --! Entrada a la cola intermedia para la normalización.
288
                q0_32x03_d                              : out   std_logic_vector (floatwidth-1 downto 0);                --! Entrada a las colas intermedias del producto punto.         
289 158 jguarin200
                prd32blki                               : out   vectorblock12;  --! Entrada de los 12 factores en el bloque de multiplicación respectivamente.
290 196 jguarin200
                add32blki                               : out   vectorblock06;  --! Entrada de los 6 sumandos del bloque de 3 sumadores.  
291
                resw                                    : out   std_logic_vector (3 downto 0);                           --! Salidas de escritura y lectura en las colas de resultados.
292
                q0_32x03_w                              : out   std_logic;
293
                q1xyz_32x20_w                   : out   std_logic;
294
                q0_32x03_r                              : out   std_logic;
295
                q1xyz_32x20_r                   : out   std_logic;
296
                resf_vector                             : in    std_logic_vector (3 downto 0);                           --! Entradas de la señal de full de las colas de resultados. 
297
                resultoutput                    : out   vectorblock04 --! 4 salidas de resultados, pues lo máximo que podrá calcularse por cada clock son 2 vectores.
298 151 jguarin200
        );
299
        end component;
300
        --! Bloque Aritmetico de Sumadores y Multiplicadores (madd)
301
        component arithblock
302
        port (
303
 
304
                clk     : in std_logic;
305
                rst : in std_logic;
306
 
307
                dpc : in std_logic;
308
 
309 158 jguarin200
                f       : in vectorblock12;
310
                a       : in vectorblock08;
311 151 jguarin200
 
312 158 jguarin200
                s       : out vectorblock04;
313
                p       : out vectorblock06
314 151 jguarin200
 
315
        );
316
        end component;
317
        --! Bloque de Raiz Cuadrada
318
        component sqrt32
319
        port (
320
 
321
                clk     : in std_logic;
322 158 jguarin200
                rd32: in xfloat32;
323
                sq32: out xfloat32
324 151 jguarin200
        );
325
        end component;
326
        --! Bloque de Inversores.
327
        component invr32
328
        port (
329
 
330
                clk             : in std_logic;
331 158 jguarin200
                dvd32   : in xfloat32;
332
                qout32  : out xfloat32
333 151 jguarin200
        );
334
        end component;
335 153 jguarin200
 
336
 
337
 
338
 
339
        type apCamera is record
340
                resx,resy : integer;
341
                width,height : real;
342
                dist : real;
343
        end record;
344
 
345
        --! Función que convierte un std_logic_vector en un numero entero
346
        function ap_slv2int(sl:std_logic_vector) return integer;
347
 
348
        --! Función que convierte un número flotante IEE754 single float, en un número std_logic_vector.
349
        function ap_fp2slv (f:real) return std_logic_vector;
350
 
351
        --! Función que convierte un número std_logic_vector en un ieee754 single float.
352
        function ap_slv2fp (sl:std_logic_vector) return real;
353
 
354
        --! Función que devuelve un vector en punto flotante IEEE754 a través de un   
355
        function ap_slv_calc_xyvec (x,y:integer; cam:apCamera) return v3f;
356
 
357 156 jguarin200
        --! Función que devuelve una cadena con el número flotante IEEE 754 ó a una cadena de cifras hexadecimales.
358 160 jguarin200
        procedure ap_slvf2string(l:inout line;sl:std_logic_vector);
359
        procedure ap_slv2hex (l:inout line;h:in std_logic_vector) ;
360 156 jguarin200
        --! Función que devuelve una cadena con el estado de macState.
361 160 jguarin200
        procedure ap_macState2string(l:inout line;s:in macState);
362 153 jguarin200
 
363 156 jguarin200
        --! Función que convierte un array de 2 std_logic_vectors que contienen un par de direcciones en string
364 160 jguarin200
        procedure ap_vnadd022string(l:inout line; va2:in vectorblockadd02);
365 153 jguarin200
 
366 156 jguarin200
        --! Función que devuelve una cadena de caracteres con el estado de la maquina de estados que controla las interrupciones
367 160 jguarin200
        procedure ap_iCtrlState2string(l:inout line;i:in iCtrlState) ;
368 156 jguarin200
 
369
        --! Función que devuelve una cadena con los componentes de un vector R3 en punto flotante IEEE754        
370 160 jguarin200
        procedure ap_v3f2string(l:inout line;v:in v3f);
371 173 jguarin200
        procedure ap_xfp032string(l:inout line;vb03:in vectorblock03);
372 157 jguarin200
 
373
        --! Función que formatea una instrucción
374 161 jguarin200
        function ap_format_instruction(i:string;ac_o,ac_f,bd_o,bd_f:std_logic_vector;comb:std_logic) return std_logic_vector;
375 157 jguarin200
 
376
        --! Función que devuelve una cadena de caracteres de un solo caracter con el valor de un bit std_logic
377 160 jguarin200
        procedure ap_sl2string(l:inout line;s:std_logic);
378
 
379 168 jguarin200
        --! Procedimiento para mostrar vectores en forma de arreglos de flotantes
380 160 jguarin200
        procedure ap_xfp122string(l:inout line;vb12:in vectorblock12);
381
        procedure ap_xfp082string(l:inout line;vb08:in vectorblock08);
382
        procedure ap_xfp062string(l:inout line;vb06:in vectorblock06);
383
        procedure ap_xfp042string(l:inout line;vb04:in vectorblock04);
384 168 jguarin200
        procedure ap_xfp022string(l:inout line;vb02:in vectorblock02);
385
 
386 156 jguarin200
 
387 151 jguarin200
end package;
388 153 jguarin200
 
389
 
390
package body arithpack is
391 160 jguarin200
 
392 168 jguarin200
        procedure ap_xfp022string(l:inout line; vb02:in vectorblock02) is
393
        begin
394
                for i in 01 downto 0 loop
395
                        write(l,string'(" ["&integer'image(i)&"]"));
396
                        write(l,string'(" "));
397
                        ap_slvf2string(l,vb02(i));
398
                end loop;
399
 
400
        end procedure;
401 160 jguarin200
        procedure ap_xfp122string(l:inout line; vb12:in vectorblock12) is
402 153 jguarin200
 
403 160 jguarin200
        begin
404
                for i in 11 downto 0 loop
405 168 jguarin200
                        write(l,string'(" ["&integer'image(i)&"]"));
406 160 jguarin200
                        write(l,string'(" "));
407
                        ap_slvf2string(l,vb12(i));
408
                end loop;
409
        end procedure;
410
 
411
        procedure ap_xfp082string(l:inout line; vb08:in vectorblock08) is
412
 
413
        begin
414
                for i in 07 downto 0 loop
415
                        write(l,string'(" ["&integer'image(i)&"]"));
416
                        write(l,string'(" "));
417
                        ap_slvf2string(l,vb08(i));
418
                end loop;
419
        end procedure;
420
 
421
        procedure ap_xfp062string(l:inout line; vb06:in vectorblock06) is
422
 
423
        begin
424
                for i in 05 downto 0 loop
425 168 jguarin200
                        write(l,string'(" ["&integer'image(i)&"]"));
426 160 jguarin200
                        write(l,string'(" "));
427
                        ap_slvf2string(l,vb06(i));
428
                end loop;
429
        end procedure;
430
 
431
        procedure ap_xfp042string(l:inout line; vb04:in vectorblock04) is
432
 
433
        begin
434
                for i in 03 downto 0 loop
435 168 jguarin200
                        write(l,string'(" ["&integer'image(i)&"]"));
436 160 jguarin200
                        write(l,string'(" "));
437
                        ap_slvf2string(l,vb04(i));
438
                end loop;
439
        end procedure;
440
 
441
 
442
        procedure ap_sl2string(l:inout line; s:in std_logic)is
443 157 jguarin200
                variable tmp:string(1 to 1);
444
        begin
445
 
446
                case s is
447
                        when '1' =>
448
                                tmp:="1";
449
                        when '0' =>
450
                                tmp:="0";
451
                        when 'U' =>
452
                                tmp:="U";
453
                        when 'X' =>
454
                                tmp:="X";
455
                        when 'Z' =>
456
                                tmp:="Z";
457
                        when 'W' =>
458
                                tmp:="W";
459
                        when 'L' =>
460
                                tmp:="L";
461
                        when 'H' =>
462
                                tmp:="H";
463
                        when others =>
464
                                tmp:="-"; -- Don't care
465
                end case;
466 168 jguarin200
                write(l,string'(" "));
467 160 jguarin200
                write(l,string'(tmp));
468 168 jguarin200
                write(l,string'(" "));
469 157 jguarin200
 
470 160 jguarin200
 
471
 
472
        end procedure;
473 157 jguarin200
 
474 161 jguarin200
        function ap_format_instruction(i:string;ac_o,ac_f,bd_o,bd_f:std_logic_vector;comb:std_logic) return std_logic_vector is
475 157 jguarin200
 
476
                alias aco : std_logic_vector (4 downto 0) is ac_o;
477
                alias acf : std_logic_vector (4 downto 0) is ac_f;
478
                alias bdo : std_logic_vector (4 downto 0) is bd_o;
479
                alias bdf : std_logic_vector (4 downto 0) is bd_f;
480
                variable ins : std_logic_vector (31 downto 0);
481
                alias it : string (1 to 3) is i;
482
        begin
483
 
484
                case it is
485
                        when "mag" =>
486
                                ins(31 downto 29) := "100";
487 160 jguarin200
                                ins(04 downto 00) := '1'&x"8";
488 157 jguarin200
                        when "nrm" =>
489 163 jguarin200
                                ins(31 downto 29) := "110";
490 160 jguarin200
                                ins(04 downto 00) := '1'&x"d";
491 157 jguarin200
                        when "add" =>
492
                                ins(31 downto 29) := "001";
493 160 jguarin200
                                ins(04 downto 00) := '0'&x"a";
494 157 jguarin200
                        when "sub" =>
495
                                ins(31 downto 29) := "011";
496 160 jguarin200
                                ins(04 downto 00) := '0'&x"a";
497 157 jguarin200
                        when "dot" =>
498
                                ins(31 downto 29) := "000";
499 160 jguarin200
                                ins(04 downto 00) := '1'&x"7";
500 157 jguarin200
                        when "crs" =>
501
                                ins(31 downto 29) := "010";
502 160 jguarin200
                                ins(04 downto 00) := '0'&x"e";
503 157 jguarin200
                        when others =>
504
                                ins(31 downto 29) := "111";
505 160 jguarin200
                                ins(04 downto 00) := '0'&x"5";
506 157 jguarin200
                end case;
507
                ins(28 downto 24) := aco;
508
                ins(23 downto 19) := acf;
509
                ins(18 downto 14) := bdo;
510
                ins(13 downto 09) := bdf;
511
                ins(08) := comb;
512
                ins(07 downto 05) := "000";
513
                return ins;
514
 
515
 
516
        end function;
517
 
518
 
519
 
520 160 jguarin200
        procedure ap_v3f2string(l:inout line;v:in v3f) is
521 155 jguarin200
        begin
522 168 jguarin200
                write(l,string'("[X]"));
523
                write(l,string'(" "));
524
                ap_slvf2string(l,v(2));
525
                write(l,string'("[Y]"));
526
                write(l,string'(" "));
527
                ap_slvf2string(l,v(1));
528
                write(l,string'("[Z]"));
529
                write(l,string'(" "));
530
                ap_slvf2string(l,v(0));
531 160 jguarin200
        end procedure;
532 173 jguarin200
        procedure ap_xfp032string(l:inout line;vb03:in vectorblock03) is
533
        begin
534
                write(l,string'("[X]"));
535
                write(l,string'(" "));
536
                ap_slvf2string(l,vb03(2));
537
                write(l,string'("[Y]"));
538
                write(l,string'(" "));
539
                ap_slvf2string(l,vb03(1));
540
                write(l,string'("[Z]"));
541
                write(l,string'(" "));
542
                ap_slvf2string(l,vb03(0));
543
        end procedure;
544 160 jguarin200
 
545
        procedure ap_iCtrlState2string(l:inout line;i:in iCtrlState) is
546 158 jguarin200
                variable tmp:string (1 to 9);
547 156 jguarin200
        begin
548 160 jguarin200
 
549
                write(l,string'("<< "));
550 156 jguarin200
                case i is
551 181 jguarin200
                        when WAITING_FOR_A_RFULL_EVENT =>
552
                                tmp:="WAIT_RF_EVNT";
553
                        when INHIBIT_RFULL_INT =>
554
                                tmp:="INHB_RF_INT";
555 156 jguarin200
                        when others =>
556 158 jguarin200
                                tmp:="ILGL__VAL";
557 156 jguarin200
                end case;
558 160 jguarin200
                write(l,string'(tmp));
559
                write(l,string'(" >>"));
560 156 jguarin200
 
561 160 jguarin200
        end procedure;
562 156 jguarin200
 
563 160 jguarin200
        procedure ap_vnadd022string(l:inout line;va2:in vectorblockadd02) is
564 156 jguarin200
        begin
565 160 jguarin200
 
566
                write(l,string'("<<[1] "));
567
                ap_slv2hex(l,va2(1));
568
                write(l,string'(" [0] "));
569
                ap_slv2hex(l,va2(0));
570
                write(l,string'(" >>"));
571
 
572
        end procedure;
573 156 jguarin200
 
574 160 jguarin200
        procedure ap_macState2string(l:inout line;s:in macState) is
575 158 jguarin200
                variable tmp:string (1 to 6);
576 156 jguarin200
        begin
577 160 jguarin200
 
578
                write(l,string'("<< "));
579 156 jguarin200
                case s is
580
                        when LOAD_INSTRUCTION =>
581
                                tmp:="LD_INS";
582
                        when FLUSH_ARITH_PIPELINE =>
583
                                tmp:="FL_ARP";
584
                        when EXECUTE_INSTRUCTION =>
585
                                tmp:="EX_INS";
586
                        when others =>
587 158 jguarin200
                                tmp:="HEL_ON";
588 156 jguarin200
                end case;
589 160 jguarin200
                write(l,string'(tmp));
590
                write(l,string'(" >>"));
591
 
592
        end procedure;
593 156 jguarin200
 
594
        constant hexchars : string (1 to 16) := "0123456789ABCDEF";
595 160 jguarin200
        procedure ap_slv2hex (l:inout line;h:in std_logic_vector) is
596
                variable index_high,index_low,highone,nc : integer;
597
        begin
598
                highone := h'high-h'low;
599
                nc:=0;
600
                for i in h'high downto h'low loop
601
                        if h(i)/='0' and h(i)/='1' then
602
                                nc:=1;
603
                        end if;
604 156 jguarin200
                end loop;
605 160 jguarin200
 
606
                if nc=1 then
607
                        for i in h'high downto h'low loop
608
                                ap_sl2string(l,h(i));
609
                        end loop;
610
                else
611
                        for i in (highone)/4 downto 0 loop
612
                                index_low:=i*4;
613
                                if (index_low+3)>highone then
614
                                        index_high := highone;
615
                                else
616
                                        index_high := i*4+3;
617
                                end if;
618
                                write(l,hexchars(1+ieee.std_logic_unsigned.conv_integer(h(index_high+h'low downto index_low+h'low))));
619
                        end loop;
620
                end if;
621
        end procedure;
622
 
623 153 jguarin200
        function ap_slv2int (sl:std_logic_vector) return integer is
624
                alias s : std_logic_vector (sl'high downto sl'low) is sl;
625
                variable i : integer;
626
        begin
627
                i:=0;
628
                for index in s'high downto s'low loop
629
                        if s(index)='1' then
630
                                i:=i*2+1;
631
                        else
632
                                i:=i*2;
633
                        end if;
634
                end loop;
635
                return i;
636
 
637
        end function;
638
        function ap_fp2slv (f:real) return std_logic_vector is
639
                variable faux : real;
640
                variable sef : std_logic_vector (31 downto 0);
641
        begin
642
                --! Signo
643
                if (f<0.0) then
644
                        sef(31) := '1';
645 160 jguarin200
                        faux:=f*(-1.0);
646 153 jguarin200
                else
647
                        sef(31) := '0';
648 160 jguarin200
                        faux:=f;
649 153 jguarin200
                end if;
650
 
651
                --! Exponente
652 160 jguarin200
                sef(30 downto 23) := conv_std_logic_vector(127+integer(floor(log(faux,2.0))),8);
653 153 jguarin200
 
654
                --! Fraction
655 160 jguarin200
                faux :=faux/(2.0**real(floor(log(faux,2.0))));
656 153 jguarin200
                faux := faux - 1.0;
657
 
658 160 jguarin200
                sef(22 downto 0)  := conv_std_logic_vector(integer(faux*(2.0**23.0)),23);
659 153 jguarin200
 
660
                return sef;
661
 
662
        end function;
663
 
664
        function ap_slv2fp(sl:std_logic_vector) return real is
665 160 jguarin200
                variable frc:integer;
666 153 jguarin200
                alias s: std_logic_vector(31 downto 0) is sl;
667 160 jguarin200
                variable f,expo: real;
668 153 jguarin200
 
669
        begin
670
 
671
 
672 160 jguarin200
                expo:=real(ap_slv2int(s(30 downto 23)) - 127);
673
                expo:=(2.0)**(expo);
674 153 jguarin200
                frc:=ap_slv2int('1'&s(22 downto 0));
675
                f:=real(frc)*(2.0**(-23.0));
676
                f:=f*real(expo);
677
 
678
                if s(31)='1' then
679
                        return -f;
680
                else
681
                        return f;
682 160 jguarin200
                end if;
683 153 jguarin200
 
684 160 jguarin200
 
685 153 jguarin200
 
686 160 jguarin200
 
687 153 jguarin200
        end function;
688
 
689
        function ap_slv_calc_xyvec (x,y:integer; cam:apCamera) return v3f is
690
 
691
 
692
                variable dx,dy : real;
693
                variable v : v3f;
694
        begin
695
 
696
                dx := cam.width/real(cam.resx);
697
                dy := cam.height/real(cam.resy);
698
 
699 160 jguarin200
                --! Eje Z: Tomando el dedo &iacute;ndice de la mano derecha, este eje queda apuntando en la direcci&on en la que mira la c&aacute;mara u observador siempre.
700 153 jguarin200
                v(0):=ap_fp2slv(cam.dist);
701
 
702 160 jguarin200
                --! Eje X: Tomando el dedo coraz&oacute;n de la mano derecha, este eje queda apuntando a la izquierda del observador, desde el observador.
703
                v(2):=ap_fp2slv(dx*real(cam.resx)*0.5-real(x)*dx-dx*0.5);
704 153 jguarin200
 
705 160 jguarin200
                --! Eje Y: Tomando el dedo pulgar de la mano derecha, este eje queda apuntando hacia arriba del observador, desde el observador.
706
                v(1):=ap_fp2slv(dy*real(cam.resy)*0.5-real(y)*dy-dy*0.5);
707 153 jguarin200
 
708
                return v;
709
 
710
        end function;
711 155 jguarin200
 
712 160 jguarin200
        procedure ap_slvf2string(l:inout line;sl:std_logic_vector) is
713 155 jguarin200
                alias f: std_logic_vector(31 downto 0) is sl;
714
                variable r: real;
715
 
716
        begin
717
 
718
                r:=ap_slv2fp(f);
719 160 jguarin200
                write(l,string'(real'image(r)));
720
                write(l,string'(" [ s:"));
721
                ap_slv2hex(l,f(31 downto 31));
722
                write(l,string'(" f: "));
723
                ap_slv2hex(l,f(30 downto 23));
724
                write(l,string'(" m: "));
725
                ap_slv2hex(l,f(22 downto 00));
726
                write(l,string'(" ]"));
727 155 jguarin200
 
728 160 jguarin200
        end procedure;
729 155 jguarin200
 
730
 
731
 
732 153 jguarin200
 
733
end package body;

powered by: WebSVN 2.1.0

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