1 ----------------------------------------------------------------------------------
5 -- Create Date: 09:
04:
40 06/08/2014
7 -- Module Name: fifo66X512 - Behavioral
16 -- Revision 0.
01 -
File Created
17 -- Additional Comments:
19 ----------------------------------------------------------------------------------
21 use IEEE.STD_LOGIC_1164.
ALL;
22 use IEEE.STD_LOGIC_ARITH.
ALL;
23 use IEEE.STD_LOGIC_UNSIGNED.
ALL;
24 use IEEE.std_logic_misc.
all;
26 -- Uncomment the following library declaration if using
27 -- arithmetic functions with or values
28 --use IEEE.NUMERIC_STD.ALL;
30 -- Uncomment the following library declaration if instantiating
31 -- any Xilinx primitives in this code.
33 use UNISIM.VComponents.
all;
35 use UNIMACRO.vcomponents.
all;
38 generic (ALMOST_FULL_OFFSET : (15 downto 0) := x"0004";
39 ALMOST_EMPTY_OFFSET : (15 downto 0) := x"0004");
43 Di : in (65 downto 0);
46 Do : out (65 downto 0);
58 signal RAM_dav: := '0';
59 signal RAM_Do_vld: := '0';
60 signal Do_vld: := '0';
61 signal wa_g: (3 downto 0) := (others => '0');
62 signal wa_g_sync: (3 downto 0) := (others => '0');
63 signal wa_g_sync1: (3 downto 0) := (others => '0');
64 signal wa_g_sync2: (3 downto 0) := (others => '0');
65 signal wc_w: (N downto 0) := (others => '0');
66 signal wc_r: (N downto 0) := (others => '0');
67 signal wa: (N downto 0) := (others => '0');
68 signal wap: (N downto 0) := (others => '0');
69 signal ra_g: (3 downto 0) := (others => '0');
70 signal ra_g_sync: (3 downto 0) := (others => '0');
71 signal ra_g_sync1: (3 downto 0) := (others => '0');
72 signal ra_g_sync2: (3 downto 0) := (others => '0');
73 signal ra: (N downto 0) := (others => '0');
74 signal rap: (N downto 0) := (others => '0');
75 attribute ASYNC_REG : ;
76 attribute ASYNC_REG of wa_g_sync : signal is "TRUE";
77 attribute ASYNC_REG of wa_g_sync1 : signal is "TRUE";
78 attribute ASYNC_REG of wa_g_sync2 : signal is "TRUE";
79 attribute ASYNC_REG of ra_g_sync : signal is "TRUE";
80 attribute ASYNC_REG of ra_g_sync1 : signal is "TRUE";
81 attribute ASYNC_REG of ra_g_sync2 : signal is "TRUE";
82 attribute shreg_extract : ;
83 attribute shreg_extract of wa_g_sync : signal is "TRUE";
84 attribute shreg_extract of wa_g_sync1 : signal is "TRUE";
85 attribute shreg_extract of wa_g_sync2 : signal is "TRUE";
86 attribute shreg_extract of ra_g_sync : signal is "TRUE";
87 attribute shreg_extract of ra_g_sync1 : signal is "TRUE";
88 attribute shreg_extract of ra_g_sync2 : signal is "TRUE";
93 variable full_th: (N downto 0);
95 full_th := '0' & not ALMOST_FULL_OFFSET(N-1 downto 0);
97 wa_g <= (others => '0');
98 wa <= (others => '0');
99 ra_g_sync <= (others => '0');
100 ra_g_sync1 <= (others => '0');
101 ra_g_sync2 <= (others => '0');
102 rap <= (others => '0');
103 wc_w <= (others => '0');
106 elsif(wclk'event and wclk = '1')then
109 when x"0" => wa_g <= x"1";
110 when x"1" => wa_g <= x"3";
111 when x"3" => wa_g <= x"2";
112 when x"2" => wa_g <= x"6";
113 when x"6" => wa_g <= x"7";
114 when x"7" => wa_g <= x"5";
115 when x"5" => wa_g <= x"4";
116 when x"4" => wa_g <= x"c";
117 when x"c" => wa_g <= x"d";
118 when x"d" => wa_g <= x"f";
119 when x"f" => wa_g <= x"e";
120 when x"e" => wa_g <= x"a";
121 when x"a" => wa_g <= x"b";
122 when x"b" => wa_g <= x"9";
123 when x"9" => wa_g <= x"8";
124 when others => wa_g <= x"0";
129 ra_g_sync1 <= ra_g_sync;
130 ra_g_sync2 <= ra_g_sync1;
131 rap(3) <= ra_g_sync2(3);
132 rap(2) <= ra_g_sync2(3) xor ra_g_sync2(2);
133 rap(1) <= ra_g_sync2(3) xor ra_g_sync2(2) xor ra_g_sync2(1);
134 rap(0) <= ra_g_sync2(3) xor ra_g_sync2(2) xor ra_g_sync2(1) xor ra_g_sync2(0);
135 if(rap(3) = '1' and ra_g_sync2(3) = '0')then
136 rap(N downto 4) <= rap(N downto 4) + 1;
138 wc_w <= wa - rap + we;
139 if(wc_w >= full_th)then
144 if(wc_w(N) = '1' or (and_reduce(wc_w(N-1 downto 0)) = '1' and we = '1'))then
154 ra_g <= (others => '0');
155 ra <= (others => '0');
156 wa_g_sync <= (others => '0');
157 wa_g_sync1 <= (others => '0');
158 wa_g_sync2 <= (others => '0');
159 wap <= (others => '0');
160 wc_r <= (others => '0');
165 elsif(rclk'event and rclk = '1')then
168 when x"0" => ra_g <= x"1";
169 when x"1" => ra_g <= x"3";
170 when x"3" => ra_g <= x"2";
171 when x"2" => ra_g <= x"6";
172 when x"6" => ra_g <= x"7";
173 when x"7" => ra_g <= x"5";
174 when x"5" => ra_g <= x"4";
175 when x"4" => ra_g <= x"c";
176 when x"c" => ra_g <= x"d";
177 when x"d" => ra_g <= x"f";
178 when x"f" => ra_g <= x"e";
179 when x"e" => ra_g <= x"a";
180 when x"a" => ra_g <= x"b";
181 when x"b" => ra_g <= x"9";
182 when x"9" => ra_g <= x"8";
183 when others => ra_g <= x"0";
188 wa_g_sync1 <= wa_g_sync;
189 wa_g_sync2 <= wa_g_sync1;
190 wap(3) <= wa_g_sync2(3);
191 wap(2) <= wa_g_sync2(3) xor wa_g_sync2(2);
192 wap(1) <= wa_g_sync2(3) xor wa_g_sync2(2) xor wa_g_sync2(1);
193 wap(0) <= wa_g_sync2(3) xor wa_g_sync2(2) xor wa_g_sync2(1) xor wa_g_sync2(0);
194 if(wap(3) = '1' and wa_g_sync2(3) = '0')then
195 wap(N downto 4) <= wap(N downto 4) + 1;
198 wc_r <= wap - ra - 1;
202 if(or_reduce(wc_r(N downto 1)) = '1' or (wc_r(0) = '1' and (RAM_dav = '0' or (re = '0' and RAM_Do_vld = '1' and Do_vld = '1'))))then
207 if(RAM_dav = '1')then
209 elsif(re = '1' or Do_vld = '0')then
212 if(RAM_Do_vld = '1')then
217 if(wc_r < ALMOST_EMPTY_OFFSET(N downto 0))then
224 i_BRAM_SDP_MACRO : BRAM_SDP_MACRO
226 BRAM_SIZE =>
"36Kb",
-- Target BRAM, "18Kb" or "36Kb"
227 DEVICE =>
"VIRTEX6",
-- Target device: "VIRTEX5",
"VIRTEX6",
"SPARTAN6"
228 WRITE_WIDTH =>
66,
-- Valid values are 1-72 (37-72 only valid when BRAM_SIZE="36Kb")
229 READ_WIDTH =>
66,
-- Valid values are 1-72 (37-72 only valid when BRAM_SIZE="36Kb")
230 DO_REG =>
1,
-- Optional output register (0 or 1)
232 SIM_COLLISION_CHECK =>
"ALL",
-- Collision check enable "ALL",
"WARNING_ONLY",
233 -- "GENERATE_X_ONLY" or "NONE"
234 SRVAL => X"000000000000000000",
-- Set/Reset value for port output
235 INIT => X"000000000000000000",
-- Initial values on output port
236 WRITE_MODE =>
"WRITE_FIRST") -- Specify "READ_FIRST" for same clock
or synchronous clocks
238 DO => Do,
-- Output read data port, width defined by READ_WIDTH parameter
239 DI => Di,
-- Input write data port, width defined by WRITE_WIDTH parameter
240 RDADDR => ra
(N-
1 downto 0),
-- Input read address, width defined by read port depth
241 RDCLK => rclk,
-- 1-bit input read clock
242 RDEN => RDEN,
-- 1-bit input read port enable
243 REGCE => REGCE,
-- 1-bit input read output register enable
244 RST => '0',
-- 1-bit input reset
245 WE => x"ff",
-- Input write enable, width defined by write port depth
246 WRADDR => wa
(N-
1 downto 0),
-- Input write address, width defined by write port depth
247 WRCLK => wclk,
-- 1-bit input write clock
248 WREN => we
-- 1-bit input write port enable
250 REGCE <= '1'
when re = '1'
or Do_vld = '0'
else '0';
251 RDEN <= '1' when re = '1' or Do_vld = '0' or RAM_Do_vld = '0' else '0';
252 ce_ra <= '1' when RAM_dav = '1' and (re = '1' or Do_vld = '0' or RAM_Do_vld = '0') else '0';