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/] [multiclk_fifo/] [1.0/] [tb/] [tb_multiclk_fifo.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 "multiclk_fifo"
3
-- Project    : 
4
-------------------------------------------------------------------------------
5
-- File       : tb_multiclk_fifo.vhd
6
-- Author     : kulmala3
7
-- Created    : 16.12.2005
8
-- Last update: 16.12.2005
9
-- Description: 
10
-------------------------------------------------------------------------------
11
-- Copyright (c) 2005 
12
-------------------------------------------------------------------------------
13
-- Revisions  :
14
-- Date        Version  Author  Description
15
-- 16.12.2005  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 ieee.std_logic_1164.all;
23
use work.txt_util.all;
24
 
25
-------------------------------------------------------------------------------
26
 
27
entity tb_multiclk_fifo is
28
 
29
end tb_multiclk_fifo;
30
 
31
-------------------------------------------------------------------------------
32
 
33
architecture rtl of tb_multiclk_fifo is
34
 
35
  component multiclk_fifo
36
    generic (
37
      re_freq_g    : integer;
38
      we_freq_g    : integer;
39
      depth_g      : integer;
40
      data_width_g : integer);
41
    port (
42
      clk_re    : in  std_logic;
43
      clk_we    : in  std_logic;
44
      rst_n     : in  std_logic;
45
      data_in   : in  std_logic_vector (data_width_g-1 downto 0);
46
      we_in     : in  std_logic;
47
      full_out  : out std_logic;
48
      one_p_out : out std_logic;
49
      re_in     : in  std_logic;
50
      data_out  : out std_logic_vector (data_width_g-1 downto 0);
51
      empty_out : out std_logic;
52
      one_d_out : out std_logic);
53
  end component;
54
 
55
  -- component generics
56
  constant re_freq_g : integer := 3;
57
  constant we_freq_g : integer := 1;
58
  constant Period_re : time    := 10 ns;
59
  constant Period_we : time    := 30 ns;
60
--  constant re_freq_g  : integer := 1;
61
--  constant we_freq_g  : integer := 3;
62
--  constant Period_re : time    := 30 ns;
63
--  constant Period_we : time    := 10 ns;
64
  constant re_freq_g : integer := 1;
65
  constant we_freq_g : integer := 1;
66
  constant Period_re : time    := 10 ns;
67
  constant Period_we : time    := 10 ns;
68
 
69
  constant depth_g      : integer := 3;
70
  constant data_width_g : integer := 4;
71
 
72
  -- component ports
73
  signal clk_re         : std_logic;
74
  signal clk_we         : std_logic;
75
  signal rst_n          : std_logic;
76
  signal data_to_dut    : std_logic_vector (data_width_g-1 downto 0);
77
  signal we_to_dut      : std_logic;
78
  signal full_from_dut  : std_logic;
79
  signal one_p_from_dut : std_logic;
80
  signal re_to_dut      : std_logic;
81
  signal data_from_dut  : std_logic_vector (data_width_g-1 downto 0);
82
  signal empty_from_dut : std_logic;
83
  signal one_d_from_dut : std_logic;
84
  signal data_cnt_r     : std_logic_vector(data_width_g-1 downto 0);
85
 
86
  -- to create periods of not reading or not writing,
87
  -- full and empty cases
88
  constant write_phase_c : integer := 7;
89
  constant read_phase_c  : integer := 6;
90
  signal   read_phase_r  : integer;
91
  signal   write_phase_r : integer;
92
  signal   int_re_r      : std_logic;
93
  signal   int_we_r      : std_logic;
94
 
95
begin  -- rtl
96
 
97
  -- component instantiation
98
  DUT : multiclk_fifo
99
    generic map (
100
      re_freq_g    => re_freq_g,
101
      we_freq_g    => we_freq_g,
102
      depth_g      => depth_g,
103
      data_width_g => data_width_g)
104
    port map (
105
      clk_re    => clk_re,
106
      clk_we    => clk_we,
107
      rst_n     => rst_n,
108
      data_in   => data_to_dut,
109
      we_in     => we_to_dut,
110
      full_out  => full_from_dut,
111
      one_p_out => one_p_from_dut,
112
      re_in     => re_to_dut,
113
      data_out  => data_from_dut,
114
      empty_out => empty_from_dut,
115
      one_d_out => one_d_from_dut
116
      );
117
 
118
  we_to_dut <= (not full_from_dut) and int_we_r;
119
 
120
  wr : process (clk_we, rst_n)
121
  begin  -- process write
122
    if rst_n = '0' then                 -- asynchronous reset (active low)
123
      data_to_dut   <= (others => '0');
124
--      we_to_dut     <= '0';
125
      write_phase_r <= 0;
126
      int_we_r      <= '0';
127
 
128
    elsif clk_we'event and clk_we = '1' then  -- rising clock edge
129
      if we_to_dut = '1' then
130
        if data_to_dut /= data_to_dut'high then
131
          data_to_dut <= data_to_dut+1;
132
        else
133
          data_to_dut <= (others => '0');
134
        end if;
135
      else
136
--          we_to_dut   <= '1';
137
        data_to_dut <= data_to_dut;
138
      end if;
139
 
140
      if write_phase_r < write_phase_c then
141
        write_phase_r <= write_phase_r+1;
142
        int_we_r      <= '1';
143
 
144
      else
145
        if write_phase_r < write_phase_c*2 then
146
          int_we_r      <= '0';
147
--          we_to_dut     <= '0';
148
          write_phase_r <= write_phase_r+1;
149
        else
150
          write_phase_r <= 0;
151
--          we_to_dut <= '1';
152
        end if;
153
      end if;
154
 
155
    end if;
156
 
157
  end process wr;
158
 
159
  re_to_dut <= not empty_from_dut and int_re_r;
160
 
161
  re : process (clk_re, rst_n)
162
  begin  -- process re
163
    if rst_n = '0' then                 -- asynchronous reset (active low)
164
--      re_to_dut  <= '0';
165
      data_cnt_r   <= conv_std_logic_vector(0, data_width_g);
166
      read_phase_r <= 0;
167
      int_re_r     <= '1';
168
    elsif clk_re'event and clk_re = '1' then  -- rising clock edge
169
 
170
      if re_to_dut = '1' then
171
        assert data_cnt_r = data_from_dut report "wrong value read: " & str(data_from_dut) & "wait: " & str(data_cnt_r) severity error;
172
        if data_cnt_r /= data_cnt_r'high then
173
          data_cnt_r <= data_cnt_r+1;
174
        else
175
          data_cnt_r <= (others => '0');
176
        end if;
177
      else
178
        data_cnt_r <= data_cnt_r;
179
      end if;
180
 
181
      if read_phase_r < read_phase_c then
182
        int_re_r     <= '1';
183
        read_phase_r <= read_phase_r+1;
184
 
185
      else
186
        if read_phase_r < read_phase_c*2 then
187
          int_re_r     <= '0';
188
          read_phase_r <= read_phase_r+1;
189
        else
190
          int_re_r     <= '0';
191
          read_phase_r <= 0;
192
        end if;
193
      end if;
194
 
195
    end if;
196
  end process re;
197
 
198
 
199
 
200
  -- clock generation
201
  -- PROC  
202
  CLOCK1 : process                      -- generate clock signal for design
203
    variable clktmp : std_logic := '0';
204
  begin
205
    clktmp := not clktmp;
206
    clk_re <= clktmp;
207
    wait for Period_re/2;
208
  end process CLOCK1;
209
 
210
  CLOCK2 : process                      -- generate clock signal for design
211
    variable clktmp : std_logic := '0';
212
  begin
213
    clktmp := not clktmp;
214
    clk_we <= clktmp;
215
    wait for Period_we/2;
216
  end process CLOCK2;
217
 
218
  -- PROC
219
  RESET : process
220
  begin
221
    Rst_n <= '0';                       -- Reset the testsystem
222
    wait for 6*Period_re;               -- Wait 
223
    Rst_n <= '1';                       -- de-assert reset
224
    wait;
225
  end process RESET;
226
 
227
 
228
 
229
end rtl;
230
 
231
-------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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