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_rx_ctrl.vhd] - Blame information for rev 145

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
-------------------------------------------------------------------------------
2
-- Title      : Testbench for Rx ctrl block
3
-- Project    : 
4
-------------------------------------------------------------------------------
5
-- File       : tb_rx_ctrl.vhd
6
-- Author     : Jussi Nieminen
7
-- Last update: 2012-03-21
8
-- Platform   : Sim only
9
-------------------------------------------------------------------------------
10
-- Description: A couple of hard-coded test cases for ctrl-registers.
11
-------------------------------------------------------------------------------
12
-- Revisions  :
13
-- Date        Version  Author  Description
14
-- 2009/12/18  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_rx_ctrl is
24
end tb_rx_ctrl;
25
 
26
 
27
architecture tb of tb_rx_ctrl is
28
 
29
  constant frequency_c     : integer   := 50000000;
30
  constant period_c        : time      := 20 ns;
31
  constant udp_ip_period_c : time      := 40 ns;
32
  signal   clk             : std_logic := '1';
33
  signal   clk_udp         : std_logic := '1';
34
  signal   rst_n           : std_logic := '0';
35
 
36
  constant rx_multiclk_fifo_depth_c : integer := 10;
37
  constant tx_fifo_depth_c          : integer := 10;
38
  constant hibi_data_width_c        : integer := 32;
39
 
40
  -- from UDP/IP
41
  signal rx_data_to_duv        : std_logic_vector(udp_block_data_w_c-1 downto 0) := (others => '0');
42
  signal rx_data_valid_to_duv  : std_logic                                       := '0';
43
  signal rx_re_from_duv        : std_logic;
44
  signal new_rx_to_duv         : std_logic                                       := '0';
45
  signal rx_len_to_duv         : std_logic_vector(tx_len_w_c-1 downto 0)         := (others => '0');
46
  signal source_ip_to_duv      : std_logic_vector(ip_addr_w_c-1 downto 0)        := (others => '0');
47
  signal dest_port_to_duv      : std_logic_vector(udp_port_w_c-1 downto 0)       := (others => '0');
48
  signal source_port_to_duv    : std_logic_vector(udp_port_w_c-1 downto 0)       := (others => '0');
49
  signal rx_erroneous_to_duv   : std_logic                                       := '0';
50
 
51
  -- to/from ctrl regs
52
  signal ip_from_duv           : std_logic_vector(ip_addr_w_c-1 downto 0);
53
  signal dest_port_from_duv    : std_logic_vector(udp_port_w_c-1 downto 0);
54
  signal source_port_from_duv  : std_logic_vector(udp_port_w_c-1 downto 0);
55
  signal rx_addr_valid_to_duv  : std_logic                                       := '0';
56
 
57
  -- to/from hibi_transmitter
58
  signal send_request_from_duv : std_logic;
59
  signal ready_for_tx_to_duv   : std_logic                                       := '0';
60
  signal rx_empty_from_duv     : std_logic;
61
  signal rx_data_from_duv      : std_logic_vector(hibi_data_width_c-1 downto 0);
62
  signal rx_re_to_duv          : std_logic                                       := '0';
63
 
64
 
65
  -- Testbench's state machines etc.
66
  type   send_state_type is (idle, sending);
67
  signal send_state      : send_state_type;
68
  signal send_data       : std_logic := '0';
69
  signal send_done       : std_logic;
70
  signal rx_data_valid_r : std_logic;
71
  signal current         : integer;
72
 
73
 
74
  -- Test constants
75
  constant test_data_amount_c : integer        := 16;  -- #words
76
  type     test_data_type is array (0 to test_data_amount_c-1) of std_logic_vector(udp_block_data_w_c-1 downto 0);
77
  constant test_data          : test_data_type :=
78
    (x"0100", x"0302", x"0504", x"0706", x"0908", x"0b0a", x"0d0c", x"0f0e",
79
      x"1110", x"1312", x"1514", x"1716", x"1918", x"1b1a", x"1d1c", x"1f1e");
80
 
81
  type test_txs_type is
82
  record
83
    source_ip         : std_logic_vector(ip_addr_w_c-1 downto 0);
84
    source_port       : std_logic_vector(udp_port_w_c-1 downto 0);
85
    dest_port         : std_logic_vector(udp_port_w_c-1 downto 0);
86
    rx_addr_valid     : std_logic;
87
    rx_len            : integer;         -- #bytes
88
    rx_erroneous      : std_logic;
89
    delay_before_next : time;
90
  end record;
91
 
92
  constant num_of_tests_c : integer := 5;
93
  type     test_txs_array is array (0 to num_of_tests_c-1) of test_txs_type;
94
 
95
  -- test cases:
96
  -- 0. Normal (not erroneus, rx address valid) 200 bytes long packet
97
  -- 1. Packet without an receiver (should be dumped)
98
  -- 2. Erroneous packet (should also be dumped)
99
  -- 3. Very short (1 byte) transfer with minimal delay
100
  -- 4. just something following the earlier short one
101
  constant test_txs : test_txs_array :=
102
    ((source_ip          => x"01234567",
103
       source_port       => x"1212",
104
       dest_port         => x"2121",
105
       rx_addr_valid     => '1',
106
       rx_len            => 200,
107
       rx_erroneous      => '0',
108
       delay_before_next => 10 * period_c),
109
     (source_ip          => x"12345678",
110
       source_port       => x"2323",
111
       dest_port         => x"3232",
112
       rx_addr_valid     => '0',
113
       rx_len            => 40,
114
       rx_erroneous      => '0',
115
       delay_before_next => 10 * period_c),
116
     (source_ip          => x"23456789",
117
       source_port       => x"3434",
118
       dest_port         => x"4343",
119
       rx_addr_valid     => '1',
120
       rx_len            => 30,
121
       rx_erroneous      => '1',
122
       delay_before_next => 10 * period_c),
123
     (source_ip          => x"3456789a",
124
       source_port       => x"4545",
125
       dest_port         => x"5454",
126
       rx_addr_valid     => '1',
127
       rx_len            => 1,
128
       rx_erroneous      => '0',
129
       delay_before_next => udp_ip_period_c),
130
     (source_ip          => x"456789ab",
131
       source_port       => x"5656",
132
       dest_port         => x"6565",
133
       rx_addr_valid     => '1',
134
       rx_len            => 20,
135
       rx_erroneous      => '0',
136
       delay_before_next => 10 * period_c)
137
     );
138
 
139
  signal test_id   : integer;
140
 
141
 
142
begin  -- tb
143
 
144
 
145
  duv : entity work.rx_ctrl
146
    generic map (
147
      rx_multiclk_fifo_depth_g => rx_multiclk_fifo_depth_c,
148
      tx_fifo_depth_g          => tx_fifo_depth_c,
149
      hibi_data_width_g        => hibi_data_width_c,
150
      frequency_g              => frequency_c
151
      )
152
    port map (
153
      clk              => clk,
154
      clk_udp          => clk_udp,
155
      rst_n            => rst_n,
156
      rx_data_in       => rx_data_to_duv,
157
      rx_data_valid_in => rx_data_valid_to_duv,
158
      rx_re_out        => rx_re_from_duv,
159
      new_rx_in        => new_rx_to_duv,
160
      rx_len_in        => rx_len_to_duv,
161
      source_ip_in     => source_ip_to_duv,
162
      dest_port_in     => dest_port_to_duv,
163
      source_port_in   => source_port_to_duv,
164
      rx_erroneous_in  => rx_erroneous_to_duv,
165
      ip_out           => ip_from_duv,
166
      dest_port_out    => dest_port_from_duv,
167
      source_port_out  => source_port_from_duv,
168
      rx_addr_valid_in => rx_addr_valid_to_duv,
169
      send_request_out => send_request_from_duv,
170
      ready_for_tx_in  => ready_for_tx_to_duv,
171
      rx_empty_out     => rx_empty_from_duv,
172
      rx_data_out      => rx_data_from_duv,
173
      rx_re_in         => rx_re_to_duv
174
      );
175
 
176
 
177
  -- clk generation:
178
  clk     <= not clk     after period_c/2;
179
  clk_udp <= not clk_udp after udp_ip_period_c/2;
180
  rst_n   <= '1'         after 4*period_c;
181
 
182
  test_id <= current;                   -- ES
183
 
184
 
185
  -----------------------------------------------------------------------------
186
  -- Three processes
187
  --  - main gives commands to others, (behav) process with wait statements
188
  --  - sender provides stimulues when requested, seq. process
189
  --  - reader checks response, seq. process
190
  -----------------------------------------------------------------------------
191
 
192
  main_ctrl : process
193
  begin  -- process main_ctrl
194
 
195
    if rst_n = '0' then
196
      wait until rst_n = '1';
197
    end if;
198
 
199
    wait for period_c*4;
200
 
201
    -- Start the test transfers
202
    for n in 0 to num_of_tests_c-1 loop
203
 
204
      current <= n;
205
 
206
      -- Give parameters to duv
207
      new_rx_to_duv       <= '1';
208
      source_ip_to_duv    <= test_txs(n).source_ip;
209
      source_port_to_duv  <= test_txs(n).source_port;
210
      dest_port_to_duv    <= test_txs(n).dest_port;
211
      rx_len_to_duv       <= std_logic_vector(to_unsigned(test_txs(n).rx_len, tx_len_w_c));
212
      rx_erroneous_to_duv <= test_txs(n).rx_erroneous;
213
 
214
      -- Request other process to provide the data
215
      send_data <= '1';
216
      wait for udp_ip_period_c;
217
      send_data <= '0';
218
 
219
      rx_addr_valid_to_duv <= test_txs(n).rx_addr_valid;
220
 
221
      -- Obsolete check, perhaps?
222
      if ready_for_tx_to_duv = '0' then
223
        -- Let this be down for a while. Assertion inside the  reader process
224
        -- will check that no
225
        -- send requests are made before this is up
226
        wait for period_c*30;
227
        ready_for_tx_to_duv <= '1';
228
      end if;
229
 
230
      -- Wait until duv starts reading and then clear the params
231
      if rx_re_from_duv = '0' then
232
        wait until rx_re_from_duv = '1';
233
      end if;
234
      wait for period_c;
235
 
236
      new_rx_to_duv       <= '0';
237
      source_ip_to_duv    <= (others => 'Z');
238
      source_port_to_duv  <= (others => 'Z');
239
      dest_port_to_duv    <= (others => 'Z');
240
      rx_erroneous_to_duv <= 'Z';
241
 
242
 
243
      -- Wait until other process completes
244
      if send_done = '0' then
245
        wait until send_done = '1';
246
      end if;
247
 
248
      wait for test_txs(n).delay_before_next;
249
 
250
    end loop;  -- n
251
 
252
 
253
    wait for period_c*30;
254
 
255
    report "Simulation ended." severity failure;
256
 
257
  end process main_ctrl;
258
 
259
 
260
  -----------------------------------------------------------------------------
261
  --
262
  -----------------------------------------------------------------------------
263
  sender : process (clk_udp, rst_n)
264
    variable send_cnt : integer := 0;
265
  begin  -- process sender
266
    if rst_n = '0' then                 -- asynchronous reset (active low)
267
 
268
      rx_data_to_duv  <= (others => '0');
269
      rx_data_valid_r <= '0';
270
      send_state      <= idle;
271
      send_done       <= '0';
272
 
273
    elsif clk_udp'event and clk_udp = '1' then  -- rising clock edge
274
 
275
      case send_state is
276
        when idle =>
277
          -- Wait for other process' request
278
 
279
          if send_data = '1' then
280
            send_state      <= sending;
281
            send_done       <= '0';
282
            rx_data_valid_r <= '1';
283
            rx_data_to_duv  <= test_data(0);
284
          end if;
285
 
286
        when sending =>
287
          -- Provide the data to duv
288
 
289
          if rx_re_from_duv = '1' and rx_data_valid_r = '1' then
290
            rx_data_valid_r <= '0';
291
 
292
            if test_txs(current).rx_len - send_cnt*2 <= 2 then
293
              send_done  <= '1';
294
              send_cnt   := 0;
295
              send_state <= idle;
296
 
297
            else
298
              rx_data_to_duv <= test_data((send_cnt+1) mod test_data_amount_c);
299
              send_cnt       := send_cnt + 1;
300
 
301
            end if;
302
 
303
          else
304
            rx_data_valid_r <= '1';
305
          end if;
306
 
307
        when others => null;
308
      end case;
309
 
310
    end if;
311
  end process sender;
312
 
313
  -- this is done to make the valid signal go up at the same time with new_rx
314
  rx_data_valid_to_duv <= rx_data_valid_r or send_data;
315
 
316
 
317
 
318
  -----------------------------------------------------------------------------
319
  -- 
320
  -----------------------------------------------------------------------------
321
  reader : process (clk, rst_n)
322
    variable read_cnt : integer := 0;
323
  begin  -- process reader
324
    if rst_n = '0' then                 -- asynchronous reset (active low)
325
 
326
    elsif clk'event and clk = '1' then  -- rising clock edge
327
 
328
      -- Check the handshake
329
      if send_request_from_duv = '1' then
330
        assert ready_for_tx_to_duv = '1'
331
          report "Failure in test: Send request when not ready." severity failure;
332
        -- reset read_cnt
333
        read_cnt := 0;
334
      end if;
335
 
336
      -- Read the data
337
      if rx_empty_from_duv = '0' then
338
        rx_re_to_duv <= '1';
339
      else
340
        rx_re_to_duv <= '0';
341
      end if;
342
 
343
      -- Check the data
344
      if rx_re_to_duv = '1' and rx_empty_from_duv = '0' then
345
        -- We are reading, check that data is correct
346
 
347
        assert test_txs(current).rx_addr_valid = '1' and
348
          test_txs(current).rx_erroneous = '0'
349
          report "Failure in test: Rx not dumped." severity failure;
350
 
351
        assert rx_data_from_duv =
352
          test_data((2*read_cnt+1) mod test_data_amount_c) & test_data((2*read_cnt) mod test_data_amount_c)
353
          report "Warning: Either invalid data or last word from odd length rx. Check manually!" severity warning;
354
 
355
        read_cnt := read_cnt + 1;
356
      end if;
357
 
358
    end if;
359
  end process reader;
360
 
361
end tb;

powered by: WebSVN 2.1.0

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