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.storage/] [fifos/] [synchronizer/] [1.0/] [tb/] [tb_aif_top.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 "asynch_if_s"
3
-- Project    : 
4
-------------------------------------------------------------------------------
5
-- File       : tb_asynch_if_send.vhd
6
-- Author     : 
7
-- Created    : 04.01.2006
8
-- Last update: 02.03.2006
9
-- Description: 
10
-------------------------------------------------------------------------------
11
-- Copyright (c) 2006 
12
-------------------------------------------------------------------------------
13
-- Revisions  :
14
-- Date        Version  Author  Description
15
-- 04.01.2006  1.0      AK      Created
16
-------------------------------------------------------------------------------
17
 
18
library ieee;
19
use ieee.std_logic_1164.all;
20
use ieee.std_logic_arith.all;
21
use ieee.std_logic_unsigned.all;
22
use work.txt_util.all;
23
-------------------------------------------------------------------------------
24
 
25
entity tb_aif_top is
26
 
27
end tb_aif_top;
28
 
29
-------------------------------------------------------------------------------
30
 
31
architecture rtl of tb_aif_top is
32
 
33
  constant data_width_g : integer := 32;
34
 
35
  -- component ports
36
  signal clk   : std_logic;
37
  signal rst_n : std_logic;
38
 
39
  -- clock and reset
40
  constant Period : time := 10 ns;
41
  constant Period2 : time := 100 ns;
42
 
43
  component aif_read_top
44
    generic (
45
      data_width_g : integer);
46
    port (
47
      tx_clk       : in  std_logic;
48
      tx_rst_n     : in  std_logic;
49
      tx_data_in   : in  std_logic_vector(data_width_g-1 downto 0);
50
      tx_empty_in  : in  std_logic;
51
      tx_re_out    : out std_logic;
52
      rx_clk       : in  std_logic;
53
      rx_rst_n     : in  std_logic;
54
      rx_empty_out : out std_logic;
55
      rx_re_in     : in  std_logic;
56
      rx_data_out  : out std_logic_vector(data_width_g-1 downto 0));
57
  end component;
58
 
59
  signal tx_data_to    : std_logic_vector(data_width_g-1 downto 0);
60
  signal tx_empty_to   : std_logic;
61
  signal tx_re_from    : std_logic;
62
  signal rx_empty_from : std_logic;
63
  signal rx_re_to      : std_logic;
64
  signal rx_data_from  : std_logic_vector(data_width_g-1 downto 0);
65
 
66
  signal   clk2        : std_logic;
67
  constant clk_scaler : integer := 1;
68
  constant clk2_scaler : integer := 1;
69
 
70
  signal cnt_tx_data_r : std_logic_vector(data_width_g-1 downto 0);
71
  signal cnt_rx_data_r : std_logic_vector(data_width_g-1 downto 0);
72
  signal rx_full_cnt_r : integer;
73
  signal tx_we_cnt_r   : integer;
74
 
75
  constant full_after_we_c  : integer := 3;   -- after n data issue full
76
  constant full_length_c    : integer := 10;  -- cc full is asserted
77
  constant time_before_we_c : integer := 10;   -- delay after sending
78
  constant start_value_c    : integer := 3;
79
 
80
begin  -- rtl
81
 
82
 
83
  aif_read_top_1 : aif_read_top
84
    generic map (
85
      data_width_g => data_width_g)
86
    port map (
87
      tx_clk       => clk2,
88
      tx_rst_n     => rst_n,
89
      tx_data_in   => tx_data_to,
90
      tx_empty_in  => tx_empty_to,
91
      tx_re_out    => tx_re_from,
92
      rx_clk       => clk,
93
      rx_rst_n     => rst_n,
94
      rx_empty_out => rx_empty_from,
95
      rx_re_in     => rx_re_to,
96
      rx_data_out  => rx_data_from
97
      );
98
 
99
 
100
  -- use clk
101
  process (clk, rst_n)
102
  begin  -- process
103
    if rst_n = '0' then                 -- asynchronous reset (active low)
104
      cnt_rx_data_r <= conv_std_logic_vector(start_value_c, data_width_g);
105
      rx_re_to      <= '0';
106
      rx_full_cnt_r <= 0;
107
 
108
    elsif clk'event and clk = '1' then  -- rising clock edge
109
      if rx_empty_from = '0' and rx_re_to = '1' then
110
        cnt_rx_data_r <= cnt_rx_data_r+1;
111
        assert cnt_rx_data_r = rx_data_from report "Error: rx data wrong wait: " &
112
          str(conv_integer(cnt_rx_data_r)) & "got: " &
113
          str(conv_integer(rx_data_from))
114
          severity error;
115
 
116
      end if;
117
      if rx_empty_from = '0' then
118
 
119
        if rx_full_cnt_r > full_after_we_c + full_after_we_c -1 then
120
          rx_re_to      <= '1';
121
          rx_full_cnt_r <= 0;
122
        elsif rx_full_cnt_r > full_after_we_c-1 then
123
          rx_re_to      <= '0';
124
          rx_full_cnt_r <= rx_full_cnt_r+1;
125
        else
126
          rx_re_to      <= '1';
127
          rx_full_cnt_r <= rx_full_cnt_r+1;
128
        end if;
129
 
130
      else
131
        rx_re_to <= '0';
132
      end if;
133
      -- rx re to always '1', resemble n2h2 behavior
134
      -- rx_re_to <= '1';
135
    end if;
136
 
137
  end process;
138
 
139
 
140
  -- transmit, use different clock.
141
  tx : process (clk2, rst_n)
142
  begin  -- process tx
143
    if rst_n = '0' then                 -- asynchronous reset (active low)
144
      tx_we_cnt_r   <= 0;
145
      tx_data_to    <= conv_std_logic_vector(start_value_c, data_width_g);
146
      cnt_tx_data_r <= conv_std_logic_vector(start_value_c+1, data_width_g);
147
      tx_empty_to   <= '1';
148
 
149
    elsif clk2'event and clk2 = '1' then  -- rising clock edge
150
      if tx_we_cnt_r > 0 then
151
        tx_we_cnt_r <= tx_we_cnt_r-1;
152
        tx_empty_to <= '1';
153
      else
154
        tx_empty_to <= '0';
155
        if tx_re_from = '1' then
156
          tx_data_to    <= cnt_tx_data_r;
157
          cnt_tx_data_r <= cnt_tx_data_r+1;
158
          tx_we_cnt_r   <= time_before_we_c;
159
        end if;
160
 
161
      end if;
162
    end if;
163
  end process tx;
164
 
165
  -- clock generation
166
  -- PROC  
167
  CLOCK1 : process                      -- generate clock signal for design
168
    variable clktmp : std_logic := '0';
169
  begin
170
    wait for PERIOD/2;
171
    clktmp := not clktmp;
172
    Clk    <= clktmp;
173
  end process CLOCK1;
174
 
175
  CLOCK2 : process                      -- generate clock signal for design
176
    variable clktmp : std_logic := '0';
177
  begin
178
    wait for PERIOD2/2;
179
    clktmp := not clktmp;
180
    Clk2   <= clktmp;
181
  end process CLOCK2;
182
 
183
  -- PROC
184
  RESET : process
185
  begin
186
    Rst_n <= '0';                       -- Reset the testsystem
187
    wait for 6*PERIOD;                  -- Wait 
188
    Rst_n <= '1';                       -- de-assert reset
189
    wait;
190
  end process RESET;
191
 
192
 
193
 
194
end rtl;
195
 
196
-------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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