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

Subversion Repositories mdct

[/] [mdct/] [trunk/] [source/] [testbench/] [INPIMAGE.VHD] - Blame information for rev 24

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 mikel262
--------------------------------------------------------------------------------
2
--                                                                            --
3
--                          V H D L    F I L E                                --
4
--                          COPYRIGHT (C) 2006                                --
5
--                                                                            --
6
--------------------------------------------------------------------------------
7
--
8
-- Title       : INPIMAGE
9
-- Design      : MDCT Core
10
-- Author      : Michal Krepa
11
--
12
--------------------------------------------------------------------------------
13
-- File        : INPIMAGE.VHD
14
-- Created     : Sat Mar 12 2006
15
--
16
--------------------------------------------------------------------------------
17
--
18
--  Description : 1D Discrete Cosine Transform TB stimulator and results compare
19
--
20
--------------------------------------------------------------------------------
21
library IEEE;
22
  use IEEE.STD_LOGIC_1164.all;
23
  use ieee.numeric_std.all;
24
  use IEEE.STD_LOGIC_TEXTIO.all;
25
 
26
library STD;
27
  use STD.TEXTIO.all;
28
 
29
library WORK;
30
  use WORK.MDCT_PKG.all;
31
  use WORK.MDCTTB_PKG.all;
32 15 mikel262
  use WORK.RNG.all;
33 2 mikel262
 
34
entity INPIMAGE is
35
  port (
36
        clk               : in STD_LOGIC;
37
        odv1              : in STD_LOGIC;
38
        dcto1             : in STD_LOGIC_VECTOR(OP_W-1 downto 0);
39
        odv               : in STD_LOGIC;
40
        dcto              : in STD_LOGIC_VECTOR(COE_W-1 downto 0);
41
 
42
        rst               : out STD_LOGIC;
43
        imageo            : out STD_LOGIC_VECTOR(IP_W-1 downto 0);
44
        dv                : out STD_LOGIC;
45
        testend           : out BOOLEAN
46
       );
47
end INPIMAGE;
48
 
49
--**************************************************************************--
50
 
51
architecture SIM of INPIMAGE is
52
 
53
  constant PERIOD             : TIME := 1 us /(CLK_FREQ_C);
54
 
55
  signal rst_s                : STD_LOGIC;
56
  signal test_inp             : INTEGER;
57 15 mikel262
  signal test_stim            : INTEGER;
58 2 mikel262
  signal test_out             : INTEGER;
59
  signal xcon_s               : INTEGER;
60
  signal ycon_s               : INTEGER;
61
  signal error_dct_matrix_s   : I_MATRIX_TYPE;
62 18 mikel262
  signal error_dcto1_matrix_s : I_MATRIX_TYPE;
63
  signal imageo_s             : STD_LOGIC_VECTOR(IP_W-1 downto 0);
64
  signal dv_s                 : STD_LOGIC;
65 2 mikel262
 
66
begin
67
 
68 18 mikel262
  rst  <= rst_s after HOLD_TIME;
69
 
70
  imageo <= imageo_s after HOLD_TIME;
71
  dv     <= dv_s after HOLD_TIME;
72 2 mikel262
 
73
 --------------------------
74
 -- input image stimuli
75
 --------------------------
76
 INPIMAGE_PROC: process
77 15 mikel262
   variable i : INTEGER   := 0;
78
   variable j : INTEGER   := 0;
79 13 mikel262
   variable INSERT_DELAYS : BOOLEAN := FALSE;
80 15 mikel262
   variable unf:        Uniform  := InitUniform(7, 0.0, 2.0);
81
        variable rnd:   real     := 0.0;
82
        variable xi            : INTEGER := 0;
83 2 mikel262
 
84
  -------------------------------------
85
  -- wait for defined number of clock cycles
86
  -------------------------------------
87
  procedure waitposedge(clocks : in INTEGER) is
88
  begin
89
    for i in 1 to clocks loop
90
      wait until clk='1' and clk'event;
91
    end loop;
92
  end waitposedge;
93
 
94
  -------------------------------------
95
  -- wait on clock rising edge
96
  -------------------------------------
97
  procedure waitposedge is
98
  begin
99
    wait until clk='1' and clk'event;
100
  end waitposedge;
101
 
102
  --------------------------------------
103
  -- read text image data
104
  --------------------------------------
105
  procedure read_image is
106
    file infile          : TEXT open read_mode is FILEIN_NAME_C;
107
    variable inline      : LINE;
108
    variable tmp_int     : INTEGER := 0;
109
    variable y_size      : INTEGER := 0;
110
    variable x_size      : INTEGER := 0;
111
    variable x_blocks8   : INTEGER := 0;
112
    variable y_blocks8   : INTEGER := 0;
113
    variable matrix      : I_MATRIX_TYPE;
114
    variable x_blk_cnt   : INTEGER := 0;
115
    variable y_blk_cnt   : INTEGER := 0;
116
    variable n_lines_arr : N_LINES_TYPE;
117
    variable line_n      : INTEGER := 0;
118
    variable pix_n       : INTEGER := 0;
119
    variable x_n         : INTEGER := 0;
120
    variable y_n         : INTEGER := 0;
121
  begin
122
    READLINE(infile,inline);
123
    READ(inline,y_size);
124
    READLINE(infile,inline);
125
    READ(inline,x_size);
126
 
127
    y_blocks8 := y_size / N;
128
    x_blocks8 := x_size / N;
129
 
130
    assert MAX_IMAGE_SIZE_X > x_size
131
      report "E02: Input image x size exceeds maximum value!"
132
      severity Failure;
133
 
134
    if y_size rem N > 0 then
135
      assert false
136
        report "E03: Image height dimension is not multiply of N!"
137
        severity Failure;
138
    end if;
139
    if x_size rem N > 0 then
140
      assert false
141
        report "E03: Image width dimension is not multiply of N!"
142
        severity Failure;
143
    end if;
144
 
145
    for y_blk_cnt in 0 to y_blocks8-1 loop
146
 
147
      -- read N input lines and store them to buffer
148
      for y_n in 0 to N-1 loop
149
        READLINE(infile,inline);
150
        HREAD(inline,n_lines_arr(y_n)(0 to x_size*IP_W-1));
151
      end loop;
152
      y_n := 0;
153
 
154
      for x_blk_cnt in 0 to x_blocks8-1 loop
155
        for y_n in 0 to N-1 loop
156
          for x_n in 0 to N-1 loop
157
            matrix(y_n,x_n) := TO_INTEGER(UNSIGNED(
158
                n_lines_arr(y_n)
159
                    ((x_blk_cnt*N+x_n)*IP_W to (x_blk_cnt*N+(x_n+1))*IP_W-1)));
160
          end loop;
161
        end loop;
162
 
163
        for i in 0 to N-1 loop
164
          for j in 0 to N-1 loop
165 18 mikel262
            dv_s      <= '1';
166
            imageo_s  <= STD_LOGIC_VECTOR(
167 2 mikel262
                         TO_UNSIGNED(INTEGER(matrix(i,j)),IP_W));
168
            xcon_s <= x_blk_cnt*N+j;
169
            ycon_s <= y_blk_cnt*N+i;
170
            waitposedge;
171 13 mikel262
            if INSERT_DELAYS = TRUE then
172 18 mikel262
              dv_s    <= '0';
173 13 mikel262
              waitposedge(40);
174
            end if;
175 2 mikel262
          end loop;
176
        end loop;
177
 
178
      end loop;
179
 
180
    end loop;
181
 
182
  end read_image;
183
 
184
   ---------------------------
185
   -- process begin
186
   ---------------------------
187
   begin
188 15 mikel262
     test_stim <= 0;
189 18 mikel262
     dv_s      <= '0';
190
     imageo_s  <= (others => '0');
191 2 mikel262
     rst_s <= '1';
192 18 mikel262
     waitposedge(20);
193 2 mikel262
     rst_s <= '0';
194
 
195
     -------------------------
196
     -- test 1
197
     -------------------------
198 15 mikel262
     test_stim <= 1;
199 2 mikel262
     for i in 0 to 7 loop
200
       for j in 0 to 7 loop
201 18 mikel262
         dv_s      <= '1';
202
         imageo_s  <= STD_LOGIC_VECTOR(TO_UNSIGNED(INTEGER(input_data0(i,j)),IP_W));
203 2 mikel262
         waitposedge;
204
       end loop;
205
 
206
     end loop;
207
 
208 18 mikel262
     dv_s <= '0';
209 2 mikel262
     waitposedge;
210
     -------------------------
211
 
212
     -------------------------
213
     -- test 2
214
     -------------------------
215 15 mikel262
     test_stim <= 2;
216 2 mikel262
     for i in 0 to 7 loop
217
       for j in 0 to 7 loop
218 18 mikel262
         dv_s      <= '1';
219
         imageo_s  <= STD_LOGIC_VECTOR(TO_UNSIGNED(INTEGER(input_data1(i,j)),IP_W));
220 2 mikel262
         waitposedge;
221
       end loop;
222
 
223
     end loop;
224
 
225 18 mikel262
     dv_s <= '0';
226 2 mikel262
     waitposedge;
227
     ------------------------
228
 
229
     -------------------------
230
     -- test 3
231
     -------------------------
232 15 mikel262
     test_stim <= 3;
233 2 mikel262
     for i in 0 to 7 loop
234
       for j in 0 to 7 loop
235 18 mikel262
         dv_s      <= '1';
236
         imageo_s  <= STD_LOGIC_VECTOR(TO_UNSIGNED(INTEGER(input_data2(i,j)),IP_W));
237 2 mikel262
         waitposedge;
238
       end loop;
239
 
240
     end loop;
241
 
242 18 mikel262
     dv_s <= '0';
243 2 mikel262
     waitposedge;
244
     ------------------------
245
 
246
     -------------------------
247
     -- test 4
248
     -------------------------
249 15 mikel262
     test_stim <= 4;
250 2 mikel262
     for i in 0 to 7 loop
251
       for j in 0 to 7 loop
252 18 mikel262
         dv_s      <= '1';
253
         imageo_s  <= STD_LOGIC_VECTOR(TO_UNSIGNED(INTEGER(input_data0(i,j)),IP_W));
254 2 mikel262
         waitposedge;
255 18 mikel262
         dv_s      <= '0';
256 2 mikel262
         waitposedge;
257
       end loop;
258
 
259
     end loop;
260
 
261 18 mikel262
     dv_s <= '0';
262 2 mikel262
     waitposedge;
263
     ------------------------
264
 
265
     -------------------------
266
     -- test 5
267
     -------------------------
268 15 mikel262
     test_stim <= 5;
269 13 mikel262
     for i in 0 to 7 loop
270
       for j in 0 to 7 loop
271 18 mikel262
         dv_s      <= '1';
272
         imageo_s  <= STD_LOGIC_VECTOR(TO_UNSIGNED(INTEGER(input_data1(i,j)),IP_W));
273 13 mikel262
         waitposedge;
274 18 mikel262
         dv_s      <= '0';
275 13 mikel262
         waitposedge(25);
276
       end loop;
277
 
278
     end loop;
279
 
280 18 mikel262
     dv_s <= '0';
281 13 mikel262
     waitposedge;
282
     ------------------------
283
 
284
     -------------------------
285 15 mikel262
     -- test 6-16
286
     -------------------------
287
 
288
     for x in 0 to 10 loop
289
       test_stim <= test_stim+1;
290
       for i in 0 to 7 loop
291
         for j in 0 to 7 loop
292 18 mikel262
           dv_s      <= '1';
293 15 mikel262
           if x rem 2 = 0 then
294 18 mikel262
             imageo_s  <= STD_LOGIC_VECTOR(TO_UNSIGNED(INTEGER(input_data0(i,j)),IP_W));
295 15 mikel262
           else
296 18 mikel262
             imageo_s  <= STD_LOGIC_VECTOR(TO_UNSIGNED(INTEGER(input_data3(i,j)),IP_W));
297 15 mikel262
           end if;
298
           waitposedge;
299
         end loop;
300
       end loop;
301
     end loop;
302
 
303 18 mikel262
     dv_s <= '0';
304 15 mikel262
     waitposedge;
305
     ------------------------
306
 
307
     -------------------------
308
     -- test 17-33
309
     -------------------------
310
 
311 18 mikel262
     for x in 0 to 16 loop
312 15 mikel262
       test_stim <= test_stim+1;
313
       if xi < 4 then
314
         xi := xi + 1;
315
       else
316
         xi := 0;
317
       end if;
318
       for i in 0 to 7 loop
319
         for j in 0 to 7 loop
320 18 mikel262
           dv_s      <= '1';
321 15 mikel262
 
322
           case xi is
323
             when 0 =>
324 18 mikel262
               imageo_s  <= STD_LOGIC_VECTOR(TO_UNSIGNED(INTEGER(input_data1(i,j)),IP_W));
325 15 mikel262
             when 1 =>
326 18 mikel262
               imageo_s  <= STD_LOGIC_VECTOR(TO_UNSIGNED(INTEGER(input_data0(i,j)),IP_W));
327 15 mikel262
             when 2 =>
328 18 mikel262
               imageo_s  <= STD_LOGIC_VECTOR(TO_UNSIGNED(INTEGER(input_data3(i,j)),IP_W));
329 15 mikel262
             when 3 =>
330 18 mikel262
               imageo_s  <= STD_LOGIC_VECTOR(TO_UNSIGNED(INTEGER(input_data4(i,j)),IP_W));
331 15 mikel262
             when others =>
332 18 mikel262
               imageo_s  <= STD_LOGIC_VECTOR(TO_UNSIGNED(INTEGER(input_data0(i,j)),IP_W));
333 15 mikel262
           end case;
334
           waitposedge;
335 18 mikel262
           dv_s      <= '0';
336 15 mikel262
           GenRnd(unf);
337
                rnd := unf.rnd;
338
                waitposedge(INTEGER(rnd));
339
         end loop;
340
       end loop;
341
     end loop;
342
 
343 18 mikel262
     dv_s <= '0';
344 15 mikel262
     waitposedge;
345
     ------------------------
346
 
347
     -------------------------
348 13 mikel262
     -- test 6
349
     -------------------------
350 15 mikel262
     if RUN_FULL_IMAGE = TRUE then
351
       read_image;
352
     end if;
353 2 mikel262
 
354 13 mikel262
     -------------------------
355
     -- test 7
356
     -------------------------
357
     --INSERT_DELAYS := TRUE;
358
     --read_image;
359
 
360 18 mikel262
     dv_s <= '0';
361 2 mikel262
     waitposedge;
362
     ------------------------
363
 
364
     wait;
365
 end process;
366
 
367
 --------------------------
368
 -- output coeffs comparison (after 1st stage)
369
 --------------------------
370
 OUTIMAGE_PROC: process
371
   variable i : INTEGER  := 0;
372
   variable j : INTEGER  := 0;
373
   variable error_matrix : I_MATRIX_TYPE;
374
   variable error_cnt    : INTEGER := 0;
375
   variable raport_str   : STRING(1 to 255);
376
   variable ref_matrix   : I_MATRIX_TYPE;
377
   variable dcto_matrix  : I_MATRIX_TYPE;
378 15 mikel262
   variable xi           : INTEGER := 0;
379 2 mikel262
  -------------------------------------
380
  -- wait for defined number of clock cycles
381
  -------------------------------------
382
  procedure waitposedge(clocks : in INTEGER) is
383
  begin
384
    for i in 1 to clocks loop
385
      wait until clk='1' and clk'event;
386
    end loop;
387
  end waitposedge;
388
 
389
  -------------------------------------
390
  -- wait on clock rising edge
391
  -------------------------------------
392
  procedure waitposedge is
393
  begin
394
    wait until clk='1' and clk'event;
395
  end waitposedge;
396
 
397
  --------------------------------------
398
  -- read text image data 1D DCT
399
  --------------------------------------
400
  procedure read_image_for1dct(error_cnt_i : inout INTEGER) is
401
    file infile          : TEXT open read_mode is FILEIN_NAME_C;
402
    variable inline      : LINE;
403
    variable tmp_int     : INTEGER := 0;
404
    variable y_size      : INTEGER := 0;
405
    variable x_size      : INTEGER := 0;
406
    variable x_blocks8   : INTEGER := 0;
407
    variable y_blocks8   : INTEGER := 0;
408
    variable matrix      : I_MATRIX_TYPE;
409
    variable x_blk_cnt   : INTEGER := 0;
410
    variable y_blk_cnt   : INTEGER := 0;
411
    variable n_lines_arr : N_LINES_TYPE;
412
    variable line_n      : INTEGER := 0;
413
    variable pix_n       : INTEGER := 0;
414
    variable x_n         : INTEGER := 0;
415
    variable y_n         : INTEGER := 0;
416
    variable i           : INTEGER := 0;
417
    variable j           : INTEGER := 0;
418
    variable dcto_matrix_v : I_MATRIX_TYPE;
419
    variable ref_matrix_v  : I_MATRIX_TYPE;
420
    variable error_dcto1_matrix_v : I_MATRIX_TYPE;
421
  begin
422
    READLINE(infile,inline);
423
    READ(inline,y_size);
424
    READLINE(infile,inline);
425
    READ(inline,x_size);
426
 
427
    y_blocks8 := y_size / N;
428
    x_blocks8 := x_size / N;
429
 
430
    assert MAX_IMAGE_SIZE_X > x_size
431
      report "E02: Input image x size exceeds maximum value!"
432
      severity Failure;
433
 
434
    if y_size rem N > 0 then
435
      assert false
436
        report "E03: Image height dimension is not multiply of N!"
437
        severity Failure;
438
    end if;
439
    if x_size rem N > 0 then
440
      assert false
441
        report "E03: Image width dimension is not multiply of N!"
442
        severity Failure;
443
    end if;
444
 
445
    for y_blk_cnt in 0 to y_blocks8-1 loop
446
 
447
      -- read N input lines and store them to buffer
448
      for y_n in 0 to N-1 loop
449
        READLINE(infile,inline);
450
        HREAD(inline,n_lines_arr(y_n)(0 to x_size*IP_W-1));
451
      end loop;
452
      y_n := 0;
453
 
454
      for x_blk_cnt in 0 to x_blocks8-1 loop
455
        for y_n in 0 to N-1 loop
456
          for x_n in 0 to N-1 loop
457
            matrix(y_n,x_n) := TO_INTEGER(UNSIGNED(
458
                n_lines_arr(y_n)
459
                    ((x_blk_cnt*N+x_n)*IP_W to (x_blk_cnt*N+(x_n+1))*IP_W-1)));
460
          end loop;
461
        end loop;
462
 
463
        for i in 0 to N-1 loop
464
          j := 0;
465
          while(true) loop
466
            waitposedge;
467
            if odv1 = '1' then
468
              dcto_matrix_v(j,i) := TO_INTEGER(SIGNED( dcto1 ));
469
              j := j + 1;
470
            end if;
471
 
472
            if j = N then
473
              exit;
474
            end if;
475
          end loop;
476
        end loop;
477
 
478
        -- compute reference coefficients
479
        ref_matrix_v := COMPUTE_REF_DCT1D(matrix,TRUE);
480
        CMP_MATRIX(ref_matrix_v,dcto_matrix_v,
481
                                    MAX_ERROR_1D,error_dcto1_matrix_v,error_cnt_i);
482
        error_dcto1_matrix_s <= error_dcto1_matrix_v;
483
      end loop;
484
    end loop;
485
  end read_image_for1dct;
486
 
487
  begin
488
     test_inp <= 0;
489
 
490
     -------------------------
491
     -- test 1
492
     -------------------------
493
     test_inp <= 1;
494
     -- compute reference coefficients
495
     ref_matrix := COMPUTE_REF_DCT1D(input_data0,TRUE);
496
 
497
     for i in 0 to N-1 loop
498
       j := 0;
499
       while(true) loop
500
 
501
         waitposedge;
502
         if odv1 = '1' then
503
           dcto_matrix(j,i) := TO_INTEGER(SIGNED( dcto1 ));
504
           j := j + 1;
505
         end if;
506
 
507
         if j = N then
508
           exit;
509
         end if;
510
 
511
       end loop;
512
     end loop;
513
 
514
     CMP_MATRIX(ref_matrix,dcto_matrix,MAX_ERROR_1D,error_matrix,error_cnt);
515
     -------------------------
516
 
517
     -------------------------
518
     -- test 2
519
     -------------------------
520
     test_inp <= 2;
521
     -- compute reference coefficients
522
     ref_matrix := COMPUTE_REF_DCT1D(input_data1,TRUE);
523
 
524
     for i in 0 to N-1 loop
525
       j := 0;
526
       while(true) loop
527
 
528
         waitposedge;
529
         if odv1 = '1' then
530
           dcto_matrix(j,i) := TO_INTEGER(SIGNED( dcto1 ));
531
           j := j + 1;
532
         end if;
533
 
534
         if j = N then
535
           exit;
536
         end if;
537
 
538
       end loop;
539
     end loop;
540
 
541
     CMP_MATRIX(ref_matrix,dcto_matrix,MAX_ERROR_1D,error_matrix,error_cnt);
542
     -------------------------
543
 
544
     -------------------------
545
     -- test 3
546
     -------------------------
547
     test_inp <= 3;
548
     -- compute reference coefficients
549
     ref_matrix := COMPUTE_REF_DCT1D(input_data2,TRUE);
550
 
551
     for i in 0 to N-1 loop
552
       j := 0;
553
       while(true) loop
554
 
555
         waitposedge;
556
         if odv1 = '1' then
557
           dcto_matrix(j,i) := TO_INTEGER(SIGNED( dcto1 ));
558
           j := j + 1;
559
         end if;
560
 
561
         if j = N then
562
           exit;
563
         end if;
564
 
565
       end loop;
566
     end loop;
567
 
568
     CMP_MATRIX(ref_matrix,dcto_matrix,MAX_ERROR_1D,error_matrix,error_cnt);
569
     -------------------------
570
 
571
     -------------------------
572
     -- test 4
573
     -------------------------
574
     test_inp <= 4;
575
     -- compute reference coefficients
576 15 mikel262
     ref_matrix := COMPUTE_REF_DCT1D(input_data0,TRUE);
577 2 mikel262
 
578
     for i in 0 to N-1 loop
579
       j := 0;
580
       while(true) loop
581
 
582
         waitposedge;
583
         if odv1 = '1' then
584
           dcto_matrix(j,i) := TO_INTEGER(SIGNED( dcto1 ));
585
           j := j + 1;
586
         end if;
587
 
588
         if j = N then
589
           exit;
590
         end if;
591
 
592
       end loop;
593
     end loop;
594
 
595
     CMP_MATRIX(ref_matrix,dcto_matrix,MAX_ERROR_1D,error_matrix,error_cnt);
596
     -------------------------
597
 
598
     -------------------------
599
     -- test 5
600
     -------------------------
601
     test_inp <= 5;
602 13 mikel262
     -- compute reference coefficients
603
     ref_matrix := COMPUTE_REF_DCT1D(input_data1,TRUE);
604
 
605
     for i in 0 to N-1 loop
606
       j := 0;
607
       while(true) loop
608
 
609
         waitposedge;
610
         if odv1 = '1' then
611
           dcto_matrix(j,i) := TO_INTEGER(SIGNED( dcto1 ));
612
           j := j + 1;
613
         end if;
614
 
615
         if j = N then
616
           exit;
617
         end if;
618
 
619
       end loop;
620
     end loop;
621 2 mikel262
 
622 13 mikel262
     CMP_MATRIX(ref_matrix,dcto_matrix,MAX_ERROR_1D,error_matrix,error_cnt);
623
     -------------------------
624
 
625
     -------------------------
626 15 mikel262
     -- test 6-16
627
     -------------------------
628
     for x in 0 to 10 loop
629
       test_inp <= test_inp + 1;
630
       -- compute reference coefficients
631
       if x rem 2 = 0 then
632
         ref_matrix := COMPUTE_REF_DCT1D(input_data0,TRUE);
633
       else
634
         ref_matrix := COMPUTE_REF_DCT1D(input_data3,TRUE);
635
       end if;
636
       for i in 0 to N-1 loop
637
         j := 0;
638
         while(true) loop
639
 
640
           waitposedge;
641
           if odv1 = '1' then
642
             dcto_matrix(j,i) := TO_INTEGER(SIGNED( dcto1 ));
643
             j := j + 1;
644
           end if;
645
 
646
           if j = N then
647
             exit;
648
           end if;
649
 
650
         end loop;
651
       end loop;
652
       CMP_MATRIX(ref_matrix,dcto_matrix,MAX_ERROR_1D,error_matrix,error_cnt);
653
     end loop;
654
     -------------------------
655
 
656
     -------------------------
657
     -- test 17-33
658
     -------------------------
659 18 mikel262
     for x in 0 to 16 loop
660 15 mikel262
       test_inp <= test_inp + 1;
661
       -- compute reference coefficients
662
       if xi < 4 then
663
         xi := xi + 1;
664
       else
665
         xi := 0;
666
       end if;
667
       case xi is
668
         when 0 =>
669
           ref_matrix := COMPUTE_REF_DCT1D(input_data1,TRUE);
670
         when 1 =>
671
           ref_matrix := COMPUTE_REF_DCT1D(input_data0,TRUE);
672
         when 2 =>
673
           ref_matrix := COMPUTE_REF_DCT1D(input_data3,TRUE);
674
         when 3 =>
675
           ref_matrix := COMPUTE_REF_DCT1D(input_data4,TRUE);
676
         when others =>
677
           ref_matrix := COMPUTE_REF_DCT1D(input_data0,TRUE);
678
       end case;
679
 
680
       for i in 0 to N-1 loop
681
         j := 0;
682
         while(true) loop
683
 
684
           waitposedge;
685
           if odv1 = '1' then
686
             dcto_matrix(j,i) := TO_INTEGER(SIGNED( dcto1 ));
687
             j := j + 1;
688
           end if;
689
 
690
           if j = N then
691
             exit;
692
           end if;
693
 
694
         end loop;
695
       end loop;
696
       CMP_MATRIX(ref_matrix,dcto_matrix,MAX_ERROR_1D,error_matrix,error_cnt);
697
     end loop;
698
     -------------------------
699
 
700
     -------------------------
701 13 mikel262
     -- test 6
702
     -------------------------
703
     test_inp <= 6;
704
 
705 15 mikel262
     if RUN_FULL_IMAGE = TRUE then
706
       read_image_for1dct(error_cnt);
707
     end if;
708 2 mikel262
     -------------------------
709
 
710 13 mikel262
     -------------------------
711
     -- test 7
712
     -------------------------
713
     test_inp <= 7;
714
 
715
     --read_image_for1dct(error_cnt);
716
     -------------------------
717
 
718 2 mikel262
     if error_cnt = 0 then
719
       assert false
720
         report "No errors found in first stage of DCT"
721
         severity Note;
722
     else
723
       assert false
724
         report "Found " & STR(error_cnt,10) & " errors in first stage of DCT!"
725
         severity Error;
726
     end if;
727
     assert false
728
       report "1D Test finished"
729
       severity Note;
730
 
731
     wait;
732
 end process;
733
 
734
 --------------------------
735
 -- final output coeffs comparison (after 2nd stage)
736
 --------------------------
737
 FINAL_OUTIMAGE_PROC: process
738
   variable i : INTEGER := 0;
739
   variable j : INTEGER := 0;
740
   variable error_matrix    : I_MATRIX_TYPE;
741
   variable error_idct_matrix : I_MATRIX_TYPE;
742
   variable error_cnt       : INTEGER := 0;
743
   variable raport_str      : STRING(1 to 255);
744
   variable ref_matrix_1d   : I_MATRIX_TYPE;
745
   variable ref_matrix_2d   : I_MATRIX_TYPE;
746
   variable ref_idct_matrix : I_MATRIX_TYPE;
747
   variable idcto_matrix    : I_MATRIX_TYPE;
748
   variable dcto_matrix     : I_MATRIX_TYPE;
749
   variable tmp_matrix      : I_MATRIX_TYPE;
750
   variable psnr            : REAL;
751 15 mikel262
   variable xi              : INTEGER := 0;
752 2 mikel262
  -------------------------------------
753
  -- wait for defined number of clock cycles
754
  -------------------------------------
755
  procedure waitposedge(clocks : in INTEGER) is
756
  begin
757
    for i in 1 to clocks loop
758
      wait until clk='1' and clk'event;
759
    end loop;
760
  end waitposedge;
761
 
762
  -------------------------------------
763
  -- wait on clock rising edge
764
  -------------------------------------
765
  procedure waitposedge is
766
  begin
767
    wait until clk='1' and clk'event;
768
  end waitposedge;
769
 
770
  --------------------------------------
771
  -- read text image data 2D DCT
772
  --------------------------------------
773
  procedure read_image_for2dct(error_cnt_i : inout INTEGER) is
774
    file infile          : TEXT open read_mode is FILEIN_NAME_C;
775
    file outfile_imagee  : TEXT open write_mode is FILEERROR_NAME_C;
776
    file outfile_imageo  : TEXT open write_mode is FILEIMAGEO_NAME_C;
777
    variable inline      : LINE;
778
    variable outline     : LINE;
779
    variable outline2    : LINE;
780
    variable tmp_int     : INTEGER := 0;
781
    variable y_size      : INTEGER := 0;
782
    variable x_size      : INTEGER := 0;
783
    variable x_blocks8   : INTEGER := 0;
784
    variable y_blocks8   : INTEGER := 0;
785
    variable matrix      : I_MATRIX_TYPE;
786
    variable x_blk_cnt   : INTEGER := 0;
787
    variable y_blk_cnt   : INTEGER := 0;
788
    variable n_lines_arr : N_LINES_TYPE;
789
    variable line_n      : INTEGER := 0;
790
    variable pix_n       : INTEGER := 0;
791
    variable x_n         : INTEGER := 0;
792
    variable y_n         : INTEGER := 0;
793
    variable i           : INTEGER := 0;
794
    variable j           : INTEGER := 0;
795
    variable dcto_matrix_v    : I_MATRIX_TYPE;
796
    variable ref_matrix_v     : I_MATRIX_TYPE;
797
    variable error_matrix_v   : I_MATRIX_TYPE;
798
    variable idcto_matrix_v   : I_MATRIX_TYPE;
799
    variable ref_matrix_1d_v  : I_MATRIX_TYPE;
800
    variable ref_matrix_2d_v  : I_MATRIX_TYPE;
801
    variable error_idct_matrix_v : I_MATRIX_TYPE;
802
    variable error_dct_matrix_v  : I_MATRIX_TYPE;
803
    variable psnr_v           : REAL := 0.0;
804
    variable linebuf          : LINE;
805
    variable input_image      : IMAGE_TYPE;
806
    variable output_image     : IMAGE_TYPE;
807
    variable dcto_image       : IMAGE_TYPE;
808
    variable str2_v           : STRING(1 to 2);
809
    variable dec_v            : INTEGER := 0;
810
    variable dec2_v           : INTEGER := 0;
811
    variable clip_cnt_v       : INTEGER := 0;
812
    variable tmp_q            : INTEGER := 0;
813
  begin
814
    READLINE(infile,inline);
815
    READ(inline,y_size);
816
    READLINE(infile,inline);
817
    READ(inline,x_size);
818
 
819
    y_blocks8 := y_size / N;
820
    x_blocks8 := x_size / N;
821
 
822
    assert MAX_IMAGE_SIZE_X > x_size
823
      report "E02: Input image x size exceeds maximum value!"
824
      severity Failure;
825
 
826
    if y_size rem N > 0 then
827
      assert false
828
        report "E03: Image height dimension is not multiply of N!"
829
        severity Failure;
830
    end if;
831
    if x_size rem N > 0 then
832
      assert false
833
        report "E03: Image width dimension is not multiply of N!"
834
        severity Failure;
835
    end if;
836
 
837
    for y_blk_cnt in 0 to y_blocks8-1 loop
838
 
839
      -- read N input lines and store them to buffer
840
      for y_n in 0 to N-1 loop
841
        READLINE(infile,inline);
842
        HREAD(inline,n_lines_arr(y_n)(0 to x_size*IP_W-1));
843
      end loop;
844
      y_n := 0;
845
 
846
      for x_blk_cnt in 0 to x_blocks8-1 loop
847
        for y_n in 0 to N-1 loop
848
          for x_n in 0 to N-1 loop
849
            matrix(y_n,x_n) := TO_INTEGER(UNSIGNED(
850
                n_lines_arr(y_n)
851
                    ((x_blk_cnt*N+x_n)*IP_W to
852
                    (x_blk_cnt*N+(x_n+1))*IP_W-1)));
853
            input_image(y_blk_cnt*N+y_n,x_blk_cnt*N+x_n) :=
854
                                                    matrix(y_n,x_n);
855
          end loop;
856
        end loop;
857
 
858
        for i in 0 to N-1 loop
859
          j := 0;
860
          while(true) loop
861
            waitposedge;
862
            if odv = '1' then
863
              tmp_q := TO_INTEGER(SIGNED( dcto ));
864
              if ENABLE_QUANTIZATION_C = TRUE then
865
                tmp_q := tmp_q / Q_MATRIX_USED(j,i);
866
                tmp_q := tmp_q * Q_MATRIX_USED(j,i);
867
              end if;
868
              dcto_matrix_v(j,i) := tmp_q;
869
              j := j + 1;
870
            end if;
871
 
872
            if j = N then
873
              exit;
874
            end if;
875
          end loop;
876
        end loop;
877
        idcto_matrix_v := COMPUTE_REF_IDCT(dcto_matrix_v);
878
        for i in 0 to N-1 loop
879
          for j in 0 to N-1 loop
880
            output_image(y_blk_cnt*N+j,x_blk_cnt*N+i) :=
881
                                                    idcto_matrix_v(j,i);
882
            dcto_image(y_blk_cnt*N+j,x_blk_cnt*N+i) :=
883
                                                    dcto_matrix_v(j,i);
884
          end loop;
885
        end loop;
886
        -- compute reference coefficients
887
        ref_matrix_1d_v := COMPUTE_REF_DCT1D(matrix,TRUE);
888
        ref_matrix_2d_v := COMPUTE_REF_DCT1D(ref_matrix_1d_v,FALSE);
889
        CMP_MATRIX(ref_matrix_2d_v,dcto_matrix_v,MAX_ERROR_2D,
890
                                error_dct_matrix_v,error_cnt_i);
891
        error_dct_matrix_s <= error_dct_matrix_v;
892
 
893
      end loop;
894
    end loop;
895
 
896
    -- PSNR
897
    psnr_v := COMPUTE_PSNR(input_image,output_image,y_size,x_size);
898
    WRITE(linebuf,STRING'("PSNR computed for image "
899
                          & FILEIN_NAME_C & " is "));
900
    WRITE(linebuf,psnr_v);
901
    WRITE(linebuf,STRING'(" dB"));
902
    assert false
903
      report linebuf.all
904
      severity Note;
905
 
906
    -- Save images
907
    WRITE(outline,y_size);
908
    WRITELINE(outfile_imageo,outline);
909
    WRITE(outline,x_size);
910
    WRITELINE(outfile_imageo,outline);
911
 
912
    WRITE(outline,y_size);
913
    WRITELINE(outfile_imagee,outline);
914
    WRITE(outline,x_size);
915
    WRITELINE(outfile_imagee,outline);
916
 
917
    for i in 0 to y_size-1 loop
918
      for j in 0 to x_size-1 loop
919
 
920
        -- output image
921
        dec_v := output_image(i,j);
922
        -- if DCT transform error created minus value, set it to zero
923
        if dec_v < 0 then
924
          dec_v := 0;
925
          clip_cnt_v := clip_cnt_v + 1;
926
        elsif dec_v > 255 then
927
          dec_v := 255;
928
          clip_cnt_v := clip_cnt_v + 1;
929
        end if;
930
 
931
        if dec_v <= HEX_BASE-1 then
932
          str2_v := "0" & STR( dec_v, HEX_BASE);
933
        else
934
          str2_v := STR( dec_v, HEX_BASE);
935
        end if;
936
        WRITE(outline,str2_v);
937
 
938
        -- dcto image
939
        dec_v := abs(output_image(i,j)-input_image(i,j));
940
        -- if DCT transform error created minus value, set it to zero
941
        if dec_v > 255 then
942
          dec_v := 255;
943
        end if;
944
 
945
        if dec_v <= HEX_BASE-1 then
946
          str2_v := "0" & STR( dec_v, HEX_BASE);
947
        else
948
          str2_v := STR( dec_v, HEX_BASE);
949
        end if;
950
        WRITE(outline2,str2_v);
951
      end loop;
952
      WRITELINE(outfile_imageo,outline);
953
      WRITELINE(outfile_imagee,outline2);
954
    end loop;
955
 
956
 
957
  end read_image_for2dct;
958
 
959
  begin
960
     test_out <= 0;
961
     testend <= false;
962
 
963
     -------------------------
964
     -- test 1
965
     -------------------------
966
     test_out <= 1;
967
     tmp_matrix := input_data0;
968
     -- compute reference coefficients
969
     ref_matrix_1d := COMPUTE_REF_DCT1D(tmp_matrix,TRUE);
970
     ref_matrix_2d := COMPUTE_REF_DCT1D(ref_matrix_1d,FALSE);
971
 
972
     for i in 0 to N-1 loop
973
       j := 0;
974
       while(true) loop
975
 
976
         waitposedge;
977
         if odv = '1' then
978
           dcto_matrix(j,i) := TO_INTEGER(SIGNED( dcto ));
979
           j := j + 1;
980
         end if;
981
 
982
         if j = N then
983
           exit;
984
         end if;
985
 
986
       end loop;
987
     end loop;
988
 
989
     waitposedge;
990
 
991
     CMP_MATRIX(ref_matrix_2d,dcto_matrix,MAX_ERROR_2D,error_matrix,error_cnt);
992
     idcto_matrix := COMPUTE_REF_IDCT(dcto_matrix);
993
     --error_idct_matrix := CMP_MATRIX(tmp_matrix,idcto_matrix,MAX_ERROR_2D);
994
     psnr := psnr + COMPUTE_PSNR(tmp_matrix,idcto_matrix);
995
     -------------------------
996
 
997
     -------------------------
998
     -- test 2
999
     -------------------------
1000
     test_out <= 2;
1001
     tmp_matrix := input_data1;
1002
     -- compute reference coefficients
1003
     ref_matrix_1d := COMPUTE_REF_DCT1D(tmp_matrix,TRUE);
1004
     ref_matrix_2d := COMPUTE_REF_DCT1D(ref_matrix_1d,FALSE);
1005
 
1006
     for i in 0 to N-1 loop
1007
       j := 0;
1008
       while(true) loop
1009
 
1010
         waitposedge;
1011
         if odv = '1' then
1012
           dcto_matrix(j,i) := TO_INTEGER(SIGNED( dcto ));
1013
           j := j + 1;
1014
         end if;
1015
 
1016
         if j = N then
1017
           exit;
1018
         end if;
1019
 
1020
       end loop;
1021
     end loop;
1022
 
1023
     waitposedge;
1024
 
1025
     CMP_MATRIX(ref_matrix_2d,dcto_matrix,MAX_ERROR_2D,error_matrix,error_cnt);
1026
     idcto_matrix := COMPUTE_REF_IDCT(dcto_matrix);
1027
     --error_idct_matrix := CMP_MATRIX(tmp_matrix,idcto_matrix,MAX_ERROR_2D);
1028
     psnr := COMPUTE_PSNR(tmp_matrix,idcto_matrix);
1029
     -------------------------
1030
 
1031
     -------------------------
1032
     -- test 3
1033
     -------------------------
1034
     test_out <= 3;
1035
     tmp_matrix := input_data2;
1036
     -- compute reference coefficients
1037
     ref_matrix_1d := COMPUTE_REF_DCT1D(tmp_matrix,TRUE);
1038
     ref_matrix_2d := COMPUTE_REF_DCT1D(ref_matrix_1d,FALSE);
1039
 
1040
     for i in 0 to N-1 loop
1041
       j := 0;
1042
       while(true) loop
1043
 
1044
         waitposedge;
1045
         if odv = '1' then
1046
           dcto_matrix(j,i) := TO_INTEGER(SIGNED( dcto ));
1047
           j := j + 1;
1048
         end if;
1049
 
1050
         if j = N then
1051
           exit;
1052
         end if;
1053
 
1054
       end loop;
1055
     end loop;
1056
 
1057
     waitposedge;
1058
 
1059
     CMP_MATRIX(ref_matrix_2d,dcto_matrix,MAX_ERROR_2D,error_matrix,error_cnt);
1060
     idcto_matrix := COMPUTE_REF_IDCT(dcto_matrix);
1061
     --error_idct_matrix := CMP_MATRIX(tmp_matrix,idcto_matrix,MAX_ERROR_2D);
1062
     --psnr := COMPUTE_PSNR(tmp_matrix,idcto_matrix);
1063
     -------------------------
1064
 
1065
     -------------------------
1066
     -- test 4
1067
     -------------------------
1068
     test_out <= 4;
1069 15 mikel262
     tmp_matrix := input_data0;
1070 2 mikel262
     -- compute reference coefficients
1071
     ref_matrix_1d := COMPUTE_REF_DCT1D(tmp_matrix,TRUE);
1072
     ref_matrix_2d := COMPUTE_REF_DCT1D(ref_matrix_1d,FALSE);
1073
 
1074
     for i in 0 to N-1 loop
1075
       j := 0;
1076
       while(true) loop
1077
 
1078
         waitposedge;
1079
         if odv = '1' then
1080
           dcto_matrix(j,i) := TO_INTEGER(SIGNED( dcto ));
1081
           j := j + 1;
1082
         end if;
1083
 
1084
         if j = N then
1085
           exit;
1086
         end if;
1087
 
1088
       end loop;
1089
     end loop;
1090
 
1091
     waitposedge;
1092
 
1093
     CMP_MATRIX(ref_matrix_2d,dcto_matrix,MAX_ERROR_2D,error_matrix,error_cnt);
1094
     idcto_matrix := COMPUTE_REF_IDCT(dcto_matrix);
1095
     --error_idct_matrix := CMP_MATRIX(tmp_matrix,idcto_matrix,MAX_ERROR_2D);
1096
     psnr := COMPUTE_PSNR(tmp_matrix,idcto_matrix);
1097
     -------------------------
1098
 
1099
     -------------------------
1100 13 mikel262
     -- test 5
1101 2 mikel262
     -------------------------
1102 13 mikel262
     test_out <= 5;
1103
     tmp_matrix := input_data1;
1104
     -- compute reference coefficients
1105
     ref_matrix_1d := COMPUTE_REF_DCT1D(tmp_matrix,TRUE);
1106
     ref_matrix_2d := COMPUTE_REF_DCT1D(ref_matrix_1d,FALSE);
1107
 
1108
     for i in 0 to N-1 loop
1109
       j := 0;
1110
       while(true) loop
1111
 
1112
         waitposedge;
1113
         if odv = '1' then
1114
           dcto_matrix(j,i) := TO_INTEGER(SIGNED( dcto ));
1115
           j := j + 1;
1116
         end if;
1117
 
1118
         if j = N then
1119
           exit;
1120
         end if;
1121
 
1122
       end loop;
1123
     end loop;
1124
 
1125
     waitposedge;
1126
 
1127
     CMP_MATRIX(ref_matrix_2d,dcto_matrix,MAX_ERROR_2D,error_matrix,error_cnt);
1128
     idcto_matrix := COMPUTE_REF_IDCT(dcto_matrix);
1129
     psnr := COMPUTE_PSNR(tmp_matrix,idcto_matrix);
1130
     -------------------------
1131
 
1132
     -------------------------
1133 15 mikel262
     -- test 6-16
1134
     -------------------------
1135
     for x in 0 to 10 loop
1136
       test_out <= test_out+1;
1137
 
1138
       if x rem 2 = 0 then
1139
         tmp_matrix := input_data0;
1140
       else
1141
         tmp_matrix := input_data3;
1142
       end if;
1143
       -- compute reference coefficients
1144
       ref_matrix_1d := COMPUTE_REF_DCT1D(tmp_matrix,TRUE);
1145
       ref_matrix_2d := COMPUTE_REF_DCT1D(ref_matrix_1d,FALSE);
1146
 
1147
       for i in 0 to N-1 loop
1148
         j := 0;
1149
         while(true) loop
1150
 
1151
           waitposedge;
1152
           if odv = '1' then
1153
             dcto_matrix(j,i) := TO_INTEGER(SIGNED( dcto ));
1154
             j := j + 1;
1155
           end if;
1156
 
1157
           if j = N then
1158
             exit;
1159
           end if;
1160
 
1161
         end loop;
1162
       end loop;
1163
 
1164
       CMP_MATRIX(ref_matrix_2d,dcto_matrix,MAX_ERROR_2D,error_matrix,error_cnt);
1165
       idcto_matrix := COMPUTE_REF_IDCT(dcto_matrix);
1166
       psnr := COMPUTE_PSNR(tmp_matrix,idcto_matrix);
1167
     end loop;
1168
     -------------------------
1169
 
1170
     -------------------------
1171
     -- test 17-33
1172
     -------------------------
1173 18 mikel262
     for x in 0 to 16 loop
1174 15 mikel262
       test_out <= test_out+1;
1175
       if xi < 4 then
1176
         xi := xi + 1;
1177
       else
1178
         xi := 0;
1179
       end if;
1180
       case xi is
1181
         when 0 =>
1182
           tmp_matrix := input_data1;
1183
         when 1 =>
1184
           tmp_matrix := input_data0;
1185
         when 2 =>
1186
           tmp_matrix := input_data3;
1187
         when 3 =>
1188
           tmp_matrix := input_data4;
1189
         when others =>
1190
           tmp_matrix := input_data0;
1191
       end case;
1192
       -- compute reference coefficients
1193
       ref_matrix_1d := COMPUTE_REF_DCT1D(tmp_matrix,TRUE);
1194
       ref_matrix_2d := COMPUTE_REF_DCT1D(ref_matrix_1d,FALSE);
1195
 
1196
       for i in 0 to N-1 loop
1197
         j := 0;
1198
         while(true) loop
1199
 
1200
           waitposedge;
1201
           if odv = '1' then
1202
             dcto_matrix(j,i) := TO_INTEGER(SIGNED( dcto ));
1203
             j := j + 1;
1204
           end if;
1205
 
1206
           if j = N then
1207
             exit;
1208
           end if;
1209
 
1210
         end loop;
1211
       end loop;
1212
 
1213
       CMP_MATRIX(ref_matrix_2d,dcto_matrix,MAX_ERROR_2D,error_matrix,error_cnt);
1214
       idcto_matrix := COMPUTE_REF_IDCT(dcto_matrix);
1215
       psnr := COMPUTE_PSNR(tmp_matrix,idcto_matrix);
1216
     end loop;
1217
     -------------------------
1218
 
1219
     -------------------------
1220 13 mikel262
     -- test 6
1221
     -------------------------
1222
     test_out <= 6;
1223 15 mikel262
     if RUN_FULL_IMAGE = TRUE then
1224
       read_image_for2dct(error_cnt);
1225
     end if;
1226 2 mikel262
     -------------------------
1227
 
1228 13 mikel262
     -------------------------
1229
     -- test 7
1230
     -------------------------
1231
     test_out <= 7;
1232
     --read_image_for2dct(error_cnt);
1233
     -------------------------
1234
 
1235 2 mikel262
     waitposedge;
1236
     testend <= TRUE;
1237
     if error_cnt = 0 then
1238
       assert false
1239
         report "No errors found in second stage of DCT"
1240
         severity Note;
1241
     else
1242
       assert false
1243
         report "Found " & STR(error_cnt,10) & " errors in second stage of DCT!"
1244
         severity Error;
1245
     end if;
1246
     assert false
1247
       report "2D Test finished"
1248
       severity Note;
1249
 
1250
     wait;
1251
 end process;
1252
 
1253
end SIM;
1254
--**************************************************************************--

powered by: WebSVN 2.1.0

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