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/] [gray_fifo/] [1.0/] [vhd/] [cdc_fifo_tester.vhd] - Blame information for rev 145

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
library ieee;
2
use ieee.std_logic_1164.all;
3
use ieee.numeric_std.all;
4
 
5
entity cdc_fifo_tester is
6
 
7
  generic (
8
    depth_log2_g : integer := 2;
9
    dataw_g      : integer := 30
10
    );
11
 
12
  port (
13
    rd_clk, wr_clk      : in  std_logic;
14
    rst_n               : in  std_logic;
15
    pass_out, error_out : out std_logic;
16
    pass_count_out      : out std_logic_vector(31 downto 0));
17
 
18
end entity cdc_fifo_tester;
19
 
20
architecture rtl of cdc_fifo_tester is
21
 
22
  signal input_ctr_r    : unsigned(dataw_g-1 downto 0);
23
  signal expected_ctr_r : unsigned(dataw_g-1 downto 0);
24
  signal check_r        : std_logic;
25
  signal wr_state       : integer range 0 to 3 := 0;
26
 
27
  constant READ_AHEAD_co : integer := 0;
28
 
29
  signal wr_data_in                : std_logic_vector(dataw_g-1 downto 0);
30
  signal rd_data_out               : std_logic_vector(dataw_g-1 downto 0);
31
  signal rd_empty_out, wr_full_out : std_logic;
32
  signal wr_en, rd_en              : std_logic;
33
 
34
  signal pass_count_r : unsigned(31 downto 0);
35
 
36
  signal wr_empty_r  : std_logic;
37
  signal rd_full_r   : std_logic;
38
  signal wr_empty2_r : std_logic;
39
  signal rd_full2_r  : std_logic;
40
 
41
  signal re_to_fifo : std_logic;
42
  constant wr_wait_c : integer := 10;
43
  signal wr_wait_r : integer range 0 to wr_wait_c-1;
44
  signal we_wait_r : std_logic;
45
begin  -- architecture rtl
46
 
47
  cdc_fifo_inst : entity work.cdc_fifo
48
    generic map (
49
      READ_AHEAD_g  => READ_AHEAD_co,
50
      SYNC_CLOCKS_g => 0,
51
      depth_log2_g  => depth_log2_g,
52
      dataw_g       => dataw_g)
53
    port map (
54
      rst_n        => rst_n,
55
      rd_clk       => rd_clk,
56
      rd_en_in     => re_to_fifo, --rd_en,
57
      rd_empty_out => rd_empty_out,
58
      rd_data_out  => rd_data_out,
59
      wr_clk       => wr_clk,
60
      wr_en_in     => wr_en,
61
      wr_full_out  => wr_full_out,
62
      wr_data_in   => wr_data_in);
63
 
64
re_to_fifo <= '1';
65
  wr_data_in     <= std_logic_vector(input_ctr_r);
66
  pass_count_out <= std_logic_vector(pass_count_r);
67
 
68
  x : process (wr_state, wr_full_out, rd_empty_out)
69
  begin
70
    if (wr_state < 2) then
71
      -- write inputs as fast as possible.
72
      -- (i.e. write when fifo is not full)
73
      -- read as fast as possible.
74
      -- (i.e. read when fifo is not empty)
75
      wr_en <= not wr_full_out;
76
      rd_en <= not rd_empty_out;
77
    elsif (wr_state = 2) then
78
      -- write inputs "as slow as possible"!
79
      -- (i.e. write only when fifo is empty)
80
      -- read whne fifo is not empty.
81
--      wr_en <= wr_empty2_r;
82
--        wr_en <= not wr_full_out;
83
      wr_en <= we_wait_r;
84
        rd_en <= not rd_empty_out;
85
    else
86
      -- write inputs as fast as possible.
87
      -- (i.e. write when fifo is not full)
88
      -- read only when fifo is full
89
      wr_en <= not wr_full_out;
90
      rd_en <= not rd_empty_out;
91
      --rd_en <= rd_full2_r;
92
    end if;
93
  end process x;
94
 
95
  inproc : process (wr_clk, rst_n) is
96
  begin  -- process inproc
97
    if rst_n = '0' then                 -- asynchronous reset (active low)
98
      input_ctr_r  <= (others => '0');
99
      wr_state     <= 0;
100
      pass_out     <= '0';
101
      pass_count_r <= (others => '0');
102
      wr_empty_r   <= '0';
103
      wr_empty2_r  <= '0';
104
      wr_wait_r <= 0;
105
      we_wait_r <= '0';
106
 
107
    elsif rising_edge(wr_clk) then      -- rising clock edge
108
      wr_empty_r  <= rd_empty_out;
109
      wr_empty2_r <= wr_empty_r;
110
 
111
      if (wr_en = '1') then
112
        input_ctr_r <= input_ctr_r + 1;
113
 
114
        pass_out <= '0';
115
        -- change state when pass/round done
116
        if (input_ctr_r = 2**dataw_g - 1) then
117
          wr_state     <= (wr_state + 1) mod 4;
118
          pass_out     <= '1';
119
          pass_count_r <= pass_count_r + 1;
120
          input_ctr_r <= (others => '0');
121
        end if;
122
      end if;
123
 
124
      if wr_state = 2 then
125
        if wr_wait_r < wr_wait_c-1 then
126
          wr_wait_r <= wr_wait_r+1;
127
          we_wait_r <= '0';
128
        else
129
          we_wait_r <= '1' and (not wr_full_out);
130
        end if;
131
      else
132
        wr_wait_r <= 0;
133
      end if;
134
 
135
    end if;
136
  end process inproc;
137
 
138
 
139
 
140
  outchecker : process (rd_clk, rst_n) is
141
  begin  -- process outcheker
142
    if rst_n = '0' then                 -- asynchronous reset (active low)
143
      expected_ctr_r <= (others => '0');
144
      check_r        <= '0';
145
      error_out      <= '0';
146
      rd_full_r      <= '0';
147
      rd_full2_r     <= '0';
148
    elsif rising_edge(rd_clk) then      -- rising clock edge
149
      check_r    <= rd_en;
150
      rd_full_r  <= wr_full_out;
151
      rd_full2_r <= rd_full_r;
152
 
153
      if ((check_r = '1' and READ_AHEAD_co = 0) or
154
          (rd_en = '1' and READ_AHEAD_co /= 0)) then
155
        if (std_logic_vector(expected_ctr_r) /= rd_data_out) then
156
          assert (false) report "test failed!" severity failure;
157
          error_out <= '1';
158
        end if;
159
        expected_ctr_r <= expected_ctr_r + 1;
160
      end if;
161
 
162
    end if;
163
  end process outchecker;
164
 
165
end architecture rtl;

powered by: WebSVN 2.1.0

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