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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
-------------------------------------------------------------------------------
2
-- Title      : Off-chip data bus for same clock frequencies at different phase
3
-- Project    : 
4
-------------------------------------------------------------------------------
5
-- File       : ext_data_synch.vhd
6
-- Author     : 
7
-- Created    : 11.08.2006
8
-- Last update: 15.08.2006
9
-- Description: REQUIRES THE SAME CLOCK FREQUENCIES FROM BOTH ENDS!
10
-- Possible hazard in empty: not synchronized. maybe change it later if errors
11
-- occure.
12
-------------------------------------------------------------------------------
13
-- Copyright (c) 2006 
14
-------------------------------------------------------------------------------
15
-- Revisions  :
16
-- Date        Version  Author  Description
17
-- 11.08.2006  1.0      AK      Created
18
-------------------------------------------------------------------------------
19
 
20
library ieee;
21
use ieee.std_logic_1164.all;
22
use ieee.std_logic_arith.all;
23
use ieee.std_logic_unsigned.all;
24
 
25
entity ext_data_synch is
26
 
27
  generic (
28
    data_width_g : integer := 4;
29
    depth_g      : integer := 10        -- FIFO size & max transfer size
30
    );
31
 
32
  port (
33
    clk   : in std_logic;
34
    rst_n : in std_logic;
35
 
36
    tx_data_in  : in  std_logic_vector(data_width_g-1 downto 0);
37
    tx_empty_in : in  std_logic;
38
    tx_re_out   : out std_logic;
39
 
40
    rx_re_in     : in  std_logic;
41
    rx_data_out  : out std_logic_vector(data_width_g-1 downto 0);
42
    rx_empty_out : out std_logic;
43
 
44
    a_empty_in  : in  std_logic;
45
    a_empty_out : out std_logic;
46
    a_we_out    : out std_logic;
47
    a_we_in     : in  std_logic;
48
    a_data_out  : out std_logic_vector(data_width_g-1 downto 0);
49
    a_data_in   : in  std_logic_vector(data_width_g-1 downto 0)
50
    );
51
 
52
end ext_data_synch;
53
 
54
architecture rtl of ext_data_synch is
55
  constant stable_period_c : integer := 3;  -- stable for n clock cycles.
56
  -- works with 3 in FPGA.
57
  constant n_data_on_lines_c : integer := 10;  -- amount of data packets that may be
58
  -- travelling currently to the other side. used to approximate the rquired
59
  -- FIFO depth (depth_g+n_data_on_lines_c = fifo depth)
60
 
61
  -- tx signals
62
  signal a_we_out_r   : std_logic;
63
  signal data_cnt_r   : integer range depth_g downto 0;
64
  signal stable_cnt_r : integer range stable_period_c-1 downto 0;
65
  signal a_data_out_r : std_logic_vector(data_width_g-1 downto 0);
66
  signal a_empty_in_r : std_logic_vector(1 downto 0);
67
  --rx signals
68
  signal a_we_in_r : std_logic_vector(1 downto 0);
69
  signal read_in   : std_logic;
70
 
71
  signal rx_fifo_data_in   : std_logic_vector (data_width_g-1 downto 0);
72
  signal rx_fifo_we_in     : std_logic;
73
  signal rx_fifo_full_out  : std_logic;
74
--  signal rx_fifo_re_in     : std_logic;
75
--  signal rx_fifo_data_out  : std_logic_vector (data_width_g-1 downto 0);
76
  signal rx_fifo_empty_out : std_logic;
77
 
78
  -- receiving FIFO
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
  type   tx_states is (send, keep_stable);
97
  signal tx_ctrl_r : tx_states;
98
 
99
begin  -- rtl
100
 
101
  -- purpose: tx side of the block
102
  a_data_out <= a_data_out_r;
103
  a_we_out   <= a_we_out_r;
104
 
105
  process (clk, rst_n)
106
  begin  -- process
107
    if rst_n = '0' then                 -- asynchronous reset (active low)
108
      a_we_out_r   <= '0';
109
      data_cnt_r   <= 0;                -- could also be depth_g
110
      tx_ctrl_r    <= send;
111
      stable_cnt_r <= 0;
112
      a_data_out_r <= (others => '0');
113
      tx_re_out    <= '0';
114
      a_empty_in_r <= (others => '0');
115
 
116
    elsif clk'event and clk = '1' then  -- rising clock edge
117
      a_empty_in_r(0) <= a_empty_in;
118
      a_empty_in_r(1) <= a_empty_in_r(0);
119
      case tx_ctrl_r is
120
        when send =>
121
          if tx_empty_in = '0' and (a_empty_in_r(1) = '1' or data_cnt_r /= 0) then
122
            a_data_out_r <= tx_data_in;
123
            tx_re_out    <= '1';
124
            a_we_out_r   <= not a_we_out_r;
125
            tx_ctrl_r    <= keep_stable;
126
            stable_cnt_r <= stable_period_c-1;
127
            if a_empty_in_r(1) = '1' then
128
              data_cnt_r <= depth_g;
129
            else
130
              data_cnt_r <= data_cnt_r-1;
131
            end if;
132
 
133
          else
134
            tx_re_out <= '0';
135
          end if;
136
 
137
        when keep_stable =>
138
          a_data_out_r <= a_data_out_r;
139
          a_we_out_r   <= a_we_out_r;
140
          tx_re_out <= '0';
141
          if stable_cnt_r /= 0 then
142
            stable_cnt_r <= stable_cnt_r-1;
143
          else
144
            tx_ctrl_r    <= send;
145
            stable_cnt_r <= stable_period_c-1;
146
          end if;
147
 
148
      end case;
149
 
150
    end if;
151
  end process;
152
 
153
 
154
  read_in <= a_we_in_r(1) xor a_we_in_r(0);
155
  -- purpose: rx side of the block
156
  process (clk, rst_n)
157
  begin  -- process
158
    if rst_n = '0' then                 -- asynchronous reset (active low)
159
      a_we_in_r     <= (others => '0');
160
      rx_fifo_we_in <= '0';
161
 
162
    elsif clk'event and clk = '1' then  -- rising clock edge
163
      -- if FIFO is full, we are anyway screwed, no reason to check it...
164
      a_we_in_r(0) <= a_we_in;
165
      a_we_in_r(1) <= a_we_in_r(0);
166
      if read_in = '1' then
167
        rx_fifo_data_in <= a_data_in;
168
        rx_fifo_we_in   <= '1';
169
        assert rx_fifo_full_out = '0' report "Writing to full FIFO!!" severity error;
170
      else
171
        rx_fifo_we_in <= '0';
172
      end if;
173
    end if;
174
  end process;
175
 
176
  fifo_1 : fifo
177
    generic map (
178
      data_width_g => data_width_g,
179
      depth_g      => depth_g+n_data_on_lines_c)
180
    port map (
181
      clk   => clk,
182
      rst_n => rst_n,
183
 
184
      data_in  => rx_fifo_data_in,
185
      we_in    => rx_fifo_we_in,
186
      full_out => rx_fifo_full_out,
187
 
188
--      one_p_out => one_p_out,
189
      re_in     => rx_re_in,
190
      data_out  => rx_data_out,
191
      empty_out => rx_fifo_empty_out
192
--    one_d_out => one_d_out
193
      );
194
 
195
  rx_empty_out <= rx_fifo_empty_out;
196
  a_empty_out  <= rx_fifo_empty_out;
197
 
198
end rtl;
199
 

powered by: WebSVN 2.1.0

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