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

Subversion Repositories mdct

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

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

powered by: WebSVN 2.1.0

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