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_receiver.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 for hibi receiver
3
-- Project    : UDP2HIBI
4
-------------------------------------------------------------------------------
5
-- File       : tb_hibi_receiver.vhd
6
-- Author     : Jussi Nieminen  <niemin95@galapagosinkeiju.cs.tut.fi>
7
-- Last update: 2012-03-23
8
-- Platform   : Sim only
9
-------------------------------------------------------------------------------
10
-- Description: Set of hard-coded directed tests.
11
-- 
12
--              There are few (e.g. 3) invalid transfers and DUV might issue
13
--              a warning from them.
14
-------------------------------------------------------------------------------
15
-- Revisions  :
16
-- Date        Version  Author  Description
17
-- 2009/12/08  1.0      niemin95        Created
18
-------------------------------------------------------------------------------
19
 
20
 
21
library ieee;
22
use ieee.std_logic_1164.all;
23
use ieee.numeric_std.all;
24
use work.udp2hibi_pkg.all;
25
 
26
entity tb_hibi_receiver is
27
end tb_hibi_receiver;
28
 
29
architecture tb of tb_hibi_receiver is
30
 
31
  constant period_c : time      := 20 ns;
32
  signal   clk      : std_logic := '1';
33
  signal   rst_n    : std_logic := '0';
34
 
35
 
36
  -- Incoming data from HIBI bus
37
  constant hibi_comm_width_c : integer := 5;  --3;
38
  constant hibi_addr_width_c : integer := 32;
39
  constant hibi_data_width_c : integer := 32;
40
 
41
  signal hibi_comm_to_duv       : std_logic_vector(hibi_comm_width_c-1 downto 0) := (others => '0');
42
  signal hibi_data_to_duv       : std_logic_vector(hibi_data_width_c-1 downto 0) := (others => '0');
43
  signal hibi_av_to_duv         : std_logic                                      := '0';
44
  signal hibi_empty_to_duv      : std_logic                                      := '1';
45
  signal hibi_re_from_duv       : std_logic;
46
 
47
 
48
  -- Going from DUV to tx-ctrl
49
  signal tx_data_from_duv       : std_logic_vector(udp_block_data_w_c-1 downto 0);
50
  signal tx_we_from_duv         : std_logic;
51
  signal tx_full_to_duv         : std_logic                                      := '0';
52
  signal new_tx_from_duv        : std_logic;
53
  signal tx_length_from_duv     : std_logic_vector(tx_len_w_c-1 downto 0);
54
  signal new_tx_ack_to_duv      : std_logic                                      := '0';
55
  signal release_lock_from_duv  : std_logic;
56
  signal new_tx_conf_from_duv   : std_logic;
57
  signal new_rx_conf_from_duv   : std_logic;
58
  signal ip_from_duv            : std_logic_vector(ip_addr_w_c-1 downto 0);
59
  signal dest_port_from_duv     : std_logic_vector(udp_port_w_c-1 downto 0);
60
  signal source_port_from_duv   : std_logic_vector(udp_port_w_c-1 downto 0);
61
  signal lock_addr_from_duv     : std_logic_vector(hibi_addr_width_c-1 downto 0);
62
  signal response_addr_from_duv : std_logic_vector(hibi_addr_width_c-1 downto 0);
63
  signal timeout_from_duv       : std_logic_vector(timeout_w_c-1 downto 0);
64
 
65
  -- From ctrl-regs to DUV
66
  signal lock_to_duv            : std_logic                                      := '0';
67
  signal lock_addr_to_duv       : std_logic_vector(hibi_addr_width_c-1 downto 0) := (others => '0');
68
 
69
  -- representing ctrl_regs
70
  signal regs_locked    : std_logic                                      := '0';
71
  signal regs_lock_addr : std_logic_vector(hibi_addr_width_c-1 downto 0) := (others => '0');
72
 
73
  -- for data going to multiclk_fifo:
74
  signal fifo_cnt : integer := 0;
75
 
76
 
77
 
78
 
79
  -----------------------------------------------------------------------------
80
  -- Type defs for test data
81
 
82
  type tx_data_type is array (integer range <>) of std_logic_vector(hibi_data_width_c-1 downto 0);
83
  type tx_info_type is
84
  record
85
    addr           : std_logic_vector(hibi_addr_width_c-1 downto 0);  -- addr from hibi
86
    len            : integer;           -- #hibi words (e.g. 32b)
87
    data_16bit_len : integer;           -- #16-b words, only in data tx, not in conf
88
    delay          : time;              -- between incoming hibi transfers
89
    data           : tx_data_type(0 to 18);  -- incoming data values
90
  end record;
91
 
92
 
93
 
94
  -----------------------------------------------------------------------------
95
  -- Test traffic.
96
  -- Change these values, and perhaps the tx_info_type, to create new tests.
97
  -- Note that monitor process is hard-coded to match these!
98
 
99
  signal   current_tx   : integer := 0;
100
 
101
  constant num_of_txs_c : integer := 13;
102
  type     test_txs_type is array (0 to num_of_txs_c-1) of tx_info_type;
103
 
104
  type     test_data_type is array (0 to 5) of std_logic_vector(15 downto 0);
105
  constant data1_c : test_data_type :=
106
    (x"0100", x"0302", x"0504", x"0706", x"0908", x"0a0b");
107
 
108
 
109
  -- Tx configuration needs 4 words
110
  -- 0:timeout, 1: dst ip addr
111
  -- 2: dst udp port & src udp port, 3: hibi addr (for ack/nack)
112
  -- 
113
  -- Data transfers starts with word: 0x0001 & tx_len(11b) & zeros.
114
  -- Release needs one data word that starts with 0x2...
115
 
116
  -- Rx configuration is similar but without timeout. Hibi addr is used
117
  -- for ack/nack and for the actual data.
118
 
119
 
120
  constant test_txs_c : test_txs_type := (
121
    -- 0: tx_conf, this should get regs locked
122
    (addr  => x"01234567", len => 4, data_16bit_len => 0, delay => 1 us,
123
      data => (x"00001234", x"acdcabba", x"0101aaaa", x"0082faac", others => (others => '0'))),
124
    -- 1: another tx_conf, forwarded to ctrl-regs which will ignore it
125
    (addr  => x"01234568", len => 4, data_16bit_len => 0, delay => 1 us,
126
      data => (x"00002212", x"abbacd00", x"1010bbbb", x"0080beba", others => (others => '0'))),
127
 
128
    -- 2: start a small tx by correct addr (11 bytes)
129
    (addr  => x"01234567", len => 4, data_16bit_len => 6, delay => 1 us,
130
      data => (x"1" & "00000001011" & "00000000000000000",
131
               data1_c(1) & data1_c(0),
132
               data1_c(3) & data1_c(2),
133
               data1_c(5) & data1_c(4), others => (others => '0'))),
134
    -- 3: start another small tx by correct addr (12 bytes)
135
    (addr                                      => x"01234567", len => 4, data_16bit_len => 6, delay => 1 us,
136
      data                                     => (x"1" & "00000001100" & "00000000000000000",
137
               data1_c(1) & data1_c(0),
138
               data1_c(3) & data1_c(2),
139
               data1_c(5) & data1_c(4), others => (others => '0'))),
140
    -- 4: tx with incorrect addr (not locked), 3 bytes, put zeros to last data words since they wont be sent
141
    (addr                                                  => x"01234568", len => 2, data_16bit_len => 0, delay => 1 us,
142
      data                                                 => (x"1" & "00000000011" & "00000000000000000",
143
                                       x"ff020100", others => (others => '0'))),
144
    -- 5: invalid release (address that was not locked)
145
    (addr  => x"0123ffff", len => 1, data_16bit_len => 0, delay => 1 us,
146
      data => (x"2fffffff", others => (others => '0'))),
147
    -- 6: releasing the correct release
148
    (addr  => x"01234567", len => 1, data_16bit_len => 0, delay => 1 us,
149
      data => (x"2fffffff", others => (others => '0'))),
150
 
151
 
152
 
153
    -- 7: new tx_conf with totally new hibi ddr
154
    (addr  => x"fedcba98", len => 4, data_16bit_len => 0, delay => 1 us,
155
      data => (x"00001111", x"0a00000a", x"ffffeeee", x"00880280", others => (others => '0'))),
156
    -- 8: and another conf to the same address, overrides the
157
    -- previous config(probably?)
158
    (addr  => x"fedcba98", len => 4, data_16bit_len => 0, delay => 1 us,
159
      data => (x"00002222", x"0b00000b", x"ddddcccc", x"00880280", others => (others => '0'))),
160
 
161
    -- 9: rx conf packet
162
    (addr  => x"14235867", len => 4, data_16bit_len => 0, delay => 1 us,
163
      data => (x"30f0f0f0", x"0f00130b", x"33334444", x"00112233", others => (others => '0'))),
164
    -- 10: invalid tx from some other sender (9 bytes)
165
    (addr                                                    => x"01010101", len => 4, data_16bit_len => 0, delay => 1 us,
166
      data                                                   => (x"1" & "00000001001" & "10001100011000001",
167
               x"03020100", x"07060504", x"ffffff08", others => (others => '0'))),
168
    -- 11: long tx from the correct sender (72 bytes)
169
    (addr  => x"fedcba98", len => 19, data_16bit_len => 36, delay => 1 us,
170
      data => (x"1" & "00001001000" & "10000100011100001",
171
               data1_c(1) & data1_c(0),  -- 1
172
               data1_c(3) & data1_c(2),
173
               data1_c(5) & data1_c(4),
174
               data1_c(1) & data1_c(0),
175
               data1_c(3) & data1_c(2),  -- 5
176
               data1_c(5) & data1_c(4),
177
               data1_c(1) & data1_c(0),
178
               data1_c(3) & data1_c(2),
179
               data1_c(5) & data1_c(4),
180
               data1_c(1) & data1_c(0),  -- 10
181
               data1_c(3) & data1_c(2),
182
               data1_c(5) & data1_c(4),
183
               data1_c(1) & data1_c(0),
184
               data1_c(3) & data1_c(2),
185
               data1_c(5) & data1_c(4),  -- 15
186
               data1_c(1) & data1_c(0),
187
               data1_c(3) & data1_c(2),
188
               data1_c(5) & data1_c(4)   -- 18
189
               )),
190
    -- 12: release
191
    (addr  => x"fedcba98", len => 1, data_16bit_len => 0, delay => 1 us,
192
      data => (x"20000000", others => (others => '0')))
193
    );
194
 
195
  -----------------------------------------------------------------------------
196
 
197
 
198
 
199
 
200
-------------------------------------------------------------------------------
201
begin  -- tb
202
-------------------------------------------------------------------------------
203
 
204
  -- clock generation and reset
205
  clk   <= not clk after period_c/2;
206
  rst_n <= '1'     after 4*period_c;
207
 
208
 
209
  --
210
  -- TB structure 
211
  --
212
  -- (proc hibi) --> DUV  ---> (proc ctrl regs)
213
  --                      +--> (proc tx_ctrl)
214
  --                   
215
  -- Moreover, (proc monitor) checks various things
216
 
217
 
218
 
219
 
220
  duv : entity work.hibi_receiver
221
    generic map (
222
      hibi_comm_width_g => hibi_comm_width_c,
223
      hibi_addr_width_g => hibi_addr_width_c,
224
      hibi_data_width_g => hibi_data_width_c
225
      )
226
    port map (
227
      clk               => clk,
228
      rst_n             => rst_n,
229
      hibi_comm_in      => hibi_comm_to_duv,
230
      hibi_data_in      => hibi_data_to_duv,
231
      hibi_av_in        => hibi_av_to_duv,
232
      hibi_re_out       => hibi_re_from_duv,
233
      hibi_empty_in     => hibi_empty_to_duv,
234
 
235
      tx_data_out       => tx_data_from_duv,
236
      tx_we_out         => tx_we_from_duv,
237
      tx_full_in        => tx_full_to_duv,
238
      new_tx_out        => new_tx_from_duv,
239
      tx_length_out     => tx_length_from_duv,
240
      new_tx_ack_in     => new_tx_ack_to_duv,
241
      release_lock_out  => release_lock_from_duv,
242
      new_tx_conf_out   => new_tx_conf_from_duv,
243
      new_rx_conf_out   => new_rx_conf_from_duv,
244
 
245
      ip_out            => ip_from_duv,
246
      dest_port_out     => dest_port_from_duv,
247
      source_port_out   => source_port_from_duv,
248
      lock_addr_out     => lock_addr_from_duv,
249
      response_addr_out => response_addr_from_duv,
250
      timeout_in        => '0',         -- ES
251
      timeout_out       => timeout_from_duv,
252
      lock_in           => lock_to_duv,
253
      lock_addr_in      => lock_addr_to_duv
254
      );
255
 
256
 
257
  -----------------------------------------------------------------------------
258
  -- This process sends data to hibi_receiver according to constant table
259
  -- test_txs_c. The table contents model the data coming from HIBI.
260
  -----------------------------------------------------------------------------
261
  hibi : process
262
  begin  -- process
263
 
264
    if rst_n = '0' then
265
      wait until rst_n = '1';
266
    end if;
267
 
268
    wait for 2* period_c;
269
 
270
    -- start transferring
271
    for n in 0 to num_of_txs_c-1 loop
272
 
273
      current_tx <= n;
274
 
275
      -- Write the address
276
      hibi_av_to_duv    <= '1';
277
      hibi_empty_to_duv <= '0';
278
      hibi_data_to_duv  <= test_txs_c(n).addr;
279
      wait for period_c;
280
 
281
      if hibi_re_from_duv = '0' then
282
        wait until hibi_re_from_duv = '1';
283
        wait for period_c;
284
      end if;
285
      hibi_av_to_duv <= '0';
286
 
287
 
288
      -- Write the data
289
      for m in 0 to test_txs_c(n).len-1 loop
290
 
291
        hibi_data_to_duv <= test_txs_c(n).data(m);
292
        wait for period_c;
293
 
294
        if hibi_re_from_duv = '0' then
295
          wait until hibi_re_from_duv = '1';
296
          wait for period_c;
297
        end if;
298
 
299
      end loop;  -- m
300
 
301
      hibi_empty_to_duv <= '1';
302
      -- Wait for some time before the next tx
303
      wait for test_txs_c(n).delay;
304
 
305
    end loop;  -- n
306
 
307
    report "Simulation ended." severity failure;
308
  end process hibi;
309
 
310
 
311
  -----------------------------------------------------------------------------
312
  -- This process represents ctrl regs where the hibi_receiver stores params.
313
  -----------------------------------------------------------------------------
314
  ctrl_regs : process (clk)
315
  begin  -- process ctrl_regs
316
    if clk'event and clk = '1' then
317
 
318
      if new_tx_conf_from_duv = '1' and
319
        (regs_locked = '0' or regs_lock_addr = lock_addr_from_duv)
320
      then
321
        regs_locked    <= '1';
322
        regs_lock_addr <= lock_addr_from_duv;
323
      end if;
324
 
325
      if release_lock_from_duv = '1' then
326
        regs_locked    <= '0';
327
        regs_lock_addr <= (others => '0');
328
      end if;
329
 
330
    end if;
331
  end process ctrl_regs;
332
  lock_to_duv      <= regs_locked;
333
  lock_addr_to_duv <= regs_lock_addr;
334
 
335
  -----------------------------------------------------------------------------
336
  -- This process presents tx_ctrl where DUV feeds data. Just acknoledges
337
  -- each new transfer.
338
  -----------------------------------------------------------------------------
339
  tx_ctrl : process
340
  begin  -- process tx_ctrl
341
 
342
    wait for period_c;
343
 
344
    if new_tx_from_duv = '1' then
345
      wait for period_c;
346
      new_tx_ack_to_duv <= '1';
347
      wait for period_c;
348
      new_tx_ack_to_duv <= '0';
349
      wait for period_c;
350
    end if;
351
 
352
  end process tx_ctrl;
353
 
354
 
355
  -----------------------------------------------------------------------------
356
  -- Monitoring process, contains all the important asserts
357
  -----------------------------------------------------------------------------
358
  monitoring : process (clk)
359
    variable new_tx_conf_received1 : std_logic := '0';
360
    variable new_tx_conf_received2 : std_logic := '0';
361
    variable new_tx_received1      : std_logic := '0';
362
    variable new_tx_received2      : std_logic := '0';
363
    variable release_received      : std_logic := '0';
364
    variable rx_conf_received      : std_logic := '0';
365
  begin  -- process monitoring
366
    if clk'event and clk = '1' then
367
 
368
      if release_lock_from_duv = '1' then
369
        assert regs_locked = '1' report "Trying to release while unlocked!" severity failure;
370
        assert test_txs_c(current_tx).addr = regs_lock_addr
371
          report "Trying to release some other's lock!" severity failure;
372
 
373
      end if;
374
 
375
      if new_tx_from_duv = '1' then
376
        assert regs_locked = '1' and regs_lock_addr = test_txs_c(current_tx).addr
377
          report "Invalid locking while starting tx!" severity failure;
378
      end if;
379
 
380
 
381
      -- multiclk fifo:
382
      if tx_we_from_duv = '1' then
383
 
384
        -- make sure that data is correct
385
        assert tx_data_from_duv = data1_c(fifo_cnt mod 6)
386
          report "Invalid data to multiclk fifo!" severity failure;
387
 
388
        if fifo_cnt = test_txs_c(current_tx).data_16bit_len - 1 then
389
          fifo_cnt <= 0;
390
        else
391
          fifo_cnt <= fifo_cnt + 1;
392
        end if;
393
      end if;
394
 
395
 
396
      -------------------------------------------------------------------------
397
      -- special asserts for each tx:
398
      -- (these depend on the test traffic, not very automagic...)
399
      -------------------------------------------------------------------------
400
      case current_tx is
401
        when 0 =>
402
          -- Correct tx_conf pkt, so we should get the data at some point
403
          -- make sure that it's received
404
          if new_tx_conf_from_duv = '1' then
405
            new_tx_conf_received1 := '1';
406
 
407
            -- make sure data is correct
408
            assert ip_from_duv = test_txs_c(current_tx).data(1)
409
              and dest_port_from_duv = test_txs_c(current_tx).data(2)(31 downto 16)
410
              and source_port_from_duv = test_txs_c(current_tx).data(2)(15 downto 0)
411
              and response_addr_from_duv = test_txs_c(current_tx).data(3)
412
              and lock_addr_from_duv = test_txs_c(current_tx).addr
413
              report "Invalid data from tx conf!" severity failure;
414
          end if;
415
 
416
 
417
        when 1 =>
418
          -- Make sure we got the conf at the last stage
419
          assert new_tx_conf_received1 = '1' report "Tx conf #1 not received!" severity failure;
420
 
421
          -- tx_conf from another sender, make sure that the lock_addr doesn't
422
          -- change (it should be the one from the previous tx)
423
          assert regs_lock_addr = test_txs_c(0).addr report "Lock address changed when it should not!" severity failure;
424
 
425
          -- make sure we get the second tx conf, even though it shouldn't
426
          -- cause any activity
427
          if new_tx_conf_from_duv = '1' then
428
            new_tx_conf_received2 := '1';
429
          end if;
430
 
431
 
432
        when 2 =>
433
          -- Make sure we got the conf at the last stage
434
          assert new_tx_conf_received2 = '1' report "Tx conf #2 not received!" severity failure;
435
 
436
          -- new tx, make sure tx_len is correct
437
          if new_tx_from_duv = '1' then
438
            assert tx_length_from_duv = test_txs_c(current_tx).data(0)(id_lo_idx_c-1 downto id_lo_idx_c-tx_len_w_c)
439
              report "Invalid tx length!" severity failure;
440
            new_tx_received1 := '1';
441
          end if;
442
 
443
 
444
        when 3 =>
445
          -- Make sure we got the tx
446
          assert new_tx_received1 = '1' report "Tx #1 not received!" severity failure;
447
 
448
          -- new tx, make sure tx_len is correct
449
          if new_tx_from_duv = '1' then
450
            assert tx_length_from_duv = test_txs_c(current_tx).data(0)(id_lo_idx_c-1 downto id_lo_idx_c-tx_len_w_c)
451
              report "Invalid tx length!" severity failure;
452
            new_tx_received2 := '1';
453
          end if;
454
 
455
          -- these can be cleared for later use
456
          new_tx_conf_received1 := '0';
457
          new_tx_conf_received2 := '0';
458
 
459
        when 4 =>
460
          -- Make sure we got the tx
461
          assert new_tx_received2 = '1' report "Tx #2 not received!" severity failure;
462
 
463
          -- make sure tx attempt to invalid address doesn't get trough
464
          assert new_tx_from_duv = '0' report "Invalid tx attempt caused a new tx!" severity failure;
465
 
466
 
467
        when 5 =>
468
          -- Invalid release, make sure that release signal stays down
469
          assert release_lock_from_duv = '0' report "Invalid release!" severity failure;
470
 
471
 
472
        when 6 =>
473
          -- Correct release
474
          if release_lock_from_duv = '1' then
475
            release_received := '1';
476
          end if;
477
 
478
 
479
        when 7 =>
480
          -- Check release
481
          assert release_received = '1' report "Lock was not released!" severity failure;
482
 
483
          if new_tx_conf_from_duv = '1' then
484
            new_tx_conf_received1 := '1';
485
          end if;
486
 
487
 
488
        when 8 =>
489
          assert new_tx_conf_received1 = '1' report "Tx conf not received!" severity failure;
490
 
491
          if new_tx_conf_from_duv = '1' then
492
            new_tx_conf_received2 := '1';
493
          end if;
494
 
495
        when 9 =>
496
          assert new_tx_conf_received2 = '1' report "Tx conf not received!!" severity failure;
497
 
498
          if new_rx_conf_from_duv = '1' then
499
            rx_conf_received := '1';
500
 
501
            -- make sure it's correct
502
            assert ip_from_duv = test_txs_c(current_tx).data(1)
503
              and dest_port_from_duv = test_txs_c(current_tx).data(2)(31 downto 16)
504
              and source_port_from_duv = test_txs_c(current_tx).data(2)(15 downto 0)
505
              and response_addr_from_duv = test_txs_c(current_tx).data(3)
506
              and lock_addr_from_duv = test_txs_c(current_tx).addr
507
              report "Invalid data from rx conf!" severity failure;
508
          end if;
509
 
510
 
511
        when 10 =>
512
          assert rx_conf_received = '1' report "No rx conf received!" severity failure;
513
 
514
          -- Make sure no txs are started
515
          assert new_tx_from_duv = '0' report "Invalid new tx!" severity failure;
516
          new_tx_received1 := '0';
517
 
518
        when 11 =>
519
 
520
          if new_tx_from_duv = '1' then
521
            new_tx_received1 := '1';
522
            assert tx_length_from_duv = test_txs_c(current_tx).data(0)(id_lo_idx_c-1 downto id_lo_idx_c-tx_len_w_c)
523
              report "Invalid tx length!" severity failure;
524
          end if;
525
 
526
        when 12 =>
527
          assert new_tx_received1 = '1' report "Tx #3 was not received!" severity failure;
528
 
529
          -- no check for last release...
530
        when others => null;
531
      end case;
532
 
533
    end if;
534
  end process monitoring;
535
 
536
end tb;

powered by: WebSVN 2.1.0

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