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