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

powered by: WebSVN 2.1.0

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