1 |
2 |
danv |
-------------------------------------------------------------------------------
|
2 |
|
|
--
|
3 |
|
|
-- Copyright (C) 2009
|
4 |
|
|
-- ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
|
5 |
|
|
-- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
|
6 |
|
|
--
|
7 |
|
|
-- This program is free software: you can redistribute it and/or modify
|
8 |
|
|
-- it under the terms of the GNU General Public License as published by
|
9 |
|
|
-- the Free Software Foundation, either version 3 of the License, or
|
10 |
|
|
-- (at your option) any later version.
|
11 |
|
|
--
|
12 |
|
|
-- This program is distributed in the hope that it will be useful,
|
13 |
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
|
|
-- GNU General Public License for more details.
|
16 |
|
|
--
|
17 |
|
|
-- You should have received a copy of the GNU General Public License
|
18 |
|
|
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19 |
|
|
--
|
20 |
|
|
-------------------------------------------------------------------------------
|
21 |
|
|
|
22 |
|
|
-- Purpose: Dual clock FIFO
|
23 |
|
|
|
24 |
|
|
LIBRARY IEEE, common_pkg_lib, common_components_lib, technology_lib, tech_fifo_lib;
|
25 |
|
|
USE IEEE.STD_LOGIC_1164.ALL;
|
26 |
|
|
USE common_pkg_lib.common_pkg.ALL;
|
27 |
|
|
USE technology_lib.technology_select_pkg.ALL;
|
28 |
|
|
|
29 |
|
|
ENTITY common_fifo_dc IS
|
30 |
|
|
GENERIC (
|
31 |
|
|
g_technology : NATURAL := c_tech_select_default;
|
32 |
|
|
g_note_is_ful : BOOLEAN := TRUE; -- when TRUE report NOTE when FIFO goes full, fifo overflow is always reported as FAILURE
|
33 |
|
|
g_fail_rd_emp : BOOLEAN := FALSE; -- when TRUE report FAILURE when read from an empty FIFO
|
34 |
|
|
g_dat_w : NATURAL := 36;
|
35 |
|
|
g_nof_words : NATURAL := 256 -- 36 * 256 = 1 M9K
|
36 |
|
|
);
|
37 |
|
|
PORT (
|
38 |
|
|
rst : IN STD_LOGIC;
|
39 |
|
|
wr_clk : IN STD_LOGIC;
|
40 |
|
|
wr_dat : IN STD_LOGIC_VECTOR(g_dat_w-1 DOWNTO 0);
|
41 |
|
|
wr_req : IN STD_LOGIC;
|
42 |
|
|
wr_ful : OUT STD_LOGIC;
|
43 |
|
|
wrusedw : OUT STD_LOGIC_VECTOR(ceil_log2(g_nof_words)-1 DOWNTO 0);
|
44 |
|
|
rd_clk : IN STD_LOGIC;
|
45 |
|
|
rd_dat : OUT STD_LOGIC_VECTOR(g_dat_w-1 DOWNTO 0);
|
46 |
|
|
rd_req : IN STD_LOGIC;
|
47 |
|
|
rd_emp : OUT STD_LOGIC;
|
48 |
|
|
rdusedw : OUT STD_LOGIC_VECTOR(ceil_log2(g_nof_words)-1 DOWNTO 0);
|
49 |
|
|
rd_val : OUT STD_LOGIC := '0'
|
50 |
|
|
);
|
51 |
|
|
END common_fifo_dc;
|
52 |
|
|
|
53 |
|
|
|
54 |
|
|
ARCHITECTURE str of common_fifo_dc IS
|
55 |
|
|
|
56 |
|
|
CONSTANT c_nof_words : NATURAL := 2**ceil_log2(g_nof_words); -- ensure size is power of 2 for dual clock FIFO
|
57 |
|
|
|
58 |
|
|
SIGNAL wr_rst : STD_LOGIC;
|
59 |
|
|
SIGNAL wr_init : STD_LOGIC;
|
60 |
|
|
SIGNAL wr_en : STD_LOGIC;
|
61 |
|
|
SIGNAL rd_en : STD_LOGIC;
|
62 |
|
|
SIGNAL ful : STD_LOGIC;
|
63 |
|
|
SIGNAL emp : STD_LOGIC;
|
64 |
|
|
|
65 |
|
|
SIGNAL nxt_rd_val : STD_LOGIC;
|
66 |
|
|
|
67 |
|
|
BEGIN
|
68 |
|
|
|
69 |
|
|
-- Control logic copied from LOFAR common_fifo_dc(virtex4).vhd
|
70 |
|
|
|
71 |
|
|
-- Need to make sure the reset lasts at least 3 cycles (see fifo_generator_ug175.pdf)
|
72 |
|
|
-- Wait at least 4 cycles after reset release before allowing FIFO wr_en (see fifo_generator_ug175.pdf)
|
73 |
|
|
|
74 |
|
|
-- Use common_areset to:
|
75 |
|
|
-- . asynchronously detect rst even when the wr_clk is stopped
|
76 |
|
|
-- . synchronize release of rst to wr_clk domain
|
77 |
|
|
-- Using common_areset is equivalent to using common_async with same signal applied to rst and din.
|
78 |
|
|
u_wr_rst : ENTITY common_components_lib.common_areset
|
79 |
|
|
GENERIC MAP (
|
80 |
|
|
g_rst_level => '1',
|
81 |
|
|
g_delay_len => 3
|
82 |
|
|
)
|
83 |
|
|
PORT MAP (
|
84 |
|
|
in_rst => rst,
|
85 |
|
|
clk => wr_clk,
|
86 |
|
|
out_rst => wr_rst
|
87 |
|
|
);
|
88 |
|
|
|
89 |
|
|
-- Delay wr_init to ensure that FIFO ful has gone low after reset release
|
90 |
|
|
u_wr_init : ENTITY common_components_lib.common_areset
|
91 |
|
|
GENERIC MAP (
|
92 |
|
|
g_rst_level => '1',
|
93 |
|
|
g_delay_len => 4
|
94 |
|
|
)
|
95 |
|
|
PORT MAP (
|
96 |
|
|
in_rst => wr_rst,
|
97 |
|
|
clk => wr_clk,
|
98 |
|
|
out_rst => wr_init -- assume init has finished g_delay_len cycles after release of wr_rst
|
99 |
|
|
);
|
100 |
|
|
|
101 |
|
|
-- The FIFO under read and over write protection are kept enabled in the MegaWizard
|
102 |
|
|
wr_en <= wr_req AND NOT wr_init; -- check on NOT ful is not necessary when overflow_checking="ON" (Altera) or according to fifo_generator_ug175.pdf (Xilinx)
|
103 |
|
|
rd_en <= rd_req; -- check on NOT emp is not necessary when underflow_checking="ON" (Altera)
|
104 |
|
|
|
105 |
|
|
nxt_rd_val <= rd_req AND NOT emp; -- check on NOT emp is necessary for rd_val
|
106 |
|
|
|
107 |
|
|
wr_ful <= ful WHEN wr_init='0' ELSE '0';
|
108 |
|
|
|
109 |
|
|
rd_emp <= emp;
|
110 |
|
|
|
111 |
|
|
p_rd_clk : PROCESS(rd_clk)
|
112 |
|
|
BEGIN
|
113 |
|
|
IF rising_edge(rd_clk) THEN
|
114 |
|
|
rd_val <= nxt_rd_val;
|
115 |
|
|
END IF;
|
116 |
|
|
END PROCESS;
|
117 |
|
|
|
118 |
|
|
u_fifo : ENTITY tech_fifo_lib.tech_fifo_dc
|
119 |
|
|
GENERIC MAP (
|
120 |
|
|
g_technology => g_technology,
|
121 |
|
|
g_dat_w => g_dat_w,
|
122 |
|
|
g_nof_words => c_nof_words
|
123 |
|
|
)
|
124 |
|
|
PORT MAP (
|
125 |
|
|
aclr => wr_rst, -- MegaWizard fifo_dc seems to use aclr synchronous with wr_clk
|
126 |
|
|
data => wr_dat,
|
127 |
|
|
rdclk => rd_clk,
|
128 |
|
|
rdreq => rd_en,
|
129 |
|
|
wrclk => wr_clk,
|
130 |
|
|
wrreq => wr_en,
|
131 |
|
|
q => rd_dat,
|
132 |
|
|
rdempty => emp,
|
133 |
|
|
rdusedw => rdusedw,
|
134 |
|
|
wrfull => ful,
|
135 |
|
|
wrusedw => wrusedw
|
136 |
|
|
);
|
137 |
|
|
|
138 |
|
|
proc_common_fifo_asserts("common_fifo_dc", g_note_is_ful, g_fail_rd_emp, wr_rst, wr_clk, ful, wr_en, rd_clk, emp, rd_en);
|
139 |
|
|
|
140 |
|
|
END str;
|