| 1 |
2 |
kdv |
/*
|
| 2 |
|
|
* xilinx_fifo_sc.v
|
| 3 |
|
|
*
|
| 4 |
|
|
* Copyright (c) 2007 Koen De Vleeschauwer.
|
| 5 |
|
|
*
|
| 6 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
| 7 |
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 8 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 9 |
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
| 10 |
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 11 |
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
| 12 |
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
| 13 |
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
| 14 |
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
| 15 |
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
| 16 |
|
|
* SUCH DAMAGE.
|
| 17 |
|
|
*/
|
| 18 |
|
|
|
| 19 |
|
|
/*
|
| 20 |
|
|
* fifo with common clock for read and write port.
|
| 21 |
|
|
*/
|
| 22 |
|
|
|
| 23 |
|
|
`include "timescale.v"
|
| 24 |
|
|
|
| 25 |
|
|
module xilinx_fifo_sc (
|
| 26 |
|
|
clk,
|
| 27 |
|
|
rst,
|
| 28 |
|
|
din,
|
| 29 |
|
|
wr_en,
|
| 30 |
|
|
full,
|
| 31 |
|
|
wr_ack,
|
| 32 |
|
|
overflow,
|
| 33 |
|
|
prog_full,
|
| 34 |
|
|
dout,
|
| 35 |
|
|
rd_en,
|
| 36 |
|
|
empty,
|
| 37 |
|
|
valid,
|
| 38 |
|
|
underflow,
|
| 39 |
|
|
prog_empty
|
| 40 |
|
|
);
|
| 41 |
|
|
|
| 42 |
|
|
parameter [8:0]dta_width=9'd8; /* Data bus width */
|
| 43 |
|
|
parameter [8:0]addr_width=9'd8; /* Address bus width, determines fifo size by evaluating 2^addr_width */
|
| 44 |
|
|
parameter [8:0]prog_thresh=9'd1; /* Programmable threshold constant for prog_empty and prog_full */
|
| 45 |
|
|
|
| 46 |
|
|
input clk;
|
| 47 |
|
|
input rst; /* low active sync master reset */
|
| 48 |
|
|
/* read port */
|
| 49 |
|
|
output [dta_width-1:0]dout; /* data output */
|
| 50 |
|
|
input rd_en; /* read enable */
|
| 51 |
|
|
output empty; /* asserted if fifo is empty; no additional reads can be performed */
|
| 52 |
|
|
output valid; /* valid (read acknowledge): indicates rd_en was asserted during previous clock cycle and data was succesfully read from fifo and placed on dout */
|
| 53 |
|
|
output underflow; /* underflow (read error): indicates rd_en was asserted during previous clock cycle but no data was read from fifo because fifo was empty */
|
| 54 |
|
|
output prog_empty; /* indicates the fifo has prog_thresh entries, or less. threshold for asserting prog_empty is prog_thresh */
|
| 55 |
|
|
/* write port */
|
| 56 |
|
|
input [dta_width-1:0]din; /* data input */
|
| 57 |
|
|
input wr_en; /* write enable */
|
| 58 |
|
|
output full; /* asserted if fifo is full; no additional writes can be performed */
|
| 59 |
|
|
output overflow; /* overflow (write error): indicates wr_en was asserted during previous clock cycle but no data was written to fifo because fifo was full */
|
| 60 |
|
|
output wr_ack; /* write acknowledge: indicates wr_en was asserted during previous clock cycle and data was succesfully written to fifo */
|
| 61 |
|
|
output prog_full; /* indicates the fifo has prog_thresh free entries, or less, left. threshold for asserting prog_full is 2^addr_width - prog_thresh */
|
| 62 |
|
|
|
| 63 |
|
|
/* Writing when the fifo is full, or reading while the fifo is empty, does not destroy the contents of the fifo. */
|
| 64 |
|
|
|
| 65 |
|
|
xilinx_fifo #(
|
| 66 |
|
|
.ALMOST_FULL_OFFSET(prog_thresh),
|
| 67 |
|
|
.ALMOST_EMPTY_OFFSET(prog_thresh),
|
| 68 |
|
|
.DATA_WIDTH(dta_width),
|
| 69 |
|
|
.ADDR_WIDTH(addr_width),
|
| 70 |
|
|
.DO_REG(0),
|
| 71 |
|
|
.EN_SYN("TRUE")
|
| 72 |
|
|
)
|
| 73 |
|
|
xilinx_fifo_sc (
|
| 74 |
|
|
.ALMOSTEMPTY(prog_empty),
|
| 75 |
|
|
.ALMOSTFULL(prog_full),
|
| 76 |
|
|
.DO(dout),
|
| 77 |
|
|
.EMPTY(empty),
|
| 78 |
|
|
.FULL(full),
|
| 79 |
|
|
.RDERR(underflow),
|
| 80 |
|
|
.VALID(valid),
|
| 81 |
|
|
.WRERR(overflow),
|
| 82 |
|
|
.WR_ACK(wr_ack),
|
| 83 |
|
|
.DI(din),
|
| 84 |
|
|
.RDCLK(clk),
|
| 85 |
|
|
.RDEN(rd_en),
|
| 86 |
|
|
.RST(rst),
|
| 87 |
|
|
.WRCLK(clk),
|
| 88 |
|
|
.WREN(wr_en)
|
| 89 |
|
|
);
|
| 90 |
|
|
|
| 91 |
|
|
`ifdef CHECK_GENERATE
|
| 92 |
|
|
initial
|
| 93 |
|
|
$display("%m: fifo parameters: dta_width=%0d addr_width=%0d prog_thresh=%0d", dta_width, addr_width, prog_thresh);
|
| 94 |
|
|
`endif
|
| 95 |
|
|
|
| 96 |
|
|
endmodule
|
| 97 |
|
|
/* not truncated */
|