URL
https://opencores.org/ocsvn/yifive/yifive/trunk
Subversion Repositories yifive
[/] [yifive/] [trunk/] [caravel_yifive/] [verilog/] [rtl/] [lib/] [sync_fifo.sv] - Rev 23
Go to most recent revision | Compare with Previous | Blame | View Log
/*********************************************************************This file is part of the sdram controller projecthttp://www.opencores.org/cores/sdr_ctrl/Description: SYNC FIFOParameters:W : Width (integer)D : Depth (integer, power of 2, 4 to 256)To Do:nothingAuthor(s): Dinesh Annayya, dinesha@opencores.orgCopyright (C) 2000 Authors and OPENCORES.ORGThis source file may be used and distributed withoutrestriction provided that this copyright statement is notremoved from the file and that any derivative work containsthe original copyright notice and the associated disclaimer.This source file is free software; you can redistribute itand/or modify it under the terms of the GNU Lesser GeneralPublic License as published by the Free Software Foundation;either version 2.1 of the License, or (at your option) anylater version.This source is distributed in the hope that it will beuseful, but WITHOUT ANY WARRANTY; without even the impliedwarranty of MERCHANTABILITY or FITNESS FOR A PARTICULARPURPOSE. See the GNU Lesser General Public License for moredetails.You should have received a copy of the GNU Lesser GeneralPublic License along with this source; if not, download itfrom http://www.opencores.org/lgpl.shtml*******************************************************************/module sync_fifo (clk,reset_n,wr_en,wr_data,full,empty,rd_en,rd_data);parameter W = 8;parameter D = 4;parameter AW = (D == 2) ? 1 :(D == 4) ? 2 :(D == 8) ? 3 :(D == 16) ? 4 :(D == 32) ? 5 :(D == 64) ? 6 :(D == 128) ? 7 :(D == 256) ? 8 : 0;output [W-1 : 0] rd_data;input [W-1 : 0] wr_data;input clk, reset_n, wr_en, rd_en;output full, empty;// synopsys translate_offinitial beginif (AW == 0) begin$display ("%m : ERROR!!! Fifo depth %d not in range 4 to 256", D);end // if (AW == 0)end // initial begin// synopsys translate_onreg [W-1 : 0] mem[D-1 : 0];reg [AW-1 : 0] rd_ptr, wr_ptr;reg full, empty;wire [W-1 : 0] rd_data;always @ (posedge clk or negedge reset_n)if (reset_n == 1'b0) beginwr_ptr <= {AW{1'b0}} ;endelse beginif (wr_en & !full) beginwr_ptr <= wr_ptr + 1'b1 ;endendalways @ (posedge clk or negedge reset_n)if (reset_n == 1'b0) beginrd_ptr <= {AW{1'b0}} ;endelse beginif (rd_en & !empty) beginrd_ptr <= rd_ptr + 1'b1 ;endendalways @ (posedge clk or negedge reset_n)if (reset_n == 1'b0) beginempty <= 1'b1 ;endelse beginempty <= (((wr_ptr - rd_ptr) == {{(AW-1){1'b0}}, 1'b1}) & rd_en & ~wr_en) ? 1'b1 :((wr_ptr == rd_ptr) & ~rd_en & wr_en) ? 1'b0 : empty ;endalways @ (posedge clk or negedge reset_n)if (reset_n == 1'b0) beginfull <= 1'b0 ;endelse beginfull <= (((wr_ptr - rd_ptr) == {{(AW-1){1'b1}}, 1'b0}) & ~rd_en & wr_en) ? 1'b1 :(((wr_ptr - rd_ptr) == {AW{1'b1}}) & rd_en & ~wr_en) ? 1'b0 : full ;endalways @ (posedge clk)if (wr_en)mem[wr_ptr] <= wr_data;assign rd_data = mem[rd_ptr];// synopsys translate_offalways @(posedge clk) beginif (wr_en && full) begin$display("%m : Error! sfifo overflow!");endendalways @(posedge clk) beginif (rd_en && empty) begin$display("%m : error! sfifo underflow!");endend// synopsys translate_on//---------------------------------------endmodule
Go to most recent revision | Compare with Previous | Blame | View Log
