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

Subversion Repositories funbase_ip_library

[/] [funbase_ip_library/] [trunk/] [TUT/] [ip.hwp.accelerator/] [dct_to_hibi/] [1.0/] [tb/] [tb_dct_cpu.vhd] - Blame information for rev 168

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
-------------------------------------------------------------------------------
2
-- Title      : Testbench for dct, CPU emulator
3
-- Project    : 
4
-------------------------------------------------------------------------------
5
-- File       : tb_dct_cpu.vhd
6
-- Author     : 
7
-- Company    : 
8
-- Created    : 2006-05-24
9 168 lanttu
-- Last update: 2013-03-22
10 145 lanttu
-- Platform   : 
11
-- Standard   : VHDL'87
12
-------------------------------------------------------------------------------
13
-- Description: CPU emulator
14
-------------------------------------------------------------------------------
15
-- Copyright (c) 2006 
16
-------------------------------------------------------------------------------
17
-- Revisions  :
18
-- Date        Version  Author  Description
19
-- 2006-05-24  1.0      rasmusa Created
20
-------------------------------------------------------------------------------
21
 
22
library IEEE;
23
use ieee.std_logic_1164.all;
24
use ieee.numeric_std.all;
25
use ieee.std_logic_textio.all;
26
use ieee.std_logic_misc.all;
27
 
28
 
29
library std;
30
use std.textio.all;
31
use work.tb_dct_package.all;
32
 
33
library dct;
34
library idct;
35
library quantizer;
36
library dctQidct;
37
 
38
use dct.DCT_pkg.all;
39
use idct.IDCT_pkg.all;
40
use quantizer.Quantizer_pkg.all;
41
 
42
entity tb_dct_cpu is
43
 
44
  generic (
45
    data_width_g : integer := 32;
46 168 lanttu
    comm_width_g : integer := 5);
47 145 lanttu
  port (
48
    clk_dctqidct_fast : in std_logic;
49
    clk               : in std_logic;
50
    rst_n             : in std_logic;
51
 
52
    data_in  : in  std_logic_vector(data_width_g-1 downto 0);
53
    comm_in  : in  std_logic_vector(comm_width_g-1 downto 0);
54
    av_in    : in  std_logic;
55
    re_out   : out std_logic;
56
    empty_in : in  std_logic;
57
 
58
    data_out : out std_logic_vector(data_width_g-1 downto 0);
59
    comm_out : out std_logic_vector(comm_width_g-1 downto 0);
60
    av_out   : out std_logic;
61
    we_out   : out std_logic;
62
    full_in  : in  std_logic;
63
 
64
    dct_data_idct_in  : in std_logic_vector(IDCT_resultw_co-1 downto 0);
65
    dct_data_quant_in : in std_logic_vector(QUANT_resultw_co-1 downto 0);
66
    dct_wr_idct_in    : in std_logic;
67
    dct_wr_quant_in   : in std_logic;
68
    dct_wr_dct_in     : in std_logic;
69
    dct_data_dct_in   : in std_logic_vector(DCT_inputw_co-1 downto 0);
70
    dct_qp_in         : in std_logic_vector(4 downto 0);
71
    dct_intra_in      : in std_logic;
72
    dct_chroma_in     : in std_logic;
73
    dct_loadqp_in     : in std_logic
74
 
75
    );
76
 
77
end tb_dct_cpu;
78
 
79
architecture rtl of tb_dct_cpu is
80
 
81
  constant hibi_addr_cpu_q_c : integer := hibi_addr_cpu_c + 1;
82
  constant hibi_addr_cpu_i_c : integer := hibi_addr_cpu_c + 2;
83
 
84
  constant data_max_c : integer := 384;
85
  constant n_blocks_c : integer := 6;
86
  type     value_vect_type is array (0 to data_max_c-1) of std_logic_vector(16-1 downto 0);
87
  type     qp_vect_type is array (0 to n_blocks_c-1) of std_logic_vector(4 downto 0);
88
  constant qp_w_c     : integer := 5;
89
 
90
 
91
  type data_type is record
92
    original  : value_vect_type;
93
    dct_org   : value_vect_type;
94
    dct_idct  : value_vect_type;
95
    idct      : value_vect_type;
96
    dct_quant : value_vect_type;
97
    quant     : value_vect_type;
98
    qp        : qp_vect_type;
99
    chroma    : std_logic_vector(6-1 downto 0);
100
    intra     : std_logic_vector(6-1 downto 0);
101
  end record;
102
 
103
  constant qp_c : integer := 1;
104
 
105
  constant values_per_word_c : integer := data_width_g/16;
106
 
107
  signal data_counter_r : integer range 0 to data_max_c-1;
108
  signal rx_counter_r   : integer range 0 to 8*8-1;
109
 
110
  signal idle_counter_r : integer;
111
 
112
  signal data_r : data_type;
113
 
114
  signal q_counter_r : integer range 0 to data_max_c-1;
115
  signal i_counter_r : integer range 0 to data_max_c-1;
116
  signal d_counter_r : integer range 0 to data_max_c-1;
117
  signal qp_counter_r : integer range 0 to data_max_c-1;
118
 
119
  signal res_q_cnt_r : integer range 0 to data_max_c-1;
120
  signal res_i_cnt_r : integer range 0 to data_max_c-1;
121
 
122
  signal result_is_quant_r : std_logic;
123
  signal last_av_r : integer;
124
 
125
  signal wait_zero_r : std_logic;
126
 
127 168 lanttu
  signal test_data_type : integer := 2;
128 145 lanttu
 
129
  -- CONTROL WORD CONFIG
130
  signal intra : std_logic := '0';
131
--  signal intra_old_r : std_logic;
132
  signal qp    : std_logic_vector(qp_w_c-1 downto 0) := std_logic_vector(to_unsigned(qp_c, qp_w_c));
133
 
134
  type   send_control_type is (idle, send_av, send_ret_addr_q, send_ret_addr_i, send_control, send_data);
135
  signal send_ctrl,send_ctrl_old : send_control_type;
136
 
137
  signal free_r : std_logic;
138
  signal new_req_r  : std_logic;
139
 
140
  function generate_data (
141
    constant test_data_type : integer )
142
    return value_vect_type is
143
    variable ret_v : value_vect_type;
144
  begin  -- generate_data
145
    for i in 0 to data_max_c-1 loop
146
      if test_data_type = 0 then
147
        ret_v(i) := std_logic_vector(resize(to_signed( 0, DCT_inputw_co), 16));
148
      elsif test_data_type = 1 then
149
        ret_v(i) := std_logic_vector(resize(to_signed( 28, DCT_inputw_co), 16));
150
      elsif test_data_type = 2 then
151
        ret_v(i) := std_logic_vector(resize(to_signed( ((i*4) mod (i+1))*7, DCT_inputw_co), 16));
152
      end if;
153
    end loop;  -- i
154
    return ret_v;
155
  end generate_data;
156
 
157
 
158
begin  -- rtl
159
 
160
  re_out <= not empty_in;
161
 
162
  process (clk, rst_n)
163
    variable zero_vect_v : std_logic_vector(data_width_g-qp_w_c-1-1 downto 0) := (others => '0');
164
  begin  -- process
165
 
166
    if rst_n = '0' then                 -- asynchronous reset (active low)
167
      send_ctrl       <= idle;
168
      free_r          <= '1';
169
      data_r.original <= generate_data(test_data_type);
170
      send_ctrl <= idle;
171
      idle_counter_r <= 0;
172
    elsif clk'event and clk = '1' then  -- rising clock edge
173
 
174
      send_ctrl_old <= send_ctrl;
175
      if send_ctrl_old /= send_ctrl then
176
        idle_counter_r <= 0;
177
      else
178
        idle_counter_r <= idle_counter_r + 1;
179
      end if;
180
 
181
      assert idle_counter_r < 20000 report "IDLE TIME EXCEEDED" severity failure;
182
 
183
      case send_ctrl is
184
 
185
        when idle =>
186
          if full_in = '0' then
187
            we_out   <= '0';
188
            data_out <= (others => '0');
189
            comm_out <= (others => '0');
190
 
191
            if free_r = '1' or new_req_r = '1' then
192
              send_ctrl <= send_av;
193
              free_r    <= '0';
194
            end if;
195
 
196
          end if;
197
 
198
 
199
        when send_av =>
200
          av_out    <= '1';
201
          data_out  <= std_logic_vector(to_unsigned(hibi_addr_dct_c, data_width_g));
202
          we_out    <= '1';
203 168 lanttu
          comm_out  <= "00010";
204 145 lanttu
          send_ctrl <= send_ret_addr_q;
205
 
206
        when send_ret_addr_q =>
207
          if full_in = '0' then
208
            av_out    <= '0';
209
            data_out  <= std_logic_vector(to_unsigned(hibi_addr_cpu_q_c, data_width_g));
210
            we_out    <= '1';
211
            send_ctrl <= send_ret_addr_i;
212
          end if;
213
 
214
        when send_ret_addr_i =>
215
          if full_in = '0' then
216
            data_out  <= std_logic_vector(to_unsigned(hibi_addr_cpu_i_c, data_width_g));
217
            we_out    <= '1';
218
            send_ctrl <= send_control;
219
          end if;
220
 
221
        when send_control =>
222
          if full_in = '0' then
223
            data_out  <= zero_vect_v & intra & qp;
224
            we_out    <= '1';
225
            send_ctrl <= send_data;
226
            assert false report "REQUEST SENT" severity note;
227
          end if;
228
 
229
        when send_data =>
230
          if full_in = '0' then
231
            we_out <= '1';
232
 
233
            for i in 0 to values_per_word_c-1 loop
234
              data_out((i+1)*16-1 downto i*16) <= data_r.original(data_counter_r + i);
235
            end loop;  -- i           
236
 
237
            if data_counter_r = data_max_c-values_per_word_c then
238
              send_ctrl      <= idle;
239
              data_counter_r <= 0;
240
              assert false report "Data sent!" severity note;
241
            else
242
              data_counter_r <= data_counter_r + values_per_word_c;
243
            end if;
244
 
245
          end if;
246
 
247
        when others => null;
248
      end case;
249
 
250
 
251
    end if;
252
  end process;
253
 
254
  re_out <= not empty_in;
255
 
256
  rx_proc : process (clk, rst_n)
257
    variable or_v : std_logic_vector(5 downto 0);
258
  begin  -- process rx_proc
259
    if rst_n = '0' then                 -- asynchronous reset (active low)
260
      rx_counter_r      <= 0;
261
      result_is_quant_r <= '1';
262
      res_q_cnt_r       <= 0;
263
      res_i_cnt_r       <= 0;
264
      new_req_r <= '0';
265
      wait_zero_r <= '0';
266
 
267
    elsif clk'event and clk = '1' then  -- rising clock edge
268
 
269
      new_req_r <= '0';
270
 
271
      if empty_in = '0' and av_in = '1' then
272
        last_av_r <= to_integer(unsigned(data_in));
273
      end if;
274
 
275
      if empty_in = '0' and av_in = '1' and data_in = std_logic_vector(to_unsigned(hibi_addr_cpu_rtm_c+2,data_width_g)) then
276 168 lanttu
       assert false report "Got release!" severity note;
277
       new_req_r <= '1';
278
       end if;
279 145 lanttu
 
280
      if res_q_cnt_r /= 0 and wait_zero_r = '0' then
281
        wait_zero_r <= '1';
282
      end if;
283
 
284
      if res_q_cnt_r = 0 and empty_in = '0' and av_in = '0' and wait_zero_r = '1' and (last_av_r = hibi_addr_cpu_q_c ) then
285
        or_v := (others => '0');
286
 
287
        for j in 0 to 5 loop
288
          for i in j*64 to (j+1)*64-1 loop
289
            if intra = '0' or i mod 64 /= 0 then
290
              or_v(j) := or_v(j) or or_reduce( data_r.quant(i) );
291
            end if;
292
          end loop;  -- i          
293
        end loop;  -- j
294
 
295
 
296
--        for i in 0 to data_max_c-1 loop
297
--          if intra = '1' then
298
--            if i mod 64 /= 0 then
299
--              or_v := or_v or or_reduce(data_r.quant(i));              
300
--            end if;
301
--          else
302
--            or_v := or_v or or_reduce(data_r.quant(i));
303
--          end if;
304
--        end loop;  -- i
305
 
306
        assert false report "Got zero bit" severity note;
307
        assert or_v = data_in(5 downto 0) report "Zero bits do not match!" severity failure;
308
 
309
 
310
        wait_zero_r <= '0';
311
        data_r.quant <= (others => (others => '0'));
312
 
313
 
314
      elsif empty_in = '0' and av_in = '0' and (last_av_r = hibi_addr_cpu_i_c or last_av_r = hibi_addr_cpu_q_c) then
315
 
316
        if result_is_quant_r = '1' then
317
 
318
          for i in 0 to values_per_word_c-1 loop
319
            assert data_in((i+1)*16-1 downto i*16) = data_r.dct_quant(res_q_cnt_r+i) report "Result data mismatch in QUANT" severity failure;
320
            data_r.quant(res_q_cnt_r+i) <= data_in((i+1)*16-1 downto i*16);
321
          end loop;  -- i
322
 
323
          if res_q_cnt_r = data_max_c-values_per_word_c then
324
            res_q_cnt_r <= 0;
325
            assert false report "QUANT Data received!" severity note;
326
          else
327
            res_q_cnt_r <= res_q_cnt_r + values_per_word_c;
328
          end if;
329
 
330
        else
331
          for i in 0 to values_per_word_c-1 loop
332
            assert data_in((i+1)*16-1 downto i*16) = data_r.dct_idct(res_i_cnt_r+i) report "Result data mismatch in IDCT" severity failure;
333
            data_r.idct(res_i_cnt_r+i) <= data_in((i+1)*16-1 downto i*16);
334
          end loop;  -- i
335
 
336
          --res_i_cnt_r <= res_i_cnt_r + values_per_word_c;
337
 
338
          if res_i_cnt_r = data_max_c-values_per_word_c then
339
            res_i_cnt_r <= 0;
340
            data_r.idct <= (others => (others => '0'));
341 168 lanttu
            assert false report "IDCT Data received!" severity note;
342
            --new_req_r <= '1';           -- LM to no self 
343 145 lanttu
          else
344
            res_i_cnt_r <= res_i_cnt_r + values_per_word_c;
345
          end if;
346
 
347
        end if;
348
 
349
        if rx_counter_r = 8*8-values_per_word_c then
350
          rx_counter_r      <= 0;
351
          result_is_quant_r <= not result_is_quant_r;
352
        else
353
          rx_counter_r <= rx_counter_r + values_per_word_c;
354
        end if;
355
 
356
      end if;
357
    end if;
358
  end process rx_proc;
359
 
360
 
361
  ref_storing : process (clk_dctqidct_fast, rst_n)
362
    variable dct_data_v : std_logic_vector(16-1 downto 0);
363
  begin  -- process result_storing
364
    if rst_n = '0' then                 -- asynchronous reset (active low)
365
      q_counter_r <= 0;
366
      i_counter_r <= 0;
367
      d_counter_r <= 0;
368
 
369
 
370
    elsif clk_dctqidct_fast'event and clk_dctqidct_fast = '1' then  -- rising clock edge
371
 
372
 
373
      if dct_wr_idct_in = '1' then
374
 
375
        data_r.dct_idct(i_counter_r) <= std_logic_vector(resize(signed(dct_data_idct_in), 16));
376
 
377
        if i_counter_r = data_max_c-1 then
378
          i_counter_r <= 0;
379
        else
380
          i_counter_r <= i_counter_r + 1;
381
        end if;
382
 
383
      end if;
384
 
385
      if dct_wr_quant_in = '1' then
386
 
387
        if q_counter_r mod 64 = 0 and intra = '1' then
388
          data_r.dct_quant(q_counter_r) <= std_logic_vector(resize(unsigned(dct_data_quant_in), 16));
389
        else
390
          data_r.dct_quant(q_counter_r) <= std_logic_vector(resize(signed(dct_data_quant_in), 16));
391
        end if;
392
 
393
        if q_counter_r = data_max_c-1 then
394
          q_counter_r <= 0;
395
        else
396
          q_counter_r <= q_counter_r + 1;
397
        end if;
398
 
399
      end if;
400
 
401
      if dct_wr_dct_in = '1' then
402
        dct_data_v := std_logic_vector(resize(signed(dct_data_dct_in), 16));
403
 
404
        assert dct_data_v = data_r.original(d_counter_r) report "DCT Input MISMATCH" severity failure;
405
        data_r.dct_org(d_counter_r) <= dct_data_v;
406
 
407
 
408
        if d_counter_r = data_max_c-1 then
409
          d_counter_r <= 0;
410
        else
411
          d_counter_r <= d_counter_r + 1;
412
        end if;
413
 
414
      end if;
415
 
416
      if dct_loadqp_in = '1' then
417
 
418
        assert dct_chroma_in = '1' or ( qp_counter_r /= 4 and qp_counter_r /= 5 ) report "CHROMA FAILURE" severity failure;
419
 
420
        assert dct_intra_in = intra report "INTRA FAILURE" severity failure;
421
        assert dct_qp_in = qp report "QP FAILURE" severity failure;
422
 
423
        data_r.chroma( qp_counter_r ) <= dct_chroma_in;
424
        data_r.intra ( qp_counter_r ) <= dct_intra_in;
425
        data_r.qp( qp_counter_r ) <= dct_qp_in;
426
 
427
 
428
        if qp_counter_r = n_blocks_c-1 then
429
          qp_counter_r <= 0;
430
          assert false report "All QPs went right!" severity note;
431
        else
432
          qp_counter_r <= qp_counter_r + 1;
433
        end if;
434
 
435
      end if;
436
 
437
 
438
    end if;
439
  end process ref_storing;
440
 
441
end rtl;

powered by: WebSVN 2.1.0

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