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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
-------------------------------------------------------------------------------
2
-- Title      : Multiclock FIFO
3
-- Project    : 
4
-------------------------------------------------------------------------------
5
-- File       : multiclk_fifo.vhd
6
-- Author     : kulmala3
7
-- Created    : 16.12.2005
8
-- Last update: 2010-04-27
9
-- Description: Synchronous multi-clock FIFO. Note that clock frequencies MUST
10
-- be realted (synchronized) in order to avoid metastability.
11
-- Clocks that are asynchronous wrt. each other do not work.
12
--
13
-- Note! data must be ready in the data in wrt. faster clock when writing!
14
-- same applies for re and we
15
-------------------------------------------------------------------------------
16
-- Copyright (c) 2005
17
-------------------------------------------------------------------------------
18
--  This file is part of Transaction Generator.
19
--
20
--  Transaction Generator is free software: you can redistribute it and/or modify
21
--  it under the terms of the Lesser GNU General Public License as published by
22
--  the Free Software Foundation, either version 3 of the License, or
23
--  (at your option) any later version.
24
--
25
--  Transaction Generator is distributed in the hope that it will be useful,
26
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
27
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28
--  Lesser GNU General Public License for more details.
29
--
30
--  You should have received a copy of the Lesser GNU General Public License
31
--  along with Transaction Generator.  If not, see <http://www.gnu.org/licenses/>.
32
-------------------------------------------------------------------------------
33
-- Revisions  :
34
-- Date        Version  Author  Description
35
-- 16.12.2005  1.0      AK      Created
36
-------------------------------------------------------------------------------
37
 
38
library ieee;
39
use ieee.std_logic_1164.all;
40
use ieee.std_logic_arith.all;
41
use ieee.std_logic_unsigned.all;
42
 
43
entity multiclk_fifo is
44
 
45
  generic (
46
    re_freq_g     : integer := 0;        -- integer multiple of clk_we
47
    we_freq_g     : integer := 0;        -- or vice versa
48
    depth_g      : integer := 0;
49
    data_width_g : integer := 0
50
    );
51
  port (
52
    clk_re : in std_logic;
53
    clk_we : in std_logic;
54
    rst_n  : in std_logic;
55
 
56
    data_in   : in  std_logic_vector (data_width_g-1 downto 0);
57
    we_in     : in  std_logic;
58
    full_out  : out std_logic;
59
    one_p_out : out std_logic;
60
 
61
    re_in     : in  std_logic;
62
    data_out  : out std_logic_vector (data_width_g-1 downto 0);
63
    empty_out : out std_logic;
64
    one_d_out : out std_logic
65
    );
66
end multiclk_fifo;
67
 
68
architecture rtl of multiclk_fifo is
69
 
70
  component fifo
71
    generic (
72
      data_width_g : integer;
73
      depth_g      : integer);
74
    port (
75
      clk       : in  std_logic;
76
      rst_n     : in  std_logic;
77
      data_in   : in  std_logic_vector (data_width_g-1 downto 0);
78
      we_in     : in  std_logic;
79
      full_out  : out std_logic;
80
      one_p_out : out std_logic;
81
      re_in     : in  std_logic;
82
      data_out  : out std_logic_vector (data_width_g-1 downto 0);
83
      empty_out : out std_logic;
84
      one_d_out : out std_logic);
85
  end component;
86
 
87
  constant re_per_we_c : integer := re_freq_g / we_freq_g;
88
  constant we_per_re_c : integer := we_freq_g / re_freq_g;
89
 
90
  -- no 0 to x-1, cuz otherwise range 0 to -1 is possible
91
  signal re_cnt_r : integer range 0 to re_per_we_c;
92
  signal we_cnt_r : integer range 0 to we_per_re_c;
93
 
94
  signal data_to_fifo    : std_logic_vector (data_width_g-1 downto 0);
95
  signal we_to_fifo      : std_logic;
96
  signal full_from_fifo  : std_logic;
97
  signal one_p_from_fifo : std_logic;
98
  signal re_to_fifo      : std_logic;
99
  signal data_from_fifo  : std_logic_vector (data_width_g-1 downto 0);
100
  signal empty_from_fifo : std_logic;
101
  signal one_d_from_fifo : std_logic;
102
 
103
begin  -- rtl
104
 
105
  data_to_fifo <= data_in;
106
  full_out     <= full_from_fifo;
107
  one_p_out    <= one_p_from_fifo;
108
  data_out     <= data_from_fifo;
109
  empty_out    <= empty_from_fifo;
110
  one_d_out    <= one_d_from_fifo;
111
 
112
  re_gt_we : if re_freq_g >= we_freq_g generate
113
 
114
    fifo_re_gt_we : fifo
115
      generic map (
116
        data_width_g => data_width_g,
117
        depth_g      => depth_g)
118
      port map (
119
        clk       => clk_re,            -- this is the difference
120
        rst_n     => rst_n,
121
        data_in   => data_to_fifo,
122
        we_in     => we_to_fifo,
123
        full_out  => full_from_fifo,
124
        one_p_out => one_p_from_fifo,
125
        re_in     => re_to_fifo,
126
        data_out  => data_from_fifo,
127
        empty_out => empty_from_fifo,
128
        one_d_out => one_d_from_fifo
129
        );
130
 
131
    re_to_fifo <= re_in;
132
 
133
    equal : if re_per_we_c = 1 generate
134
      we_to_fifo <= we_in;
135
    end generate equal;
136
 
137
    greater : if re_per_we_c > 1 generate
138
      -- re clk is faster than we
139
      process (clk_re, rst_n)
140
      begin  -- process
141
        if rst_n = '0' then             -- asynchronous reset (active low)
142
          we_to_fifo <= '0';--we_in;
143
          re_cnt_r   <= 0;
144
 
145
        elsif clk_re'event and clk_re = '1' then  -- rising clock edge
146
 
147
          if we_in = '1' then
148
            if re_cnt_r = re_per_we_c-2 then
149
              we_to_fifo <= '1';
150
            else
151
              we_to_fifo <= '0';
152
            end if;
153
 
154
            if re_cnt_r /= re_per_we_c-1 then
155
              re_cnt_r <= re_cnt_r+1;
156
            else
157
              re_cnt_r <= 0;
158
            end if;
159
 
160
          else
161
            we_to_fifo <= '0';
162
            re_cnt_r   <= 0;
163
          end if;
164
        end if;
165
      end process;
166
 
167
 
168
    end generate greater;
169
 
170
 
171
  end generate re_gt_we;
172
 
173
  we_gt_re : if re_freq_g < we_freq_g generate
174
 
175
    fifo_re_gt_we : fifo
176
      generic map (
177
        data_width_g => data_width_g,
178
        depth_g      => depth_g)
179
      port map (
180
        clk       => clk_we,
181
        rst_n     => rst_n,
182
        data_in   => data_to_fifo,
183
        we_in     => we_to_fifo,
184
        full_out  => full_from_fifo,
185
        one_p_out => one_p_from_fifo,
186
        re_in     => re_to_fifo,
187
        data_out  => data_from_fifo,
188
        empty_out => empty_from_fifo,
189
        one_d_out => one_d_from_fifo
190
        );
191
 
192
 
193
    we_to_fifo <= we_in;
194
 
195
    -- we clk is faster than re
196
    process (clk_we, rst_n)
197
    begin  -- process
198
      if rst_n = '0' then               -- asynchronous reset (active low)
199
        re_to_fifo <= '0';--re_in;
200
        we_cnt_r   <= 0;
201
 
202
      elsif clk_we'event and clk_we = '1' then  -- rising clock edge
203
        if re_in = '1' then
204
          if we_cnt_r = we_per_re_c-2 then
205
            re_to_fifo <= '1';
206
          else
207
            re_to_fifo <= '0';
208
          end if;
209
          if we_cnt_r /= we_per_re_c-1 then
210
            we_cnt_r <= we_cnt_r+1;
211
          else
212
            we_cnt_r <= 0;
213
          end if;
214
        else
215
          re_to_fifo <= '0';
216
          we_cnt_r   <= 0;
217
        end if;
218
      end if;
219
    end process;
220
 
221
  end generate we_gt_re;
222
 
223
end rtl;

powered by: WebSVN 2.1.0

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