Professional Documents
Culture Documents
Async Fifo
Async Fifo
***********************************************************************************
**
// Author : Inc
// DoR : June 2021
// module name : Dual clock Asynchronous FIFO
// RH : v1
// Remarks :
//
//
***********************************************************************************
***
`timescale 1 ns/ 1 ps
`include "dc_dpram.v"
// write port
input wire wr_clk ,
input wire fifo_wr_en ,
input wire [FIFO_WIDTH-1:0] fifo_wr_data,
output reg fifo_full ,
//read port
input wire rd_clk ,
input wire fifo_rd_en ,
output wire [FIFO_WIDTH-1:0] fifo_rd_data,
output reg fifo_empty );
reg async_rst_n1_wr;
reg async_rst_n2_wr;
wire async_rst_n_wr;
reg async_rst_n1_rd;
reg async_rst_n2_rd;
wire async_rst_n_rd;
wire wr_en;
reg fifo_full_nxt;
wire rd_en;
reg fifo_empty_nxt;
// wr port logic
//async reset sync logic in wr clk domain
always @ (posedge wr_clk) begin
async_rst_n1_wr <= async_rst_n;
async_rst_n2_wr <= async_rst_n1_wr;
end
integer i;
// gray to binary
always @(*) begin
for (i=0;i <= $clog2(FIFO_DEPTH);i=i+1) begin
rd_ptr_wr_bin[i] = ^(rd_ptr_wr >> i);
end
end
always @ (*) begin
fifo_full_nxt = 1'b0;
if (({~wr_ptr_nxt[$clog2(FIFO_DEPTH)],wr_ptr_nxt[$clog2(FIFO_DEPTH)-1:0]} ==
rd_ptr_wr_bin) && (wr_en==1'b1)) begin
fifo_full_nxt = 1'b1;
end
else if ({~wr_ptr[$clog2(FIFO_DEPTH)],wr_ptr[$clog2(FIFO_DEPTH)-1:0]} ==
rd_ptr_wr_bin) begin
fifo_full_nxt = 1'b1;
end
end
integer j;
// gray to binary
always @(*) begin
for (j=0; j <= $clog2(FIFO_DEPTH);j=j+1) begin
wr_ptr_rd_bin[j] = ^(wr_ptr_rd >> j);
end
end
// dcdpram instantiation
dc_dpram # (.WIDTH (FIFO_WIDTH), .DEPTH(FIFO_DEPTH)) DC_DPRAM_U1 (
.wr_clk (wr_clk ),
.wr_en (wr_en ),
.wr_addr (wr_addr ),
.wr_data (fifo_wr_data ),
.rd_clk (rd_clk ),
.rd_en (rd_en ),
.rd_addr (rd_addr ),
.rd_data (fifo_rd_data )
);
endmodule