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/] [hibi_pe_dma/] [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: 2012-01-12
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
  signal avalon_addr_from_tx   : std_logic_vector(data_width_g-1 downto 0);
93
  signal avalon_re_from_tx     : std_logic;
94
  signal avalon_readdata_to_tx : std_logic_vector(data_width_g-1 downto 0) := (others => '0');
95
 
96
  signal avalon_waitrequest_to_tx   : std_logic;
97
  signal avalon_waitrequest_to_tx2  : std_logic;
98
  signal avalon_readdatavalid_to_tx : std_logic;
99
 
100
  signal hibi_data_from_tx          : std_logic_vector(data_width_g-1 downto 0);
101
  signal hibi_av_from_tx            : std_logic;
102
  signal hibi_full_to_tx            : std_logic := '0';
103
  signal hibi_comm_from_tx          : std_logic_vector(4 downto 0);
104
  signal hibi_we_from_tx            : std_logic;
105
 
106
  -- Configuration signals
107
  signal tx_comm_to_tx      : std_logic_vector(4 downto 0)                := (others => '0');
108
  signal tx_hibi_addr_to_tx : std_logic_vector(data_width_g-1 downto 0)   := (others => '0');
109
  signal tx_ram_addr_to_tx  : std_logic_vector(data_width_g-1 downto 0)   := (others => '0');
110
  signal tx_amount_to_tx    : std_logic_vector(amount_width_g-1 downto 0) := (others => '0');
111
  signal tx_start_to_tx             : std_logic := '0';
112
  signal tx_status_done_from_tx     : std_logic;
113
 
114
 
115
  -----------------------------------------------------------------------------
116
  -- Memory and Avalon
117
  -----------------------------------------------------------------------------  
118
  constant rom_data_file_name_g : string  := "ram_init.dat";
119
  constant output_file_name_g   : string  := "ram_contents.dat";
120
  constant write_trigger_g      : natural := 16#6543#;  -- RAM gets dumped to file
121
  constant ram_addr_width_g     : integer := 16;
122
 
123
  signal cs1_n_to_ram   : std_logic;
124
  signal cs2_to_ram     : std_logic;
125
  signal addr_to_ram    : std_logic_vector(ram_addr_width_g-1 downto 0);
126
  signal data_inout_ram : std_logic_vector(data_width_g-1 downto 0);
127
  signal we_n_to_ram    : std_logic;
128
  signal oe_n_to_ram    : std_logic;
129
 
130
  signal delayed_data_from_ram_r : std_logic_vector(data_width_g-1 downto 0);
131
  signal avalon_ready_r : std_logic;
132
 
133
 
134
 
135
  -----------------------------------------------------------------------------
136
  -- Signal for modeling HIBI
137
  -----------------------------------------------------------------------------
138
  signal hibi_addr_r        : std_logic_vector(data_width_g-1 downto 0);
139
  signal hibi_amount_r      : std_logic_vector(amount_width_g-1 downto 0);
140
  signal hibi_data_r        : std_logic_vector(data_width_g-1 downto 0);
141
  signal avalon_addr_r      : std_logic_vector(data_width_g-1 downto 0);
142
  signal avalon_data_r      : std_logic_vector(data_width_g-1 downto 0);
143
  signal avalon_amount_r    : std_logic_vector(amount_width_g-1 downto 0);
144
  signal wait_cnt_r         : integer range 0 to wait_between_sends_c;
145
  signal avalon_waitr_cnt_r : integer range 0 to avalon_waitr_c-1;
146
  signal hibi_we_was_up_r   : std_logic;
147
  --  signal hibi_full_cnt_r : integer range 0 to hibi_full_c;
148
  signal hibi_full_cnt_r    : integer;
149
  signal hibi_ready_r       : std_logic;
150
 
151
  signal hibi_full_up_cc : integer := 0;
152
 
153
 
154
 
155
begin  -- rtl
156
 
157
 
158
  -----------------------------------------------------------------------------
159
  -- DUT component instantiation 
160
  --
161
  -----------------------------------------------------------------------------
162
  DUT : entity work.hpd_tx_control
163
    generic map (
164
      data_width_g   => data_width_g,
165
      amount_width_g => amount_width_g)
166
    port map (
167
      clk   => clk,
168
      rst_n => rst_n,
169
 
170
      avalon_addr_out         => avalon_addr_from_tx,
171
      avalon_re_out           => avalon_re_from_tx,
172
      avalon_readdata_in      => avalon_readdata_to_tx,
173
      avalon_waitrequest_in   => avalon_waitrequest_to_tx2,
174
      avalon_readdatavalid_in => avalon_readdatavalid_to_tx,
175
 
176
      hibi_data_out => hibi_data_from_tx,
177
      hibi_av_out   => hibi_av_from_tx,
178
      hibi_full_in  => hibi_full_to_tx,
179
      hibi_comm_out => hibi_comm_from_tx,
180
      hibi_we_out   => hibi_we_from_tx,
181
 
182
      tx_start_in        => tx_start_to_tx,
183
      tx_status_done_out => tx_status_done_from_tx,
184
      tx_comm_in         => tx_comm_to_tx,
185
      tx_hibi_addr_in    => tx_hibi_addr_to_tx,
186
      tx_ram_addr_in     => tx_ram_addr_to_tx,
187
      tx_amount_in       => tx_amount_to_tx);
188
 
189
 
190
 
191
  -----------------------------------------------------------------------------
192
  -- Give commands to the tested block n2h2_tx
193
  -- Asks to send longer and longer transfer
194
  ------------------------------------------------------------------------------  
195
  test : process (clk, rst_n)
196
  begin  -- process test
197
    if rst_n = '0' then                 -- asynchronous reset (active low)
198
      tx_start_to_tx     <= '0';
199
      tx_hibi_addr_to_tx <= X"0000ffff";
200
      tx_comm_to_tx      <= (others => 'Z');                           --'0');
201
      tx_ram_addr_to_tx  <= (others => 'Z');                           -- '0');
202
      tx_amount_to_tx    <= (others => 'Z');                           -- '0');
203
      wait_cnt_r         <= 0;
204
      main_ctrl_r        <= idle;
205
      amount_r           <= conv_std_logic_vector(1, amount_width_g);  --(others => '0');
206
      mem_addr_r         <= (others => '0');
207
 
208
 
209
    elsif clk'event and clk = '1' then  -- rising clock edge
210
 
211
 
212
      case main_ctrl_r is
213
 
214
        when idle =>
215
          -- Wait that previous tx is ready and then few cycles more. 
216
          -- Increase the source memory address for every transfer
217
 
218
          tx_start_to_tx <= '0';
219
 
220
          if tx_status_done_from_tx = '1' then
221
            wait_cnt_r <= wait_cnt_r+1;
222
 
223
            if wait_cnt_r = wait_between_sends_c-1 then
224
              wait_cnt_r  <= 0;
225
              main_ctrl_r <= send;
226
              if conv_integer(amount_r) > 1 then
227
                mem_addr_r <= mem_addr_r+conv_integer(tx_amount_to_tx)*4;
228
              else
229
                mem_addr_r <= mem_addr_r+conv_integer(tx_amount_to_tx)*4;
230
              end if;
231
            end if;
232
 
233
          end if;
234
 
235
 
236
        when send =>
237
          -- Ask to send a new transfer
238
          -- Increase the mem addr, hibi addr
239
          tx_start_to_tx     <= '1';
240
          tx_ram_addr_to_tx  <= mem_addr_r;
241
          tx_hibi_addr_to_tx <= tx_hibi_addr_to_tx+1;
242
          tx_amount_to_tx    <= amount_r;
243
          tx_comm_to_tx      <= "00010";
244
 
245
          -- Increase transfer length for the next time
246
          if conv_integer(amount_r) >= amount_max_c then
247
            amount_r <= conv_std_logic_vector(1, amount_width_g);
248
          else
249
            amount_r <= amount_r+1;
250
          end if;
251
 
252
          -- Loop back to idle state
253
          main_ctrl_r <= idle;
254
 
255
 
256
        when others =>
257
      end case;
258
    end if;
259
  end process test;
260
 
261
  -- avalon_readdata_to_tx <= avalon_data_r;
262
 
263
 
264
  -----------------------------------------------------------------------------
265
  -- Instantiate memory block
266
  ------------------------------------------------------------------------------  
267
  sram_scalable_1 : entity work.sram_scalable
268
    generic map (
269
      rom_data_file_name_g => rom_data_file_name_g,
270
      output_file_name_g   => output_file_name_g,
271
      write_trigger_g      => write_trigger_g,
272
      addr_width_g         => ram_addr_width_g,
273
      data_width_g         => data_width_g)
274
    port map (
275
      cs1_n_in   => cs1_n_to_ram,
276
      cs2_in     => cs2_to_ram,
277
      addr_in    => addr_to_ram,
278
      data_inout => data_inout_ram,
279
      we_n_in    => we_n_to_ram,
280
      oe_n_in    => oe_n_to_ram
281
      );
282
 
283
 
284
 
285
  -----------------------------------------------------------------------------
286
  -- Imitate Avalon switch fabric between mem and n2h2_tx:
287
  --  - delay the addr going to memory by one cycle
288
  --  - delay the data coming from memory by one cycle
289
  ------------------------------------------------------------------------------  
290
  cs1_n_to_ram <= '0';                  -- avalon_waitrequest_to_tx;
291
  cs2_to_ram   <= avalon_re_from_tx;
292
  addr_to_ram  <= conv_std_logic_vector(conv_integer(avalon_addr_from_tx)/4, ram_addr_width_g);
293
 
294
  avalon_waitrequest_to_tx2 <= avalon_waitrequest_to_tx or (not avalon_re_from_tx);
295
  avalon_readdata_to_tx     <= delayed_data_from_ram_r;
296
 
297
 
298
  delay_valid : process (clk, rst_n)
299
  begin  -- process delay_valid
300
    if rst_n = '0' then                 -- asynchronous reset (active low)
301
 
302
    elsif clk'event and clk = '1' then  -- rising clock edge
303
      -- memory latency 2 (note below the same signal assignment)
304
      avalon_readdatavalid_to_tx <= not avalon_waitrequest_to_tx2;
305
 
306
    end if;
307
  end process delay_valid;
308
  -- memory latency 1
309
  -- avalon_readdatavalid_to_tx <= not avalon_waitrequest_to_tx2;
310
 
311
  we_n_to_ram <= '1';
312
  oe_n_to_ram <= '0';
313
 
314
  avalon : process (clk2, rst_n)
315
  begin  -- process avalon
316
    if rst_n = '0' then                 -- asynchronous reset (active low)
317
      avalon_waitrequest_to_tx <= '1';
318
      delayed_data_from_ram_r  <= (others => 'Z');  --data_inout_ram;
319
      avalon_waitr_cnt_r       <= 0;
320
 
321
 
322
    elsif clk'event and clk = '1' then  -- rising clock edge
323
 
324
 
325
      if tx_start_to_tx = '1' then
326
        avalon_addr_r <= mem_addr_r;
327
      end if;
328
 
329
      delayed_data_from_ram_r <= data_inout_ram;
330
 
331
      if avalon_re_from_tx = '1' then
332
        if avalon_waitr_cnt_r = avalon_waitr_c-1 then
333
          avalon_waitr_cnt_r       <= 0;
334
          avalon_waitrequest_to_tx <= '1';
335
        else
336
          avalon_waitr_cnt_r       <= avalon_waitr_cnt_r+1;
337
          avalon_waitrequest_to_tx <= '0';
338
        end if;
339
 
340
      else
341
        avalon_waitrequest_to_tx <= '1';
342
      end if;
343
    end if;
344
                                        --avalon_waitrequest_to_tx <= '0';
345
  end process avalon;
346
 
347
 
348
  -----------------------------------------------------------------------------
349
  -- Imitate the HIBI wrapper that gets the data from n2h2_tx
350
  ------------------------------------------------------------------------------    
351
  hibi : process (clk, rst_n)
352
  begin  -- process hibi
353
    if rst_n = '0' then                 -- asynchronous reset (active low)
354
      hibi_addr_r      <= X"0000ffff";
355
      hibi_full_to_tx  <= '1';
356
      hibi_data_r      <= (others => '0');
357
      hibi_amount_r    <= (others => '0');
358
      hibi_full_cnt_r  <= 0;
359
      hibi_we_was_up_r <= '1';
360
 
361
    elsif clk'event and clk = '1' then  -- rising clock edge
362
 
363
                                        -- Generate full signal
364
      if hibi_we_was_up_r = '1' then
365
        hibi_full_cnt_r <= hibi_full_cnt_r+1;
366
        hibi_full_to_tx <= '1';
367
        if hibi_full_cnt_r = hibi_full_up_cc then
368
          hibi_full_to_tx  <= '0';
369
          hibi_full_cnt_r  <= 0;
370
          hibi_we_was_up_r <= '0';
371
        end if;
372
      end if;
373
 
374
      -- Take and check the incoming data
375
      if hibi_we_from_tx = '1' then
376
        if hibi_full_up_cc > 0 then
377
          hibi_full_to_tx <= '1';
378
        end if;
379
        hibi_we_was_up_r <= '1';
380
 
381
        assert hibi_comm_from_tx /= "00000" report "Error. DMA sets comm=idle" severity error;
382
 
383
 
384
 
385
        if hibi_av_from_tx = '1' then
386
          -- Check incoming address
387
          -- +1 because of the main test program value
388
          assert hibi_addr_r+1 = hibi_data_from_tx report "hibi addr error" severity error;
389
          hibi_addr_r <= hibi_addr_r+1;
390
 
391
        else
392
          -- Check incoming data
393
          assert avalon_readdata_to_tx = hibi_data_from_tx report "hibi data error" severity error;
394
 
395
          if hibi_data_r = 2**ram_addr_width_g-1 then
396
            hibi_data_r <= (others => '0');
397
          else
398
            hibi_data_r <= hibi_data_r+1;
399
          end if;
400
 
401
          hibi_amount_r        <= hibi_amount_r+1;
402
          assert hibi_amount_r <= tx_amount_to_tx report "too many data" severity error;
403
        end if;
404
 
405
      else
406
        -- DMA does not write to HIBI        
407
        if main_ctrl_r = send then
408
          hibi_amount_r <= (others => '0');
409
        end if;
410
      end if;
411
 
412
    end if;
413
  end process hibi;
414
 
415
 
416
  -----------------------------------------------------------------------------
417
  -- 
418
  ------------------------------------------------------------------------------  
419
  full_control : process
420
  begin  -- process full_control
421
    wait for incr_hibi_full_after_c;
422
    hibi_full_up_cc <= hibi_full_up_cc+1;
423
  end process full_control;
424
 
425
 
426
 
427
  -----------------------------------------------------------------------------
428
  -- Generate clokcs and reset
429
  ------------------------------------------------------------------------------  
430
  CLOCK1 : process                      -- generate clock signal for design
431
    variable clktmp : std_logic := '0';
432
  begin
433
    wait for PERIOD/2;
434
    clktmp := not clktmp;
435
    Clk    <= clktmp;
436
  end process CLOCK1;
437
 
438
  CLOCK2 : process                      -- generate clock signal for design
439
    variable clktmp : std_logic := '0';
440
  begin
441
    clktmp := not clktmp;
442
    Clk2   <= clktmp;
443
    wait for PERIOD/2;
444
  end process CLOCK2;
445
 
446
  RESET : process
447
  begin
448
    Rst_n <= '0';                       -- Reset the testsystem
449
    wait for 6*PERIOD;                  -- Wait 
450
    Rst_n <= '1';                       -- de-assert reset
451
    wait;
452
  end process RESET;
453
 
454
 
455
 
456
 
457
end rtl;

powered by: WebSVN 2.1.0

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