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/] [pkt_codec_mk2/] [1.0/] [vhd/] [cdc.vhd] - Blame information for rev 147

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
-------------------------------------------------------------------------------
2
-- Title      : CDC (Clock Domain Crossing)
3
-- Project    : 
4
-------------------------------------------------------------------------------
5
-- File       : cdc.vhd
6
-- Author     : Lasse Lehtonen
7
-- Company    : 
8
-- Created    : 2011-10-12
9 147 lanttu
-- Last update: 2012-06-14
10 145 lanttu
-- Platform   : 
11
-- Standard   : VHDL'87
12
-------------------------------------------------------------------------------
13
-- Description:
14
--
15
-- Generics:
16
-- 
17
-- clock_mode_g 0 : single clock
18
-- clock_mode_g 1 : two asynchronous clocks
19
--
20
-------------------------------------------------------------------------------
21
-- Copyright (c) 2011 
22
-------------------------------------------------------------------------------
23
-- Revisions  :
24
-- Date        Version  Author  Description
25
-- 2011-10-12  1.0      lehton87        Created
26
-------------------------------------------------------------------------------
27
 
28
library ieee;
29
use ieee.std_logic_1164.all;
30
 
31
entity cdc is
32
 
33
  generic (
34
    cmd_width_g  : positive;
35
    data_width_g : positive;
36 147 lanttu
    clock_mode_g : natural;
37
    len_width_g  : natural;
38
    fifo_depth_g : natural);
39 145 lanttu
 
40
  port (
41
    clk_ip  : in std_logic;
42
    clk_net : in std_logic;
43
    rst_n   : in std_logic;
44
 
45
    ip_cmd_out  : out std_logic_vector(cmd_width_g-1 downto 0);
46
    ip_data_out : out std_logic_vector(data_width_g-1 downto 0);
47
    ip_stall_in : in  std_logic;
48
 
49
    ip_cmd_in    : in  std_logic_vector(cmd_width_g-1 downto 0);
50
    ip_data_in   : in  std_logic_vector(data_width_g-1 downto 0);
51
    ip_stall_out : out std_logic;
52
 
53 147 lanttu
    ip_len_in : in std_logic_vector(len_width_g-1 downto 0);  -- 2012-05-04
54
 
55 145 lanttu
    net_cmd_out  : out std_logic_vector(cmd_width_g-1 downto 0);
56
    net_data_out : out std_logic_vector(data_width_g-1 downto 0);
57
    net_stall_in : in  std_logic;
58
 
59 147 lanttu
    net_len_out : out std_logic_vector(len_width_g-1 downto 0);  -- 2012-05-04
60
 
61 145 lanttu
    net_cmd_in    : in  std_logic_vector(cmd_width_g-1 downto 0);
62
    net_data_in   : in  std_logic_vector(data_width_g-1 downto 0);
63
    net_stall_out : out std_logic);
64
 
65
end cdc;
66
 
67
 
68
architecture rtl of cdc is
69
 
70
  signal ip_in_cd     : std_logic_vector(cmd_width_g+data_width_g-1 downto 0);
71
  signal net_in_cd    : std_logic_vector(cmd_width_g+data_width_g-1 downto 0);
72
  signal ip_out_cd    : std_logic_vector(cmd_width_g+data_width_g-1 downto 0);
73
  signal net_out_cd   : std_logic_vector(cmd_width_g+data_width_g-1 downto 0);
74
  signal ip_out_cd_r  : std_logic_vector(cmd_width_g+data_width_g-1 downto 0);
75
  signal net_out_cd_r : std_logic_vector(cmd_width_g+data_width_g-1 downto 0);
76
  signal ip_we        : std_logic;
77
  signal net_we       : std_logic;
78
  signal ip_re        : std_logic;
79
  signal net_re       : std_logic;
80
  signal ip_empty     : std_logic;
81
  signal net_empty    : std_logic;
82 147 lanttu
 
83
  signal out_len   : std_logic_vector(len_width_g-1 downto 0);  -- 2012-05-04
84
  signal out_len_r : std_logic_vector(len_width_g-1 downto 0);  -- 2012-05-04
85 145 lanttu
 
86
begin  -- rtl
87
 
88
  -----------------------------------------------------------------------------
89
  -- ONE CLOCK
90
  --
91
  -- Just a direct combinatorial connection
92
  -----------------------------------------------------------------------------
93
  clock_mode_0 : if clock_mode_g = 0 generate
94
 
95
    ip_cmd_out    <= net_cmd_in;
96
    ip_data_out   <= net_data_in;
97
    net_stall_out <= ip_stall_in;
98
 
99
    net_cmd_out  <= ip_cmd_in;
100
    net_data_out <= ip_data_in;
101
    ip_stall_out <= net_stall_in;
102 147 lanttu
 
103
    net_len_out <= ip_len_in;           -- 2012-05-04
104 145 lanttu
 
105
  end generate clock_mode_0;
106
 
107
  -----------------------------------------------------------------------------
108
  -- TWO ASYNCHRONOUS CLOCKS
109
  -----------------------------------------------------------------------------
110
  clock_mode_1 : if clock_mode_g = 1 generate
111
 
112
    ---------------------------------------------------------------------------
113
    -- FROM IP TO NET
114
    ---------------------------------------------------------------------------
115
    ip_in_cd <= ip_cmd_in & ip_data_in;
116
    net_re   <= not net_stall_in;
117
 
118
    ip_we_p : process (ip_cmd_in)
119
    begin  -- process ip_we_p
120
      if ip_cmd_in /= "00" then
121
        ip_we <= '1';
122
      else
123
        ip_we <= '0';
124
      end if;
125
    end process ip_we_p;
126
 
127
    fifo_ip2net : entity work.fifo_2clk
128
      generic map (
129
        data_width_g => cmd_width_g+data_width_g,
130 147 lanttu
        depth_g      => fifo_depth_g)
131 145 lanttu
      port map (
132
        rst_n => rst_n,
133
 
134
        clk_wr   => clk_ip,
135
        we_in    => ip_we,
136
        data_in  => ip_in_cd,
137
        full_out => ip_stall_out,
138
 
139
        clk_rd    => clk_net,
140
        re_in     => net_re,
141
        data_out  => net_out_cd,
142
        empty_out => net_empty);
143
 
144 147 lanttu
    fifo_len2net : entity work.fifo_2clk  -- 2012-05-04
145
      generic map (
146
        data_width_g => len_width_g,
147
        depth_g      => fifo_depth_g)
148
      port map (
149
        rst_n => rst_n,
150
 
151
        clk_wr   => clk_ip,
152
        we_in    => ip_we,
153
        data_in  => ip_len_in,
154
        full_out => open,
155
 
156
        clk_rd    => clk_net,
157
        re_in     => net_re,
158
        data_out  => out_len,
159
        empty_out => open);
160
 
161
    sto1_p : process (clk_net, rst_n)
162 145 lanttu
    begin  -- process sto1_p
163
      if rst_n = '0' then               -- asynchronous reset (active low)
164
        net_out_cd_r <= (others => '0');
165 147 lanttu
        out_len_r <= (others => '0'); -- 2012-05-04
166 145 lanttu
      elsif clk_net'event and clk_net = '1' then  -- rising clock edge
167
        if net_stall_in = '0' and net_empty = '0' then
168
          net_out_cd_r <= net_out_cd;
169 147 lanttu
          out_len_r    <= out_len;      -- 2012-05-04
170
        end if;
171 145 lanttu
      end if;
172
    end process sto1_p;
173
 
174 147 lanttu
    net_outs_p : process (net_empty, net_out_cd, net_out_cd_r, net_stall_in,
175
                          out_len, out_len_r)
176 145 lanttu
    begin  -- process net_outs_p
177
      if net_stall_in = '1' then
178
        net_cmd_out <= net_out_cd_r(cmd_width_g+data_width_g-1 downto
179
                                    data_width_g);
180
        net_data_out <= net_out_cd_r(data_width_g-1 downto 0);
181 147 lanttu
        net_len_out  <= out_len_r;      -- 2012-05-04
182 145 lanttu
      elsif net_empty = '1' then
183 147 lanttu
        net_cmd_out  <= (others => '0');
184 145 lanttu
        net_data_out <= (others => '0');
185 147 lanttu
        net_len_out  <= (others => '0');  -- 2012-05-04
186 145 lanttu
      else
187
        net_cmd_out <= net_out_cd(cmd_width_g+data_width_g-1 downto
188
                                  data_width_g);
189
        net_data_out <= net_out_cd(data_width_g-1 downto 0);
190 147 lanttu
        net_len_out  <= out_len;      -- 2012-05-04
191 145 lanttu
      end if;
192
    end process net_outs_p;
193 147 lanttu
 
194 145 lanttu
    ---------------------------------------------------------------------------
195
    -- FROM NET TO IP
196
    ---------------------------------------------------------------------------
197
    net_in_cd <= net_cmd_in & net_data_in;
198
    ip_re     <= not ip_stall_in;
199
 
200
    net_we_p : process (net_cmd_in)
201
    begin  -- process ip_we_p
202
      if net_cmd_in /= "00" then
203
        net_we <= '1';
204
      else
205
        net_we <= '0';
206
      end if;
207
    end process net_we_p;
208
 
209
    fifo_net2ip : entity work.fifo_2clk
210
      generic map (
211
        data_width_g => cmd_width_g+data_width_g,
212 147 lanttu
        depth_g      => fifo_depth_g)
213 145 lanttu
      port map (
214
        rst_n => rst_n,
215
 
216
        clk_wr   => clk_net,
217
        we_in    => net_we,
218
        data_in  => net_in_cd,
219
        full_out => net_stall_out,
220
 
221
        clk_rd    => clk_ip,
222
        re_in     => ip_re,
223
        data_out  => ip_out_cd,
224
        empty_out => ip_empty);
225
 
226 147 lanttu
    sto2_p : process (clk_ip, rst_n)
227 145 lanttu
    begin  -- process sto1_p
228
      if rst_n = '0' then               -- asynchronous reset (active low)
229
        ip_out_cd_r <= (others => '0');
230
      elsif clk_ip'event and clk_ip = '1' then  -- rising clock edge
231
        if ip_stall_in = '0' and ip_empty = '0' then
232
          ip_out_cd_r <= ip_out_cd;
233 147 lanttu
        end if;
234 145 lanttu
      end if;
235
    end process sto2_p;
236
 
237 147 lanttu
    ip_outs_p : process (ip_empty, ip_out_cd, ip_out_cd_r, ip_stall_in)
238 145 lanttu
    begin  -- process net_outs_p
239
      if ip_stall_in = '1' then
240
        ip_cmd_out <= ip_out_cd_r(cmd_width_g+data_width_g-1 downto
241
                                  data_width_g);
242
        ip_data_out <= ip_out_cd_r(data_width_g-1 downto 0);
243
      elsif ip_empty = '1' then
244 147 lanttu
        ip_cmd_out  <= (others => '0');
245 145 lanttu
        ip_data_out <= (others => '0');
246
      else
247
        ip_cmd_out <= ip_out_cd(cmd_width_g+data_width_g-1 downto
248 147 lanttu
                                data_width_g);
249 145 lanttu
        ip_data_out <= ip_out_cd(data_width_g-1 downto 0);
250
      end if;
251
    end process ip_outs_p;
252
 
253
  end generate clock_mode_1;
254
 
255
end rtl;

powered by: WebSVN 2.1.0

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