2016-04-11 12:01:59 -04:00
|
|
|
//#############################################################################
|
|
|
|
//# Function: Clock domain crossing FIFO #
|
|
|
|
//#############################################################################
|
|
|
|
//# Author: Andreas Olofsson #
|
|
|
|
//# License: MIT (see LICENSE file in OH! repository) #
|
|
|
|
//#############################################################################
|
2015-05-01 17:13:44 -04:00
|
|
|
|
2016-04-11 12:01:59 -04:00
|
|
|
module oh_fifo_cdc # (parameter DW = 104, //FIFO width
|
|
|
|
parameter DEPTH = 32, //FIFO depth (entries)
|
2016-06-19 17:08:46 -04:00
|
|
|
parameter TARGET = "GENERIC" //XILINX,ALTERA,GENERIC
|
2016-04-11 12:01:59 -04:00
|
|
|
)
|
|
|
|
(
|
2020-09-23 16:47:13 -04:00
|
|
|
input nreset, // async active low reset
|
|
|
|
//Write Side
|
|
|
|
input clk_in, // write clock
|
|
|
|
input valid_in, // write valid
|
|
|
|
input [DW-1:0] packet_in, // write packet
|
|
|
|
output wait_out, // write pushback
|
|
|
|
//Read Side
|
|
|
|
input clk_out, //read clock
|
|
|
|
output reg valid_out, //read valid
|
|
|
|
output [DW-1:0] packet_out, //read packet
|
|
|
|
input wait_in, // read pushback
|
|
|
|
//Status
|
|
|
|
output prog_full, // fifo is half full
|
|
|
|
output full, // fifo is full
|
|
|
|
output empty // fifo is empty
|
2016-04-11 12:01:59 -04:00
|
|
|
);
|
2016-03-21 11:18:07 -04:00
|
|
|
|
2016-08-25 11:42:31 -04:00
|
|
|
// local wires
|
2016-06-19 17:08:46 -04:00
|
|
|
wire wr_en;
|
|
|
|
wire rd_en;
|
2016-08-25 11:42:31 -04:00
|
|
|
|
|
|
|
// parametric async fifo
|
2016-03-21 11:18:07 -04:00
|
|
|
oh_fifo_async #(.TARGET(TARGET),
|
|
|
|
.DW(DW),
|
2016-04-11 12:01:59 -04:00
|
|
|
.DEPTH(DEPTH))
|
2016-01-19 13:28:47 -05:00
|
|
|
fifo (.prog_full (prog_full),
|
|
|
|
.full (full),
|
2016-01-20 10:51:57 -05:00
|
|
|
.rd_count (),
|
2016-01-19 13:28:47 -05:00
|
|
|
.nreset (nreset),
|
|
|
|
.dout (packet_out[DW-1:0]),
|
|
|
|
.empty (empty),
|
|
|
|
.wr_clk (clk_in),
|
|
|
|
.rd_clk (clk_out),
|
|
|
|
.wr_en (wr_en),
|
|
|
|
.din (packet_in[DW-1:0]),
|
2016-04-11 12:01:59 -04:00
|
|
|
.rd_en (rd_en));
|
2016-08-25 11:42:31 -04:00
|
|
|
|
|
|
|
// FIFO control logic
|
2020-09-23 16:47:13 -04:00
|
|
|
assign wr_en = valid_in;
|
2016-08-25 11:42:31 -04:00
|
|
|
assign rd_en = ~empty & ~wait_in;
|
2020-09-23 16:47:13 -04:00
|
|
|
assign wait_out = prog_full;
|
2016-08-25 11:42:31 -04:00
|
|
|
|
2020-09-23 16:47:13 -04:00
|
|
|
|
|
|
|
//async asser, sync deassert of reset
|
|
|
|
oh_rsync sync_reset(.nrst_out (nreset_out),
|
|
|
|
.clk (clk_out),
|
|
|
|
.nrst_in (nreset));
|
2016-08-25 11:42:31 -04:00
|
|
|
|
2020-09-23 16:47:13 -04:00
|
|
|
//align valid signal with FIFO read delay
|
|
|
|
always @ (posedge clk_out or negedge nreset_out)
|
|
|
|
if(!nreset_out)
|
|
|
|
valid_out <= 1'b0;
|
|
|
|
else if(~wait_in)
|
|
|
|
valid_out <= rd_en;
|
2016-01-19 13:28:47 -05:00
|
|
|
|
2016-04-11 12:01:59 -04:00
|
|
|
endmodule // oh_fifo_cdc
|
|
|
|
|