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.interface/] [udp2hibi/] [1.0/] [tb/] [tb_hibi_test.vhd] - Blame information for rev 183

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

Line No. Rev Author Line
1 145 lanttu
-------------------------------------------------------------------------------
2
-- Title      : Testbench with real hibi
3
-- Project    : UDP2HIBI
4
-------------------------------------------------------------------------------
5
-- File       : tb_hibi_test.vhd
6
-- Author     : Jussi Nieminen
7
-- Last update: 2012-03-23
8
-- Platform   : Sim only
9
-------------------------------------------------------------------------------
10
-- Description: -
11
-------------------------------------------------------------------------------
12
-- Revisions  :
13
-- Date        Version  Author  Description
14
-- 2009/12/28  1.0      niemin95        Created
15
-------------------------------------------------------------------------------
16
 
17
library ieee;
18
use ieee.std_logic_1164.all;
19
use ieee.numeric_std.all;
20
use work.udp2hibi_pkg.all;
21
 
22
 
23
entity tb_hibi_test is
24
  port (
25
    tx_cnt : out integer;
26
    rx_cnt : out integer);
27
end tb_hibi_test;
28
 
29
 
30
architecture tb of tb_hibi_test is
31
 
32
  constant frequency_c     : integer   := 50000000;
33
  constant period_c        : time      := 20 ns;
34
  constant udp_ip_period_c : time      := 40 ns;
35
  signal   clk             : std_logic := '1';
36
  signal   clk_udp         : std_logic := '1';
37
  signal   rst_n           : std_logic := '0';
38
 
39
  constant hibi_data_width_c : integer := 32;
40
  constant hibi_comm_width_c : integer := 3;
41
  constant hibi_addr_width_c : integer := 32;
42
 
43
  constant receiver_table_size_c    : integer := 4;
44
  constant tx_multiclk_fifo_depth_c : integer := 10;
45
  constant rx_multiclk_fifo_depth_c : integer := 10;
46
  constant hibi_tx_fifo_depth_c     : integer := 10;
47
  constant ack_fifo_depth_c         : integer := 4;
48
 
49
  signal test_data_to_hibi   : std_logic_vector( hibi_data_width_c-1 downto 0 ) := (others => '0');
50
  signal test_we_to_hibi     : std_logic := '0';
51
  signal test_av_to_hibi     : std_logic := '0';
52
  signal test_comm_to_hibi   : std_logic_vector( hibi_comm_width_c-1 downto 0 ) := (others => '0');
53
  signal test_full_from_hibi : std_logic;
54
 
55
  signal test_data_from_hibi  : std_logic_vector( hibi_data_width_c-1 downto 0 );
56
  signal test_empty_from_hibi : std_logic;
57
  signal test_av_from_hibi    : std_logic;
58
  signal test_comm_from_hibi  : std_logic_vector( hibi_comm_width_c-1 downto 0 );
59
  signal test_re_to_hibi      : std_logic := '0';
60
 
61
  signal data_hibi_udp2hibi  : std_logic_vector( hibi_data_width_c-1 downto 0 );
62
  signal empty_hibi_udp2hibi : std_logic;
63
  signal av_hibi_udp2hibi    : std_logic;
64
  signal comm_hibi_udp2hibi  : std_logic_vector( hibi_comm_width_c-1 downto 0 );
65
  signal re_udp2hibi_hibi    : std_logic;
66
 
67
  signal data_udp2hibi_hibi : std_logic_vector( hibi_data_width_c-1 downto 0 );
68
  signal we_udp2hibi_hibi   : std_logic;
69
  signal av_udp2hibi_hibi   : std_logic;
70
  signal comm_udp2hibi_hibi : std_logic_vector( hibi_comm_width_c-1 downto 0 );
71
  signal full_hibi_udp2hibi : std_logic;
72
 
73
  signal data_to_hibi   : std_logic_vector( 2* hibi_data_width_c-1 downto 0 );
74
  signal we_to_hibi     : std_logic_vector( 1 downto 0 );
75
  signal av_to_hibi     : std_logic_vector( 1 downto 0 );
76
  signal comm_to_hibi   : std_logic_vector( 2* hibi_comm_width_c-1 downto 0 );
77
  signal full_from_hibi : std_logic_vector( 1 downto 0 );
78
 
79
  signal data_from_hibi  : std_logic_vector( 2* hibi_data_width_c-1 downto 0 );
80
  signal empty_from_hibi : std_logic_vector( 1 downto 0 );
81
  signal av_from_hibi    : std_logic_vector( 1 downto 0 );
82
  signal re_to_hibi      : std_logic_vector( 1 downto 0 );
83
  signal comm_from_hibi  : std_logic_vector( 2* hibi_comm_width_c-1 downto 0 );
84
 
85
 
86
  signal tx_data_from_udp2hibi       : std_logic_vector( udp_block_data_w_c-1 downto 0 );
87
  signal tx_data_valid_from_udp2hibi : std_logic;
88
  signal tx_re_to_udp2hibi           : std_logic := '0';
89
  signal new_tx_from_udp2hibi        : std_logic;
90
  signal tx_len_from_udp2hibi        : std_logic_vector( tx_len_w_c-1 downto 0 );
91
  signal dest_ip_from_udp2hibi       : std_logic_vector( ip_addr_w_c-1 downto 0 );
92
  signal dest_port_from_udp2hibi     : std_logic_vector( udp_port_w_c-1 downto 0 );
93
  signal source_port_from_udp2hibi   : std_logic_vector( udp_port_w_c-1 downto 0 );
94
 
95
  signal rx_data_to_udp2hibi       : std_logic_vector( udp_block_data_w_c-1 downto 0 ) := (others => '0');
96
  signal rx_data_valid_to_udp2hibi : std_logic := '0';
97
  signal rx_re_from_udp2hibi       : std_logic;
98
  signal new_rx_to_udp2hibi        : std_logic := '0';
99
  signal rx_len_to_udp2hibi        : std_logic_vector( tx_len_w_c-1 downto 0 ) := (others => '0');
100
  signal source_ip_to_udp2hibi     : std_logic_vector( ip_addr_w_c-1 downto 0 ) := (others => '0');
101
  signal dest_port_to_udp2hibi     : std_logic_vector( udp_port_w_c-1 downto 0 ) := (others => '0');
102
  signal source_port_to_udp2hibi   : std_logic_vector( udp_port_w_c-1 downto 0 ) := (others => '0');
103
  signal rx_erroneous_to_udp2hibi  : std_logic := '0';
104
 
105
 
106
  -- test data ----------------------------------------------------------------
107
 
108
  constant test_len_bytes_c : integer := 1303;
109
  constant data_amount_c : integer := 16;
110
  type test_data_type is array (0 to data_amount_c-1) of std_logic_vector( hibi_data_width_c-1 downto 0 );
111
  constant test_data : test_data_type :=
112
    ( x"03020100", x"07060504", x"0b0a0908", x"0f0e0d0c",
113
      x"13121110", x"17161514", x"1b1a1918", x"1f1e1d1c",
114
      x"23222120", x"27262524", x"2b2a2928", x"2f2e2d2c",
115
      x"33323130", x"37363534", x"3b3a3938", x"3f3e3d3c" );
116
 
117
  type tx_conf_type is array (0 to 4) of std_logic_vector( hibi_data_width_c-1 downto 0 );
118
  constant tx_conf : tx_conf_type :=
119
    ( x"01000000", x"00001234", x"acdcabba", x"11112222", x"03000000" );
120
  constant rx_conf : tx_conf_type :=
121
    ( x"01000000", x"30000000", x"acdcabba", x"22221111", x"03000000" );
122
 
123
  constant simulation_timeout_c : integer := 5000;
124
  signal timeout_cnt_r : integer;
125
 
126
-------------------------------------------------------------------------------
127
begin  -- tb
128
-------------------------------------------------------------------------------
129
 
130
  av_to_hibi   <= test_av_to_hibi & av_udp2hibi_hibi;
131
  data_to_hibi <= test_data_to_hibi & data_udp2hibi_hibi;
132
  we_to_hibi   <= test_we_to_hibi & we_udp2hibi_hibi;
133
  re_to_hibi   <= test_re_to_hibi & re_udp2hibi_hibi;
134
 
135
  test_full_from_hibi  <= full_from_hibi(1);
136
  full_hibi_udp2hibi   <= full_from_hibi(0);
137
  test_av_from_hibi    <= av_from_hibi(1);
138
  av_hibi_udp2hibi     <= av_from_hibi(0);
139
  test_data_from_hibi  <= data_from_hibi( 2*hibi_data_width_c-1 downto hibi_data_width_c );
140
  data_hibi_udp2hibi   <= data_from_hibi( hibi_data_width_c-1 downto 0 );
141
  test_empty_from_hibi <= empty_from_hibi(1);
142
  empty_hibi_udp2hibi  <= empty_from_hibi(0);
143
 
144
--  hibi_bus : entity work.hibiv2
145
  hibi_bus : entity work.hibi_segment_v3
146
    generic map (
147
      use_monitor_g   => 0,
148
      data_width_g    => hibi_data_width_c,
149
      n_agents_g      => 2,
150
      n_segments_g    => 1,
151
      rel_ip_freq_g   => 1,
152
      rel_noc_freq_g  => 1
153
      )
154
    port map (
155
      clk_ip          => clk,
156
      clk_noc         => clk,
157
      rst_n           => rst_n,
158
      av_in           => av_to_hibi,
159
      data_in         => data_to_hibi,
160
      we_in           => we_to_hibi,
161
      full_out        => full_from_hibi,
162
      one_p_out       => open,
163
      av_out          => av_from_hibi,
164
      data_out        => data_from_hibi,
165
      re_in           => re_to_hibi,
166
      empty_out       => empty_from_hibi,
167
      one_d_out       => open,
168
      mon_UART_rx_in  => '1',
169
      mon_UART_tx_out => open,
170
      mon_command_in  => (others => '0')
171
      );
172
 
173
 
174
  udp2hibi_block : entity work.udp2hibi
175
    generic map (
176
      receiver_table_size_g    => receiver_table_size_c,
177
      ack_fifo_depth_g         => ack_fifo_depth_c,
178
      tx_multiclk_fifo_depth_g => tx_multiclk_fifo_depth_c,
179
      rx_multiclk_fifo_depth_g => rx_multiclk_fifo_depth_c,
180
      hibi_tx_fifo_depth_g     => hibi_tx_fifo_depth_c,
181
      hibi_data_width_g        => hibi_data_width_c,
182
      hibi_addr_width_g        => hibi_addr_width_c,
183
      hibi_comm_width_g        => hibi_comm_width_c,
184
      frequency_g              => frequency_c
185
      )
186
    port map (
187
      clk                      => clk,
188
      clk_udp                  => clk_udp,
189
      rst_n                    => rst_n,
190
      hibi_comm_in             => comm_hibi_udp2hibi,
191
      hibi_data_in             => data_hibi_udp2hibi,
192
      hibi_av_in               => av_hibi_udp2hibi,
193
      hibi_empty_in            => empty_hibi_udp2hibi,
194
      hibi_re_out              => re_udp2hibi_hibi,
195
      hibi_comm_out            => comm_udp2hibi_hibi,
196
      hibi_data_out            => data_udp2hibi_hibi,
197
      hibi_av_out              => av_udp2hibi_hibi,
198
      hibi_we_out              => we_udp2hibi_hibi,
199
      hibi_full_in             => full_hibi_udp2hibi,
200
      tx_data_out              => tx_data_from_udp2hibi,
201
      tx_data_valid_out        => tx_data_valid_from_udp2hibi,
202
      tx_re_in                 => tx_re_to_udp2hibi,
203
      new_tx_out               => new_tx_from_udp2hibi,
204
      tx_len_out               => tx_len_from_udp2hibi,
205
      dest_ip_out              => dest_ip_from_udp2hibi,
206
      dest_port_out            => dest_port_from_udp2hibi,
207
      source_port_out          => source_port_from_udp2hibi,
208
      rx_data_in               => rx_data_to_udp2hibi,
209
      rx_data_valid_in         => rx_data_valid_to_udp2hibi,
210
      rx_re_out                => rx_re_from_udp2hibi,
211
      new_rx_in                => new_rx_to_udp2hibi,
212
      rx_len_in                => rx_len_to_udp2hibi,
213
      source_ip_in             => source_ip_to_udp2hibi,
214
      dest_port_in             => dest_port_to_udp2hibi,
215
      source_port_in           => source_port_to_udp2hibi,
216
      rx_erroneous_in          => rx_erroneous_to_udp2hibi
217
      );
218
 
219
 
220
  -- clk generation
221
  clk <= not clk after period_c/2;
222
  clk_udp <= not clk_udp after udp_ip_period_c/2;
223
  rst_n <= '1' after period_c*4;
224
 
225
  -- *******
226
  -- test ip has address 0x03000000
227
  -- udp2hibi has address 0x01000000
228
 
229
  test_ip: process
230
  begin  -- process test_ip
231
 
232
    if rst_n = '0' then
233
      wait until rst_n = '1';
234
    end if;
235
 
236
    wait for period_c*4;
237
 
238
    -- send tx_conf, rx_conf and finally data
239
 
240
    ---------------------------------------------------------------------------
241
    -- tx_conf
242
    for n in 0 to 4 loop
243
 
244
      if n = 0 then
245
        test_av_to_hibi <= '1';
246
      else
247
        test_av_to_hibi <= '0';
248
      end if;
249
 
250
      test_we_to_hibi <= '1';
251
      test_data_to_hibi <= tx_conf(n);
252
 
253
      wait for period_c;
254
      if test_full_from_hibi = '1' then
255
        wait until test_full_from_hibi = '0';
256
        wait for period_c;
257
      end if;
258
 
259
    end loop;  -- n
260
    test_we_to_hibi <= '0';
261
 
262
    -- wait for the ack
263
    wait until test_empty_from_hibi = '0';
264
    test_re_to_hibi <= '1';
265
    wait for period_c*2;
266
    -- now the ack should be read
267
    assert test_data_from_hibi = x"58000000" report "Invalid tx ack from udp2hibi." severity failure;
268
    wait for period_c;
269
    assert test_empty_from_hibi = '1' report "Still not empty after tx ack?" severity failure;
270
    test_re_to_hibi <= '0';
271
    wait for period_c*2;
272
 
273
 
274
    ---------------------------------------------------------------------------
275
    -- rx_conf
276
    for n in 0 to 4 loop
277
 
278
      if n = 0 then
279
        test_av_to_hibi <= '1';
280
      else
281
        test_av_to_hibi <= '0';
282
      end if;
283
 
284
      test_we_to_hibi <= '1';
285
      test_data_to_hibi <= rx_conf(n);
286
 
287
      wait for period_c;
288
      if test_full_from_hibi = '1' then
289
        wait until test_full_from_hibi = '0';
290
        wait for period_c;
291
      end if;
292
 
293
    end loop;  -- n
294
    test_we_to_hibi <= '0';
295
 
296
    wait for period_c*4;
297
 
298
    -- wait for the ack
299
    wait until test_empty_from_hibi = '0';
300
    test_re_to_hibi <= '1';
301
    wait for period_c*2;
302
    -- now the ack should be read
303
    assert test_data_from_hibi = x"50000000" report "Invalid rx ack from udp2hibi." severity failure;
304
    wait for period_c;
305
    assert test_empty_from_hibi = '1' report "Still not empty after rx ack?" severity failure;
306
    test_re_to_hibi <= '0';
307
    wait for period_c*2;
308
 
309
    ---------------------------------------------------------------------------
310
    -- data, but first the address and data header
311
    test_av_to_hibi <= '1';
312
    test_we_to_hibi <= '1';
313
    test_data_to_hibi <= x"01000000";
314
    if test_full_from_hibi = '1' then
315
      wait until test_full_from_hibi = '0';
316
    end if;
317
    wait for period_c;
318
 
319
    test_av_to_hibi <= '0';
320
    test_data_to_hibi <= x"1" & std_logic_vector( to_unsigned( test_len_bytes_c, tx_len_w_c ))
321
                         & "00000000000000000";
322
    if test_full_from_hibi = '1' then
323
      wait until test_full_from_hibi = '0';
324
    end if;
325
    wait for period_c;
326
 
327
    -- now the data
328
    for n in 0 to (test_len_bytes_c+3)/4-1 loop
329
      tx_cnt <= n;
330
      test_data_to_hibi <= test_data(n mod data_amount_c);
331
      wait for period_c;
332
      if test_full_from_hibi = '1' then
333
        wait until test_full_from_hibi = '0';
334
        wait for period_c;
335
      end if;
336
    end loop;  -- n
337
 
338
    test_we_to_hibi <= '0';
339
    ---------------------------------------------------------------------------
340
 
341
    -- now wait for the data to come back
342
    wait until test_empty_from_hibi = '0';
343
    test_re_to_hibi <= '1';
344
    wait for period_c;
345
 
346
    -- read out the rx_header
347
    if test_empty_from_hibi = '1' then
348
      wait until test_empty_from_hibi = '0';
349
    end if;
350
    wait for period_c;
351
 
352
    assert test_data_from_hibi( 31 downto 17 ) = x"4"
353
      & std_logic_vector( to_unsigned( test_len_bytes_c, tx_len_w_c ))
354
      report "Invalid rx header for test ip." severity failure;
355
 
356
    -- read the data
357
    for n in 0 to (test_len_bytes_c+3)/4-1 loop
358
      wait for period_c;
359
      if test_empty_from_hibi = '1' then
360
        wait until test_empty_from_hibi = '0';
361
        wait for period_c;
362
      end if;
363
 
364
      -- ignore addresses
365
      if test_av_from_hibi = '1' then
366
        wait for period_c;
367
        if test_empty_from_hibi = '1' then
368
          wait until test_empty_from_hibi = '0';
369
          wait for period_c;
370
        end if;
371
      end if;
372
 
373
      assert test_data_from_hibi = test_data(n mod data_amount_c)
374
        report "Invalid return data to test process." severity failure;
375
    end loop;  -- n
376
    test_re_to_hibi <= '0';
377
 
378
    wait for period_c*10;
379
    report "Simulation ended." severity failure;
380
 
381
  end process test_ip;
382
 
383
  -----------------------------------------------------------------------------
384
  -----------------------------------------------------------------------------
385
 
386
  udp_ip: process
387
    variable tx_len_int : integer;
388
  begin  -- process udp_ip
389
 
390
    wait until new_tx_from_udp2hibi = '1';
391
    if clk_udp = '0' then
392
      wait until clk_udp = '1';
393
    end if;
394
 
395
    wait for udp_ip_period_c;
396
 
397
    tx_len_int := to_integer( unsigned( tx_len_from_udp2hibi ));
398
 
399
    assert
400
      dest_ip_from_udp2hibi = x"acdcabba" and
401
      dest_port_from_udp2hibi = x"1111" and
402
      source_port_from_udp2hibi = x"2222" and
403
      tx_len_int = test_len_bytes_c
404
      report "Invalid tx info from udp2hibi." severity failure;
405
 
406
    assert tx_data_valid_from_udp2hibi = '1' report "Tx data not valid??" severity failure;
407
 
408
    -- read data
409
    tx_re_to_udp2hibi <= '1';
410
    for n in 0 to (test_len_bytes_c+1)/2-1 loop
411
      if tx_data_valid_from_udp2hibi = '0' then
412
        wait until tx_data_valid_from_udp2hibi = '1';
413
      end if;
414
      wait for udp_ip_period_c;
415
      assert
416
        ( n mod 2 = 0 and
417
          tx_data_from_udp2hibi = test_data((n/2) mod data_amount_c)(15 downto 0) ) or
418
        ( n mod 2 = 1 and
419
          tx_data_from_udp2hibi = test_data((n/2) mod data_amount_c)(31 downto 16) )
420
        report "Invalid data from udp2hibi." severity failure;
421
    end loop;  -- n
422
 
423
    -- wait for a while, and send data back
424
    wait for udp_ip_period_c*10;
425
 
426
    new_rx_to_udp2hibi <= '1';
427
    source_ip_to_udp2hibi <= x"acdcabba";
428
    dest_port_to_udp2hibi <= x"2222";
429
    source_port_to_udp2hibi <= x"1111";
430
    rx_erroneous_to_udp2hibi <= '0';
431
    rx_len_to_udp2hibi <= std_logic_vector( to_unsigned( test_len_bytes_c, tx_len_w_c ));
432
    rx_data_to_udp2hibi <= test_data(0)(15 downto 0);
433
    rx_data_valid_to_udp2hibi <= '1';
434
 
435
    wait until rx_re_from_udp2hibi = '1';
436
    if clk_udp = '0' then
437
      wait until clk_udp = '1';
438
    else
439
      wait for udp_ip_period_c;
440
    end if;
441
 
442
    new_rx_to_udp2hibi <= '0';
443
 
444
    for n in 1 to (test_len_bytes_c+1)/2-1 loop
445
      rx_cnt <= n;
446
      if n mod 2 = 0 then
447
        rx_data_to_udp2hibi <= test_data((n/2) mod data_amount_c)(15 downto 0);
448
      else
449
        rx_data_to_udp2hibi <= test_data((n/2) mod data_amount_c)(31 downto 16);
450
      end if;
451
      wait for udp_ip_period_c;
452
      if rx_re_from_udp2hibi = '0' then
453
        wait until rx_re_from_udp2hibi = '1';
454
        wait for udp_ip_period_c;
455
      end if;
456
    end loop;  -- n
457
    rx_data_valid_to_udp2hibi <= '0';
458
 
459
    -- wait forever
460
    wait;
461
 
462
  end process udp_ip;
463
 
464
  -----------------------------------------------------------------------------
465
  -----------------------------------------------------------------------------
466
 
467
  timeout_proc: process (clk, rst_n)
468
  begin  -- process timeout_proc
469
    if rst_n = '0' then                 -- asynchronous reset (active low)
470
      timeout_cnt_r <= 0;
471
    elsif clk'event and clk = '1' then  -- rising clock edge
472
      assert timeout_cnt_r < simulation_timeout_c report "Timeout! Something went wrong..." severity failure;
473
      timeout_cnt_r <= timeout_cnt_r + 1;
474
    end if;
475
  end process timeout_proc;
476
 
477
end tb;

powered by: WebSVN 2.1.0

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