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.communication/] [n2h2/] [1.0/] [tb/] [blocks/] [tb_n2h2_tx_str.vhd] - Blame information for rev 145

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
-------------------------------------------------------------------------------
2
-- Title      : Testbench for design "n2h2_tx"
3
-- Project    : 
4
-------------------------------------------------------------------------------
5
-- File       : tb_n2h2_tx.vhd
6
-- Author     : kulmala3
7
-- Created    : 30.03.2005
8
-- Last update: 2011-11-15
9
-- Description: DMA reads data from memory  and writes them to
10
--              HIBI. Values are just running numbers and checked automatically.
11
--
12
-------------------------------------------------------------------------------
13
-- Copyright (c) 2005 
14
-------------------------------------------------------------------------------
15
-- Revisions  :
16
-- Date        Version  Author  Description
17
-- 30.03.2005  1.0      AK      Created
18
-------------------------------------------------------------------------------
19
-------------------------------------------------------------------------------
20
-- Funbase IP library Copyright (C) 2011 TUT Department of Computer Systems
21
--
22
-- This file is part of HIBI
23
--
24
-- This source file may be used and distributed without
25
-- restriction provided that this copyright statement is not
26
-- removed from the file and that any derivative work contains
27
-- the original copyright notice and the associated disclaimer.
28
--
29
-- This source file is free software; you can redistribute it
30
-- and/or modify it under the terms of the GNU Lesser General
31
-- Public License as published by the Free Software Foundation;
32
-- either version 2.1 of the License, or (at your option) any
33
-- later version.
34
--
35
-- This source is distributed in the hope that it will be
36
-- useful, but WITHOUT ANY WARRANTY; without even the implied
37
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
38
-- PURPOSE.  See the GNU Lesser General Public License for more
39
-- details.
40
--
41
-- You should have received a copy of the GNU Lesser General
42
-- Public License along with this source; if not, download it
43
-- from http://www.opencores.org/lgpl.shtml
44
-------------------------------------------------------------------------------
45
 
46
library ieee;
47
use ieee.std_logic_1164.all;
48
use ieee.std_logic_arith.all;
49
use ieee.std_logic_unsigned.all;
50
 
51
-------------------------------------------------------------------------------
52
 
53
entity tb_n2h2_tx is
54
 
55
end tb_n2h2_tx;
56
 
57
-------------------------------------------------------------------------------
58
 
59
architecture rtl of tb_n2h2_tx is
60
 
61
 
62
  -- component generics
63
  constant data_width_g   : integer := 32;
64
  constant amount_width_g : integer := 16;
65
 
66
 
67
  constant wait_between_sends_c   : integer := 2;   -- unit: cycles
68
  constant hibi_full_c            : integer := 2;
69
  constant avalon_waitr_c         : integer := 7;
70
  constant amount_max_c           : integer := 63;  -- longest transfer in words
71
  constant incr_hibi_full_after_c : time    := 1000000 ns;  -- how often HIBI
72
                                                            -- goes full
73
 
74
 
75
  -----------------------------------------------------------------------------
76
  --
77
  -----------------------------------------------------------------------------
78
  -- clock and reset
79
  signal   Clk    : std_logic;
80
  signal   Clk2   : std_logic;          -- turha kello?
81
  signal   Rst_n  : std_logic;
82
  constant Period : time := 10 ns;
83
 
84
  type   main_control_type is (idle, send, wait_one);
85
  signal main_ctrl_r : main_control_type;
86
 
87
  signal amount_r   : std_logic_vector(amount_width_g-1 downto 0);
88
  signal mem_addr_r : std_logic_vector(data_width_g-1 downto 0);
89
 
90
 
91
  -----------------------------------------------------------------------------
92
  -- Tested sub-unit of Nios-to-HIBI
93
  -----------------------------------------------------------------------------
94
  component n2h2_tx
95
    generic (
96
      data_width_g   : integer;
97
      addr_width_g   : integer := 32;
98
      amount_width_g : integer
99
      );
100
    port (
101
      clk   : in std_logic;
102
      rst_n : in std_logic;
103
 
104
      -- Avalon master interface for reading memory
105
      avalon_addr_out         : out std_logic_vector(addr_width_g-1 downto 0);
106
      avalon_readdata_in      : in  std_logic_vector(data_width_g-1 downto 0);
107
      avalon_re_out           : out std_logic;
108
      avalon_waitrequest_in   : in  std_logic;
109
      avalon_readdatavalid_in : in  std_logic;
110
 
111
      -- Hibi interface for writing
112
      hibi_av_out   : out std_logic;
113
      hibi_data_out : out std_logic_vector(data_width_g-1 downto 0);
114
      hibi_comm_out : out std_logic_vector(4 downto 0);
115
      hibi_full_in  : in  std_logic;
116
      hibi_we_out   : out std_logic;
117
 
118
      -- DMA conf interface
119
      tx_start_in        : in  std_logic;
120
      tx_status_done_out : out std_logic;
121
      tx_comm_in         : in  std_logic_vector(4 downto 0);
122
      tx_hibi_addr_in    : in  std_logic_vector(addr_width_g-1 downto 0);
123
      tx_ram_addr_in     : in  std_logic_vector(addr_width_g-1 downto 0);
124
      tx_amount_in       : in  std_logic_vector(amount_width_g-1 downto 0)
125
      );
126
  end component;
127
 
128
 
129
  signal avalon_addr_from_tx   : std_logic_vector(data_width_g-1 downto 0);
130
  signal avalon_re_from_tx     : std_logic;
131
  signal avalon_readdata_to_tx : std_logic_vector(data_width_g-1 downto 0) := (others => '0');
132
 
133
  signal avalon_waitrequest_to_tx   : std_logic;
134
  signal avalon_waitrequest_to_tx2  : std_logic;
135
  signal avalon_readdatavalid_to_tx : std_logic;
136
 
137
  signal hibi_data_from_tx          : std_logic_vector(data_width_g-1 downto 0);
138
  signal hibi_av_from_tx            : std_logic;
139
  signal hibi_full_to_tx            : std_logic := '0';
140
  signal hibi_comm_from_tx          : std_logic_vector(4 downto 0);
141
  signal hibi_we_from_tx            : std_logic;
142
 
143
  -- Configuration signals
144
  signal tx_comm_to_tx      : std_logic_vector(4 downto 0)                := (others => '0');
145
  signal tx_hibi_addr_to_tx : std_logic_vector(data_width_g-1 downto 0)   := (others => '0');
146
  signal tx_ram_addr_to_tx  : std_logic_vector(data_width_g-1 downto 0)   := (others => '0');
147
  signal tx_amount_to_tx    : std_logic_vector(amount_width_g-1 downto 0) := (others => '0');
148
  signal tx_start_to_tx             : std_logic := '0';
149
  signal tx_status_done_from_tx     : std_logic;
150
 
151
 
152
  -----------------------------------------------------------------------------
153
  -- Memory and Avalon
154
  -----------------------------------------------------------------------------  
155
  constant rom_data_file_name_g : string  := "ram_init.dat";
156
  constant output_file_name_g   : string  := "ram_contents.dat";
157
  constant write_trigger_g      : natural := 16#6543#;  -- RAM gets dumped to file
158
  constant ram_addr_width_g     : integer := 16;
159
 
160
  component sram_scalable
161
    generic (
162
      rom_data_file_name_g : string;
163
      output_file_name_g   : string;
164
      write_trigger_g      : natural;
165
      addr_width_g         : integer;
166
      data_width_g         : integer
167
      );
168
    port (
169
      cs1_n_in   : in    std_logic;
170
      cs2_in     : in    std_logic;
171
      addr_in    : in    std_logic_vector(addr_width_g-1 downto 0);
172
      data_inout : inout std_logic_vector(data_width_g-1 downto 0);
173
      we_n_in    : in    std_logic;
174
      oe_n_in    : in    std_logic
175
      );
176
  end component;
177
 
178
  signal cs1_n_to_ram   : std_logic;
179
  signal cs2_to_ram     : std_logic;
180
  signal addr_to_ram    : std_logic_vector(ram_addr_width_g-1 downto 0);
181
  signal data_inout_ram : std_logic_vector(data_width_g-1 downto 0);
182
  signal we_n_to_ram    : std_logic;
183
  signal oe_n_to_ram    : std_logic;
184
 
185
  signal delayed_data_from_ram_r : std_logic_vector(data_width_g-1 downto 0);
186
  signal avalon_ready_r : std_logic;
187
 
188
 
189
 
190
  -----------------------------------------------------------------------------
191
  -- Signal for modeling HIBI
192
  -----------------------------------------------------------------------------
193
  signal hibi_addr_r        : std_logic_vector(data_width_g-1 downto 0);
194
  signal hibi_amount_r      : std_logic_vector(amount_width_g-1 downto 0);
195
  signal hibi_data_r        : std_logic_vector(data_width_g-1 downto 0);
196
  signal avalon_addr_r      : std_logic_vector(data_width_g-1 downto 0);
197
  signal avalon_data_r      : std_logic_vector(data_width_g-1 downto 0);
198
  signal avalon_amount_r    : std_logic_vector(amount_width_g-1 downto 0);
199
  signal wait_cnt_r         : integer range 0 to wait_between_sends_c;
200
  signal avalon_waitr_cnt_r : integer range 0 to avalon_waitr_c-1;
201
  signal hibi_we_was_up_r   : std_logic;
202
  --  signal hibi_full_cnt_r : integer range 0 to hibi_full_c;
203
  signal hibi_full_cnt_r    : integer;
204
  signal hibi_ready_r       : std_logic;
205
 
206
  signal hibi_full_up_cc : integer := 0;
207
 
208
 
209
 
210
begin  -- rtl
211
 
212
 
213
  -----------------------------------------------------------------------------
214
  -- DUT component instantiation 
215
  --
216
  ------------------------------------------------------------------------------  
217
  DUT : n2h2_tx
218
    --DUT: entity work.n2h2_tx
219
    generic map (
220
      data_width_g   => data_width_g,
221
      amount_width_g => amount_width_g)
222
    port map (
223
      clk   => clk,
224
      rst_n => rst_n,
225
 
226
      avalon_addr_out         => avalon_addr_from_tx,
227
      avalon_re_out           => avalon_re_from_tx,
228
      avalon_readdata_in      => avalon_readdata_to_tx,
229
      avalon_waitrequest_in   => avalon_waitrequest_to_tx2,
230
      avalon_readdatavalid_in => avalon_readdatavalid_to_tx,
231
 
232
      hibi_data_out => hibi_data_from_tx,
233
      hibi_av_out   => hibi_av_from_tx,
234
      hibi_full_in  => hibi_full_to_tx,
235
      hibi_comm_out => hibi_comm_from_tx,
236
      hibi_we_out   => hibi_we_from_tx,
237
 
238
      tx_start_in        => tx_start_to_tx,
239
      tx_status_done_out => tx_status_done_from_tx,
240
      tx_comm_in         => tx_comm_to_tx,
241
      tx_hibi_addr_in    => tx_hibi_addr_to_tx,
242
      tx_ram_addr_in     => tx_ram_addr_to_tx,
243
      tx_amount_in       => tx_amount_to_tx);
244
 
245
 
246
 
247
  -----------------------------------------------------------------------------
248
  -- Give commands to the tested block n2h2_tx
249
  -- Asks to send longer and longer transfer
250
  ------------------------------------------------------------------------------  
251
  test : process (clk, rst_n)
252
  begin  -- process test
253
    if rst_n = '0' then                 -- asynchronous reset (active low)
254
      tx_start_to_tx     <= '0';
255
      tx_hibi_addr_to_tx <= X"0000ffff";
256
      tx_comm_to_tx      <= (others => 'Z');                           --'0');
257
      tx_ram_addr_to_tx  <= (others => 'Z');                           -- '0');
258
      tx_amount_to_tx    <= (others => 'Z');                           -- '0');
259
      wait_cnt_r         <= 0;
260
      main_ctrl_r        <= idle;
261
      amount_r           <= conv_std_logic_vector(1, amount_width_g);  --(others => '0');
262
      mem_addr_r         <= (others => '0');
263
 
264
 
265
    elsif clk'event and clk = '1' then  -- rising clock edge
266
 
267
 
268
      case main_ctrl_r is
269
 
270
        when idle =>
271
          -- Wait that previous tx is ready and then few cycles more. 
272
          -- Increase the source memory address for every transfer
273
 
274
          tx_start_to_tx <= '0';
275
 
276
          if tx_status_done_from_tx = '1' then
277
            wait_cnt_r <= wait_cnt_r+1;
278
 
279
            if wait_cnt_r = wait_between_sends_c-1 then
280
              wait_cnt_r  <= 0;
281
              main_ctrl_r <= send;
282
              if conv_integer(amount_r) > 1 then
283
                mem_addr_r <= mem_addr_r+conv_integer(tx_amount_to_tx)*4;
284
              else
285
                mem_addr_r <= mem_addr_r+conv_integer(tx_amount_to_tx)*4;
286
              end if;
287
            end if;
288
 
289
          end if;
290
 
291
 
292
        when send =>
293
          -- Ask to send a new transfer
294
          -- Increase the mem addr, hibi addr
295
          tx_start_to_tx     <= '1';
296
          tx_ram_addr_to_tx  <= mem_addr_r;
297
          tx_hibi_addr_to_tx <= tx_hibi_addr_to_tx+1;
298
          tx_amount_to_tx    <= amount_r;
299
          tx_comm_to_tx      <= "00010";
300
 
301
          -- Increase transfer length for the next time
302
          if conv_integer(amount_r) >= amount_max_c then
303
            amount_r <= conv_std_logic_vector(1, amount_width_g);
304
          else
305
            amount_r <= amount_r+1;
306
          end if;
307
 
308
          -- Loop back to idle state
309
          main_ctrl_r <= idle;
310
 
311
 
312
        when others =>
313
      end case;
314
    end if;
315
  end process test;
316
 
317
  -- avalon_readdata_to_tx <= avalon_data_r;
318
 
319
 
320
  -----------------------------------------------------------------------------
321
  -- Instantiate memory block
322
  ------------------------------------------------------------------------------  
323
  sram_scalable_1 : sram_scalable
324
    generic map (
325
      rom_data_file_name_g => rom_data_file_name_g,
326
      output_file_name_g   => output_file_name_g,
327
      write_trigger_g      => write_trigger_g,
328
      addr_width_g         => ram_addr_width_g,
329
      data_width_g         => data_width_g)
330
    port map (
331
      cs1_n_in   => cs1_n_to_ram,
332
      cs2_in     => cs2_to_ram,
333
      addr_in    => addr_to_ram,
334
      data_inout => data_inout_ram,
335
      we_n_in    => we_n_to_ram,
336
      oe_n_in    => oe_n_to_ram
337
      );
338
 
339
 
340
 
341
  -----------------------------------------------------------------------------
342
  -- Imitate Avalon switch fabric between mem and n2h2_tx:
343
  --  - delay the addr going to memory by one cycle
344
  --  - delay the data coming from memory by one cycle
345
  ------------------------------------------------------------------------------  
346
  cs1_n_to_ram <= '0';                  -- avalon_waitrequest_to_tx;
347
  cs2_to_ram   <= avalon_re_from_tx;
348
  addr_to_ram  <= conv_std_logic_vector(conv_integer(avalon_addr_from_tx)/4, ram_addr_width_g);
349
 
350
  avalon_waitrequest_to_tx2 <= avalon_waitrequest_to_tx or (not avalon_re_from_tx);
351
  avalon_readdata_to_tx     <= delayed_data_from_ram_r;
352
 
353
 
354
  delay_valid : process (clk, rst_n)
355
  begin  -- process delay_valid
356
    if rst_n = '0' then                 -- asynchronous reset (active low)
357
 
358
    elsif clk'event and clk = '1' then  -- rising clock edge
359
      -- memory latency 2 (note below the same signal assignment)
360
      avalon_readdatavalid_to_tx <= not avalon_waitrequest_to_tx2;
361
 
362
    end if;
363
  end process delay_valid;
364
  -- memory latency 1
365
  -- avalon_readdatavalid_to_tx <= not avalon_waitrequest_to_tx2;
366
 
367
  we_n_to_ram <= '1';
368
  oe_n_to_ram <= '0';
369
 
370
  avalon : process (clk2, rst_n)
371
  begin  -- process avalon
372
    if rst_n = '0' then                 -- asynchronous reset (active low)
373
      avalon_waitrequest_to_tx <= '1';
374
      delayed_data_from_ram_r  <= (others => 'Z');  --data_inout_ram;
375
      avalon_waitr_cnt_r       <= 0;
376
 
377
 
378
    elsif clk'event and clk = '1' then  -- rising clock edge
379
 
380
 
381
      if tx_start_to_tx = '1' then
382
        avalon_addr_r <= mem_addr_r;
383
      end if;
384
 
385
      delayed_data_from_ram_r <= data_inout_ram;
386
 
387
      if avalon_re_from_tx = '1' then
388
        if avalon_waitr_cnt_r = avalon_waitr_c-1 then
389
          avalon_waitr_cnt_r       <= 0;
390
          avalon_waitrequest_to_tx <= '1';
391
        else
392
          avalon_waitr_cnt_r       <= avalon_waitr_cnt_r+1;
393
          avalon_waitrequest_to_tx <= '0';
394
        end if;
395
 
396
      else
397
        avalon_waitrequest_to_tx <= '1';
398
      end if;
399
    end if;
400
                                        --avalon_waitrequest_to_tx <= '0';
401
  end process avalon;
402
 
403
 
404
  -----------------------------------------------------------------------------
405
  -- Imitate the HIBI wrapper that gets the data from n2h2_tx
406
  ------------------------------------------------------------------------------    
407
  hibi : process (clk, rst_n)
408
  begin  -- process hibi
409
    if rst_n = '0' then                 -- asynchronous reset (active low)
410
      hibi_addr_r      <= X"0000ffff";
411
      hibi_full_to_tx  <= '1';
412
      hibi_data_r      <= (others => '0');
413
      hibi_amount_r    <= (others => '0');
414
      hibi_full_cnt_r  <= 0;
415
      hibi_we_was_up_r <= '1';
416
 
417
    elsif clk'event and clk = '1' then  -- rising clock edge
418
 
419
                                        -- Generate full signal
420
      if hibi_we_was_up_r = '1' then
421
        hibi_full_cnt_r <= hibi_full_cnt_r+1;
422
        hibi_full_to_tx <= '1';
423
        if hibi_full_cnt_r = hibi_full_up_cc then
424
          hibi_full_to_tx  <= '0';
425
          hibi_full_cnt_r  <= 0;
426
          hibi_we_was_up_r <= '0';
427
        end if;
428
      end if;
429
 
430
      -- Take and check the incoming data
431
      if hibi_we_from_tx = '1' then
432
        if hibi_full_up_cc > 0 then
433
          hibi_full_to_tx <= '1';
434
        end if;
435
        hibi_we_was_up_r <= '1';
436
 
437
        assert hibi_comm_from_tx /= "00000" report "Error. DMA sets comm=idle" severity error;
438
 
439
 
440
 
441
        if hibi_av_from_tx = '1' then
442
          -- Check incoming address
443
          -- +1 because of the main test program value
444
          assert hibi_addr_r+1 = hibi_data_from_tx report "hibi addr error" severity error;
445
          hibi_addr_r <= hibi_addr_r+1;
446
 
447
        else
448
          -- Check incoming data
449
          assert avalon_readdata_to_tx = hibi_data_from_tx report "hibi data error" severity error;
450
 
451
          if hibi_data_r = 2**ram_addr_width_g-1 then
452
            hibi_data_r <= (others => '0');
453
          else
454
            hibi_data_r <= hibi_data_r+1;
455
          end if;
456
 
457
          hibi_amount_r        <= hibi_amount_r+1;
458
          assert hibi_amount_r <= tx_amount_to_tx report "too many data" severity error;
459
        end if;
460
 
461
      else
462
        -- DMA does not write to HIBI        
463
        if main_ctrl_r = send then
464
          hibi_amount_r <= (others => '0');
465
        end if;
466
      end if;
467
 
468
    end if;
469
  end process hibi;
470
 
471
 
472
  -----------------------------------------------------------------------------
473
  -- 
474
  ------------------------------------------------------------------------------  
475
  full_control : process
476
  begin  -- process full_control
477
    wait for incr_hibi_full_after_c;
478
    hibi_full_up_cc <= hibi_full_up_cc+1;
479
  end process full_control;
480
 
481
 
482
 
483
  -----------------------------------------------------------------------------
484
  -- Generate clokcs and reset
485
  ------------------------------------------------------------------------------  
486
  CLOCK1 : process                      -- generate clock signal for design
487
    variable clktmp : std_logic := '0';
488
  begin
489
    wait for PERIOD/2;
490
    clktmp := not clktmp;
491
    Clk    <= clktmp;
492
  end process CLOCK1;
493
 
494
  CLOCK2 : process                      -- generate clock signal for design
495
    variable clktmp : std_logic := '0';
496
  begin
497
    clktmp := not clktmp;
498
    Clk2   <= clktmp;
499
    wait for PERIOD/2;
500
  end process CLOCK2;
501
 
502
  RESET : process
503
  begin
504
    Rst_n <= '0';                       -- Reset the testsystem
505
    wait for 6*PERIOD;                  -- Wait 
506
    Rst_n <= '1';                       -- de-assert reset
507
    wait;
508
  end process RESET;
509
 
510
 
511
 
512
 
513
end rtl;

powered by: WebSVN 2.1.0

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