1
0
mirror of https://github.com/aolofsson/oh.git synced 2025-01-17 20:02:53 +08:00
oh/common/hdl/oh_fifo_sync.v

97 lines
2.4 KiB
Coq
Raw Normal View History

2015-12-08 21:10:17 -05:00
module oh_fifo_sync (/*AUTOARG*/
// Outputs
dout, empty, full, almost_full, count,
2015-12-08 21:10:17 -05:00
// Inputs
clk, nreset, din, wr_en, rd_en
);
//#####################################################################
//# PARAMETERS
//#####################################################################
parameter DEPTH = 4;
parameter DW = 104;
parameter ALMOST_FULL = DEPTH-1;
2015-01-28 13:53:09 -05:00
2015-12-08 21:10:17 -05:00
localparam AW = $clog2(DEPTH);
//#####################################################################
//# INTERFACE
//#####################################################################
2015-12-08 21:10:17 -05:00
//clk/reset
input clk;
input nreset;
//write port
input [DW-1:0] din;
input wr_en;
//Read port
input rd_en;
output [DW-1:0] dout;
//Status
output empty;
output full;
output almost_full;
output [AW:0] count;
2015-12-08 21:10:17 -05:00
//#####################################################################
//# BODY
//#####################################################################
2015-12-08 21:10:17 -05:00
reg [AW-1:0] wr_addr;
reg [AW-1:0] rd_addr;
reg [AW:0] count;
assign empty = (count[AW:0]==0);
assign almost_full = (count[AW:0] >=ALMOST_FULL);
assign full = (count==DEPTH);
always @ ( posedge clk or negedge nreset)
if(!nreset)
begin
wr_addr[AW-1:0] <= 'd0;
rd_addr[AW-1:0] <= 'b0;
count[AW:0] <= 'b0;
2015-12-08 21:10:17 -05:00
end
else if(wr_en & rd_en)
begin
wr_addr[AW-1:0] <= wr_addr[AW-1:0] + 'd1;
rd_addr[AW-1:0] <= rd_addr[AW-1:0] + 'd1;
2015-12-08 21:10:17 -05:00
end
else if(wr_en)
begin
wr_addr[AW-1:0] <= wr_addr[AW-1:0] + 'd1;
count[AW:0] <= count[AW:0] + 'd1;
2015-12-08 21:10:17 -05:00
end
else if(rd_en)
begin
rd_addr[AW-1:0] <= rd_addr[AW-1:0] + 'd1;
count[AW:0] <= count[AW:0] - 'd1;
2015-12-08 21:10:17 -05:00
end
// GENERIC DUAL PORTED MEMORY
2015-04-18 16:11:21 -04:00
defparam mem.DW=DW;
defparam mem.AW=AW;
oh_memory_dp
#(.DW(DW),
.AW(AW))
mem (
2015-04-18 16:11:21 -04:00
// Outputs
2015-12-08 21:10:17 -05:00
.rd_data (dout[DW-1:0]),
2015-04-18 16:11:21 -04:00
// Inputs
.wr_clk (clk),
.wr_en ({(DW/8){wr_en}}),
2015-04-18 16:11:21 -04:00
.wr_addr (wr_addr[AW-1:0]),
2015-12-08 21:10:17 -05:00
.wr_data (din[DW-1:0]),
2015-04-19 21:54:22 -04:00
.rd_clk (clk),
2015-04-18 16:11:21 -04:00
.rd_en (rd_en),
.rd_addr (rd_addr[AW-1:0]));
endmodule // fifo_sync
2015-04-18 16:11:21 -04:00
// Local Variables:
// verilog-library-directories:(".")
// End: