Debian Codegraph @

hdl/fpga/ip/altera/common_dcfifo/common_dcfifo.vhd

raw
1 -- Copyright (c) 2017 Nuand LLC
2 --
3 -- Permission is hereby granted, free of charge, to any person obtaining a copy
4 -- of this software and associated documentation files (the "Software"), to deal
5 -- in the Software without restriction, including without limitation the rights
6 -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 -- copies of the Software, and to permit persons to whom the Software is
8 -- furnished to do so, subject to the following conditions:
9 --
10 -- The above copyright notice and this permission notice shall be included in
11 -- all copies or substantial portions of the Software.
12 --
13 -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 -- THE SOFTWARE.
20
21 library ieee;
22 use ieee.std_logic_1164.all;
23 use ieee.math_real.all;
24
25 package common_dcfifo_p is
26
27 function compute_rdusedw_high( numwords : natural;
28 width : natural;
29 width_r : natural;
30 add_usedw_msb : string
31 ) return natural;
32
33 function compute_wrusedw_high( numwords : natural;
34 add_usedw_msb : string
35 ) return natural;
36
37 end package;
38
39 package body common_dcfifo_p is
40
41 function compute_rdusedw_high( numwords : natural;
42 width : natural;
43 width_r : natural;
44 add_usedw_msb : string ) return natural is
45 variable x : real := 0.0;
46 variable y : real := 0.0;
47 variable rv : natural := 0;
48 begin
49 x := real(numwords);
50
51 if( width > width_r ) then
52 y := real(width) / real(width_r);
53 rv := integer(ceil(log2(x) + log2(y))) - 1;
54 else
55 -- Less or equal. If equal, log2(y) is 0 and the term goes away.
56 y := real(width_r) / real(width);
57 rv := integer(ceil(log2(x) - log2(y))) - 1;
58 end if;
59
60 if( add_usedw_msb = "on" or add_usedw_msb = "oN" or
61 add_usedw_msb = "On" or add_usedw_msb = "ON" ) then
62 rv := rv + 1;
63 end if;
64
65 return rv;
66 end function;
67
68 function compute_wrusedw_high( numwords : natural;
69 add_usedw_msb : string ) return natural is
70 variable rv : natural := 0;
71 begin
72 rv := integer(ceil(log2(real(numwords)))) - 1;
73
74 if( add_usedw_msb = "on" or add_usedw_msb = "oN" or
75 add_usedw_msb = "On" or add_usedw_msb = "ON" ) then
76 rv := rv + 1;
77 end if;
78
79 return rv;
80 end function;
81
82 end package body;
83
84 library ieee;
85 use ieee.std_logic_1164.all;
86
87 library altera_mf;
88 use altera_mf.altera_mf_components.all;
89
90 library work;
91 use work.common_dcfifo_p.all;
92
93 entity common_dcfifo is
94 generic (
95 ADD_RAM_OUTPUT_REGISTER : string := "OFF";
96 ADD_USEDW_MSB_BIT : string := "OFF";
97 CLOCKS_ARE_SYNCHRONIZED : string := "FALSE";
98 DELAY_RDUSEDW : natural := 1;
99 DELAY_WRUSEDW : natural := 1;
100 INTENDED_DEVICE_FAMILY : string := "UNUSED";
101 LPM_NUMWORDS : natural := 4096;
102 LPM_SHOWAHEAD : string := "ON";
103 LPM_WIDTH : natural := 32;
104 LPM_WIDTH_R : natural := 32;
105 OVERFLOW_CHECKING : string := "ON";
106 RDSYNC_DELAYPIPE : natural := 5;
107 READ_ACLR_SYNCH : string := "ON";
108 UNDERFLOW_CHECKING : string := "ON";
109 USE_EAB : string := "ON";
110 WRITE_ACLR_SYNCH : string := "ON";
111 WRSYNC_DELAYPIPE : natural := 5
112 );
113 port (
114 aclr : in std_logic := '0';
115 data : in std_logic_vector(LPM_WIDTH-1 downto 0);
116 rdclk : in std_logic;
117 rdreq : in std_logic;
118 wrclk : in std_logic;
119 wrreq : in std_logic;
120 q : out std_logic_vector(LPM_WIDTH_R-1 downto 0);
121 rdempty : out std_logic;
122 rdfull : out std_logic;
123 rdusedw : out std_logic_vector(compute_rdusedw_high(LPM_NUMWORDS,
124 LPM_WIDTH,
125 LPM_WIDTH_R,
126 ADD_USEDW_MSB_BIT) downto 0);
127 wrempty : out std_logic;
128 wrfull : out std_logic;
129 wrusedw : out std_logic_vector(compute_wrusedw_high(LPM_NUMWORDS,
130 ADD_USEDW_MSB_BIT) downto 0)
131 --eccstatus : out std_logic_vector(1 downto 0)
132 );
133 end entity;
134
135 architecture arch of common_dcfifo is
136
137 attribute ALTERA_ATTRIBUTE : string;
138
139 attribute ALTERA_ATTRIBUTE of arch : architecture is "-name SDC_STATEMENT ""set_false_path -to [get_registers {*fifo_gen:U_dcfifo_mixed_widths|dcfifo_*:auto_generated|dffpipe_*:wraclr|dffe*a[0]}] """;
140
141 function valid_width_ratio( width : natural; width_r : natural ) return boolean is
142 variable r : natural := 0;
143 variable rv : boolean := false;
144 begin
145 if( width > width_r ) then
146 r := width / width_r;
147 else
148 r := width_r / width;
149 end if;
150 case r is
151 when 1 | 2 | 4 | 8 | 16 | 32 => rv := true;
152 when others => rv := false;
153 end case;
154 return rv;
155 end function;
156
157 constant LPM_HINT : string := "UNUSED";
158 constant ENABLE_ECC : string := "FALSE";
159
160 begin
161
162 -- ------------------------------------------------------------------------
163 -- Parameter checking. Should cause synthesis to error-out in Quartus.
164 -- ------------------------------------------------------------------------
165
166 assert valid_width_ratio( LPM_WIDTH, LPM_WIDTH_R )
167 report "Invalid width ratio in mixed width DCFIFO!"
168 severity failure;
169
170 assert (LPM_NUMWORDS >= 4)
171 report "Invalid FIFO depth (" & integer'image(LPM_NUMWORDS) & "). Must be >= 4."
172 severity failure;
173
174 -- ------------------------------------------------------------------------
175 -- MIXED WIDTH DCFIFO
176 -- We could just always use a mixed width DCFIFO. It's legal to have
177 -- the same input/output port widths in this mode, but (unconfirmed)
178 -- it may use more resources (maybe?).
179 -- ------------------------------------------------------------------------
180
181 mixed_fifo_gen : if( LPM_WIDTH /= LPM_WIDTH_R ) generate
182 U_dcfifo_mixed_widths : dcfifo_mixed_widths
183 generic map (
184 ADD_RAM_OUTPUT_REGISTER => ADD_RAM_OUTPUT_REGISTER,
185 ADD_USEDW_MSB_BIT => ADD_USEDW_MSB_BIT,
186 CLOCKS_ARE_SYNCHRONIZED => CLOCKS_ARE_SYNCHRONIZED,
187 DELAY_RDUSEDW => DELAY_RDUSEDW,
188 DELAY_WRUSEDW => DELAY_WRUSEDW,
189 INTENDED_DEVICE_FAMILY => INTENDED_DEVICE_FAMILY,
190 --ENABLE_ECC => ENABLE_ECC,
191 LPM_NUMWORDS => LPM_NUMWORDS,
192 LPM_SHOWAHEAD => LPM_SHOWAHEAD,
193 LPM_WIDTH => LPM_WIDTH,
194 LPM_WIDTH_R => LPM_WIDTH_R,
195 LPM_WIDTHU => wrusedw'length,
196 LPM_WIDTHU_R => rdusedw'length,
197 OVERFLOW_CHECKING => OVERFLOW_CHECKING,
198 RDSYNC_DELAYPIPE => RDSYNC_DELAYPIPE,
199 READ_ACLR_SYNCH => READ_ACLR_SYNCH,
200 UNDERFLOW_CHECKING => UNDERFLOW_CHECKING,
201 USE_EAB => USE_EAB,
202 WRITE_ACLR_SYNCH => WRITE_ACLR_SYNCH,
203 WRSYNC_DELAYPIPE => WRSYNC_DELAYPIPE,
204 LPM_HINT => LPM_HINT,
205 LPM_TYPE => "dcfifo_mixed_widths"
206 )
207 port map (
208 aclr => aclr,
209 data => data,
210 rdclk => rdclk,
211 rdreq => rdreq,
212 wrclk => wrclk,
213 wrreq => wrreq,
214 q => q,
215 rdempty => rdempty,
216 rdfull => rdfull,
217 rdusedw => rdusedw,
218 wrempty => wrempty,
219 wrfull => wrfull,
220 wrusedw => wrusedw
221 --eccstatus => eccstatus
222 );
223 end generate;
224
225
226 -- ------------------------------------------------------------------------
227 -- DCFIFO
228 -- When read/write port widths are equal.
229 -- ------------------------------------------------------------------------
230
231 fifo_gen : if( LPM_WIDTH = LPM_WIDTH_R ) generate
232 U_dcfifo : dcfifo
233 generic map (
234 ADD_RAM_OUTPUT_REGISTER => ADD_RAM_OUTPUT_REGISTER,
235 ADD_USEDW_MSB_BIT => ADD_USEDW_MSB_BIT,
236 CLOCKS_ARE_SYNCHRONIZED => CLOCKS_ARE_SYNCHRONIZED,
237 DELAY_RDUSEDW => DELAY_RDUSEDW,
238 DELAY_WRUSEDW => DELAY_WRUSEDW,
239 INTENDED_DEVICE_FAMILY => INTENDED_DEVICE_FAMILY,
240 --ENABLE_ECC => ENABLE_ECC,
241 LPM_NUMWORDS => LPM_NUMWORDS,
242 LPM_SHOWAHEAD => LPM_SHOWAHEAD,
243 LPM_WIDTH => LPM_WIDTH,
244 LPM_WIDTHU => wrusedw'length,
245 OVERFLOW_CHECKING => OVERFLOW_CHECKING,
246 RDSYNC_DELAYPIPE => RDSYNC_DELAYPIPE,
247 READ_ACLR_SYNCH => READ_ACLR_SYNCH,
248 UNDERFLOW_CHECKING => UNDERFLOW_CHECKING,
249 USE_EAB => USE_EAB,
250 WRITE_ACLR_SYNCH => WRITE_ACLR_SYNCH,
251 WRSYNC_DELAYPIPE => WRSYNC_DELAYPIPE,
252 LPM_HINT => LPM_HINT,
253 LPM_TYPE => "dcfifo"
254 )
255 port map (
256 aclr => aclr,
257 data => data,
258 rdclk => rdclk,
259 rdreq => rdreq,
260 wrclk => wrclk,
261 wrreq => wrreq,
262 q => q,
263 rdempty => rdempty,
264 rdfull => rdfull,
265 rdusedw => rdusedw,
266 wrempty => wrempty,
267 wrfull => wrfull,
268 wrusedw => wrusedw
269 --eccstatus => eccstatus
270 );
271 end generate;
272
273 end architecture;