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_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 "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
  generic (
29
    re_faster_g : integer := 0);        -- 0 we faster, 1 re
30
  port (
31
    clk_we    : in  std_logic;
32
    clk_re    : in  std_logic;
33
    clk_ps_re : in  std_logic;
34
    clk_ps_we : in  std_logic;
35
    error_out : out std_logic;
36
    rst_n     : in  std_logic
37
    );
38
end tb_mixed_clk_fifo;
39
 
40
-------------------------------------------------------------------------------
41
 
42
architecture rtl of tb_mixed_clk_fifo is
43
 
44
  -- component generics
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_g,
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
      error_out <= '0';
145
      if re_to_dut = '1' then
146
        if data_cnt_r /= data_from_dut then
147
          error_out <= '1';
148
          assert data_cnt_r = data_from_dut report "wrong value read: " & str(data_from_dut) & "wait: " & str(data_cnt_r) severity error;
149
        end if;
150
        if data_cnt_r /= data_cnt_r'high then
151
          data_cnt_r <= data_cnt_r+1;
152
        else
153
          data_cnt_r <= (others => '0');
154
        end if;
155
      else
156
        data_cnt_r <= data_cnt_r;
157
      end if;
158
 
159
      if read_phase_r < read_phase_c then
160
        int_re_r     <= '1';
161
        read_phase_r <= read_phase_r+1;
162
 
163
      else
164
        if read_phase_r < read_phase_c*2 then
165
          int_re_r     <= '0';
166
          read_phase_r <= read_phase_r+1;
167
        else
168
          int_re_r     <= '0';
169
          read_phase_r <= 0;
170
        end if;
171
      end if;
172
 
173
    end if;
174
  end process re;
175
 
176
 
177
end rtl;
178
 
179
-------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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