Re: asynchronous FIFO design
The code you have provided will use LUT RAMs when targeting Xilinx
architectures as the asynchronous read does not allow BlockRAM
inference. If you desire BlockRAM, you should change the reading of the
memory array to be synchronous (including synchronous reset if desired
although for the depth you are using though (32-bits) LUT RAMs are
probably not necessarily a bad thing. At first glance, I see one issue
with your code. You have within an always block with a reset the
writing to the RAM. If you do not separate out this code into an always
block without a reset, you could have synthesis - simulation mismatch.
I suggest changing the following:
always @(negedge vd_rst_n or posedge clk_vd)
begin
if(~vd_rst_n) begin
wptr <=5'b0;
end else begin
if(datain_en) begin
mem[wptr] <= datain;
wptr <= wptr + 1;
end
end
end
To:
always @(negedge vd_rst_n or posedge clk_vd)
if(~vd_rst_n) begin
wptr <=5'b0;
else if (datain_en)
wptr <= wptr + 1;
always @(posedge clk_vd)
if(datain_en) begin
mem[wptr] <= datain;
There are other things that can be done to make this slightly more
efficient as well. If you get rid of the reset on any shift register
code like this:
always @(negedge cp_rst_n or posedge clk_cp)
begin
if(~cp_rst_n) begin
pkt_end_cp <= 4'b0;
end else begin
pkt_end_cp <= { pkt_end_cp[2:0], pkt_end};
end
end
To:
always @(posedge clk_cp)
pkt_end_cp <= { pkt_end_cp[2:0], pkt_end};
You would have opportunities to infer SRLs and thus save some resources.
In this particular case, it would not be a big difference but in
others it may make a bigger difference. There are also cases where
changing to a synchronous reset from an asynchronous reset can also
improve area and performance. For this piece of code, again, probably
would not see much but is still a good general suggestion. I would
suggest though to keep the reset asynchronous for the boundary crossing
logic since that should probably be considered asynchronous any ways.
-- Brian
kelvins wrote:
> As I have a problem in asynchronous FIFO design.
> My case is described as below,
>
> I want to design a FIFO as write in clock VD domain, and read in clock
> CP domain.
> And there is a signal (VD domain) informs 32-bytes is completed write
> to FIFO, then
> can be read out in clock CP domain, and guarantee there is not any data
> coming in
> the read out phase.
>
> The RTL code is below, It's passed in simulation phase. My problem is
> can it
> pass the synthesis phase? Will it have any issue? Thanks.
>
<Snip>
|