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.communication/] [hibi/] [2.0/] [vhd/] [copy_of_multiclk_fifo.vhd] - Blame information for rev 159

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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