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_asynch_if_fpga.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_fpga.vhd
6
-- Author     : 
7
-- Created    : 04.01.2006
8
-- Last update: 04.01.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_asynch_if_fpga is
26
  port (
27
    clk       : in  std_logic;
28
    clk2      : in  std_logic;
29
    rst_n     : in  std_logic;
30
    error_out : out std_logic
31
    );
32
end tb_asynch_if_fpga;
33
 
34
-------------------------------------------------------------------------------
35
 
36
architecture rtl of tb_asynch_if_fpga is
37
 
38
  component asynch_if_rx
39
    generic (
40
      data_width_g : integer := 32
41
      );
42
    port (
43
      clk      : in  std_logic;
44
      rst_n    : in  std_logic;
45
      a_we_in  : in  std_logic;
46
      ack_out  : out std_logic;
47
      we_out   : out std_logic;
48
      data_in  : in  std_logic_vector(data_width_g-1 downto 0);
49
      data_out : out std_logic_vector(data_width_g-1 downto 0);
50
      full_in  : in  std_logic);
51
  end component;
52
 
53
  constant data_width_g : integer := 32;
54
 
55
  -- component ports
56
  signal ack_from_rx  : std_logic;
57
  signal we_from_rx   : std_logic;
58
  signal data_from_rx : std_logic_vector(data_width_g-1 downto 0);
59
  signal full_to_rx   : std_logic;
60
 
61
  -- clock and reset
62
  component asynch_if_tx
63
    generic (
64
      data_width_g : integer);
65
    port (
66
      clk      : in  std_logic;
67
      rst_n    : in  std_logic;
68
      we_in    : in  std_logic;
69
      data_in  : in  std_logic_vector(data_width_g-1 downto 0);
70
      data_out : out std_logic_vector(data_width_g-1 downto 0);
71
      full_out : out std_logic;
72
      a_we_out : out std_logic;
73
      ack_in   : in  std_logic
74
      );
75
  end component;
76
 
77
  signal we_to_tx     : std_logic;
78
  signal data_to_tx   : std_logic_vector(data_width_g-1 downto 0);
79
  signal data_from_tx : std_logic_vector(data_width_g-1 downto 0);
80
  signal full_from_tx : std_logic;
81
  signal a_we_from_tx : std_logic;
82
 
83
  signal cnt_tx_data_r : std_logic_vector(data_width_g-1 downto 0);
84
  signal cnt_rx_data_r : std_logic_vector(data_width_g-1 downto 0);
85
  signal rx_full_cnt_r : integer;
86
  signal tx_we_cnt_r   : integer;
87
 
88
  constant full_after_we_c  : integer := 3;   -- after n data issue full
89
  constant full_length_c    : integer := 10;  -- cc full is asserted
90
  constant time_before_we_c : integer := 0;   -- delay after sending
91
  constant start_value_c    : integer := 3;
92
 
93
begin  -- rtl
94
 
95
  -- component instantiation
96
  DUT : asynch_if_rx
97
    generic map (
98
      data_width_g => data_width_g)
99
    port map (
100
      clk      => clk,
101
      rst_n    => rst_n,
102
      a_we_in  => a_we_from_tx,
103
      ack_out  => ack_from_rx,
104
      data_in  => data_from_tx,
105
      data_out => data_from_rx,
106
      we_out   => we_from_rx,
107
      full_in  => full_to_rx
108
      );
109
 
110
  asynch_if_tx_1 : asynch_if_tx
111
    generic map (
112
      data_width_g => data_width_g)
113
    port map (
114
      clk      => clk2,
115
      rst_n    => rst_n,
116
      we_in    => we_to_tx,
117
      data_in  => data_to_tx,
118
      data_out => data_from_tx,
119
      full_out => full_from_tx,
120
      a_we_out => a_we_from_tx,
121
      ack_in   => ack_from_rx
122
      );
123
 
124
 
125
  -- receiving, use clk
126
  process (clk, rst_n)
127
  begin  -- process
128
    if rst_n = '0' then                 -- asynchronous reset (active low)
129
      cnt_rx_data_r <= conv_std_logic_vector(start_value_c, data_width_g);
130
      full_to_rx    <= '0';
131
      rx_full_cnt_r <= 0;
132
      error_out     <= '0';
133
 
134
    elsif clk'event and clk = '1' then  -- rising clock edge
135
      if we_from_rx = '1' and full_to_rx = '0' then
136
        if cnt_rx_data_r /= data_from_rx then
137
          error_out <= '1';
138
        else
139
          error_out <= '0';
140
        end if;
141
--        assert cnt_rx_data_r = data_from_rx report "Error: rx data wrong wait: " &
142
--          str(conv_integer(cnt_rx_data_r)) & "got: " &
143
--          str(conv_integer(data_from_rx))
144
--          severity error;
145
        cnt_rx_data_r <= cnt_rx_data_r+1;
146
        rx_full_cnt_r <= rx_full_cnt_r + 1;
147
      end if;
148
 
149
      if rx_full_cnt_r > full_after_we_c + full_after_we_c -1 then
150
        full_to_rx    <= '0';
151
        rx_full_cnt_r <= 0;
152
      elsif rx_full_cnt_r > full_after_we_c-1 then
153
        full_to_rx    <= '1';
154
        rx_full_cnt_r <= rx_full_cnt_r+1;
155
      end if;
156
 
157
    end if;
158
 
159
  end process;
160
 
161
  -- transmit, use different clock.
162
  tx : process (clk2, rst_n)
163
  begin  -- process tx
164
    if rst_n = '0' then                 -- asynchronous reset (active low)
165
      tx_we_cnt_r   <= 0;
166
      data_to_tx    <= conv_std_logic_vector(start_value_c, data_width_g);
167
      cnt_tx_data_r <= conv_std_logic_vector(start_value_c, data_width_g);
168
      we_to_tx      <= '0';
169
 
170
    elsif clk2'event and clk2 = '1' then  -- rising clock edge
171
      if tx_we_cnt_r > 0 then
172
        tx_we_cnt_r <= tx_we_cnt_r-1;
173
        we_to_tx    <= '0';
174
      end if;
175
      if full_from_tx = '0' then
176
        if tx_we_cnt_r = 0 then
177
          we_to_tx      <= '1';
178
          data_to_tx    <= cnt_tx_data_r;
179
          cnt_tx_data_r <= cnt_tx_data_r+1;
180
          tx_we_cnt_r   <= time_before_we_c;
181
        end if;
182
      end if;
183
    end if;
184
  end process tx;
185
 
186
 
187
end rtl;
188
 
189
-------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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