/*
|
/*
|
* Simply RISC PCX FIFO
|
* PCX FIFO
|
*
|
*
|
* (C) Copyleft 2007 Simply RISC LLP
|
* (C) Copyleft 2007 Fabrizio Fazzino
|
* AUTHOR: Fabrizio Fazzino <fabrizio.fazzino@srisc.com>
|
|
*
|
*
|
* LICENSE:
|
* LICENSE:
|
* This is a Free Hardware Design; you can redistribute it and/or
|
* This is a Free Hardware Design; you can redistribute it and/or
|
* modify it under the terms of the GNU General Public License
|
* modify it under the terms of the GNU General Public License
|
* version 2 as published by the Free Software Foundation.
|
* version 2 as published by the Free Software Foundation.
|
* The above named program is distributed in the hope that it will
|
* The above named program is distributed in the hope that it will
|
* be useful, but WITHOUT ANY WARRANTY; without even the implied
|
* be useful, but WITHOUT ANY WARRANTY; without even the implied
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
* See the GNU General Public License for more details.
|
* See the GNU General Public License for more details.
|
*
|
*
|
* DESCRIPTION:
|
* DESCRIPTION:
|
* Replica of the 'pcx_fifo' module used by Dmitry for his advanced
|
* Replica of the 'pcx_fifo' module used by Dmitry for his advanced
|
* bridge, the original one was from an Altera SCFIFO Megafunction.
|
* bridge, the original one was from an Altera SCFIFO Megafunction.
|
*/
|
*/
|
|
|
`timescale 1ns/100ps
|
`timescale 1ns/100ps
|
|
|
`define PCX_FIFO_DATA_WIDTH 130
|
`define PCX_FIFO_DATA_WIDTH 130
|
|
|
module pcx_fifo(
|
module pcx_fifo(
|
// System
|
// System
|
input aclr, // Async Clear (resets the FIFO to empty)
|
input aclr, // Async Clear (resets the FIFO to empty)
|
input clock, // Clock
|
input clock, // Clock
|
|
|
// FIFO
|
// FIFO
|
input rdreq, // Read Request (when not empty)
|
input rdreq, // Read Request (when not empty)
|
input wrreq, // Write Request (when not full)
|
input wrreq, // Write Request (when not full)
|
input [(`PCX_FIFO_DATA_WIDTH-1):0] data, // Data Input
|
input [(`PCX_FIFO_DATA_WIDTH-1):0] data, // Data Input
|
output empty, // FIFO is empty
|
output empty, // FIFO is empty
|
output full, // FIFO is full
|
output full, // FIFO is full
|
output reg [(`PCX_FIFO_DATA_WIDTH-1):0] q // Data Output (oldest data when Read Request)
|
output reg [(`PCX_FIFO_DATA_WIDTH-1):0] q // Data Output (oldest data when Read Request)
|
);
|
);
|
|
|
// Local Params TODO CHECKME
|
// Local Params TODO CHECKME
|
localparam fifo_depth = 32; // TODO Dmitry says this should be enough, put an assertion to detect overflow
|
localparam fifo_depth = 32; // TODO Dmitry says this should be enough, put an assertion to detect overflow
|
localparam pointer_width = 6; // 5 bits to address 32 elements + 1 to detect wrapping
|
localparam pointer_width = 6; // 5 bits to address 32 elements + 1 to detect wrapping
|
|
|
// Read/Write Pointers
|
// Read/Write Pointers
|
logic [(pointer_width-1):0] rd_ptr;
|
logic [(pointer_width-1):0] rd_ptr;
|
logic [(pointer_width-1):0] wr_ptr;
|
logic [(pointer_width-1):0] wr_ptr;
|
|
|
// Memory Array
|
// Memory Array
|
logic [(`PCX_FIFO_DATA_WIDTH-1):0] mem[fifo_depth];
|
logic [(`PCX_FIFO_DATA_WIDTH-1):0] mem[fifo_depth];
|
|
|
`ifdef SIMPLY_RISC_DEBUG
|
`ifdef SIMPLY_RISC_DEBUG
|
// For debugging
|
// For debugging
|
logic printed_once = 0;
|
logic printed_once = 0;
|
`endif
|
`endif
|
|
|
// One-process style for reset/read/write
|
// One-process style for reset/read/write
|
always @(posedge clock) begin
|
always @(posedge clock) begin
|
// Reset
|
// Reset
|
if (aclr) begin
|
if (aclr) begin
|
`ifdef SIMPLY_RISC_DEBUG
|
`ifdef SIMPLY_RISC_DEBUG
|
if (!printed_once) begin
|
if (!printed_once) begin
|
$display("PCX FIFO Asynchronous Clear");
|
$display("PCX FIFO Asynchronous Clear");
|
printed_once = 1;
|
printed_once = 1;
|
end
|
end
|
`endif
|
`endif
|
rd_ptr = {pointer_width{1'b0}};
|
rd_ptr = {pointer_width{1'b0}};
|
wr_ptr = {pointer_width{1'b0}};
|
wr_ptr = {pointer_width{1'b0}};
|
end else begin
|
end else begin
|
// Read
|
// Read
|
if (rdreq) begin
|
if (rdreq) begin
|
`ifdef SIMPLY_RISC_DEBUG
|
`ifdef SIMPLY_RISC_DEBUG
|
if (empty) $fatal(1, "*** ERROR *** Attempt to read PCX FIFO whilst empty");
|
if (empty) $fatal(1, "*** ERROR *** Attempt to read PCX FIFO whilst empty");
|
$display("PCX FIFO Read Request: rd_ptr=%0d, data=0x%032X", rd_ptr, mem[rd_ptr]);
|
$display("PCX FIFO Read Request: rd_ptr=%0d, data=0x%032X", rd_ptr, mem[rd_ptr]);
|
`endif
|
`endif
|
q <= mem[rd_ptr];
|
q <= mem[rd_ptr];
|
rd_ptr <= rd_ptr + 1;
|
rd_ptr <= rd_ptr + 1;
|
end
|
end
|
// Write
|
// Write
|
if (wrreq) begin
|
if (wrreq) begin
|
`ifdef SIMPLY_RISC_DEBUG
|
`ifdef SIMPLY_RISC_DEBUG
|
if (full) $fatal(1, "*** ERROR *** Attempt to write PCX FIFO whilst full");
|
if (full) $fatal(1, "*** ERROR *** Attempt to write PCX FIFO whilst full");
|
$display("PCX FIFO Write Request: wr_ptr=%0d, data=0x%032X", wr_ptr, data);
|
$display("PCX FIFO Write Request: wr_ptr=%0d, data=0x%032X", wr_ptr, data);
|
`endif
|
`endif
|
mem[wr_ptr] <= data;
|
mem[wr_ptr] <= data;
|
wr_ptr <= wr_ptr + 1;
|
wr_ptr <= wr_ptr + 1;
|
end
|
end
|
end
|
end
|
end // always @ (posedge clock)
|
end // always @ (posedge clock)
|
|
|
// FIFO status flags
|
// FIFO status flags
|
assign empty = (rd_ptr == wr_ptr);
|
assign empty = (rd_ptr == wr_ptr);
|
assign full = ((rd_ptr[pointer_width-2:0] == wr_ptr[pointer_width-2:0]) && (rd_ptr[pointer_width-1] != wr_ptr[pointer_width-1]));
|
assign full = ((rd_ptr[pointer_width-2:0] == wr_ptr[pointer_width-2:0]) && (rd_ptr[pointer_width-1] != wr_ptr[pointer_width-1]));
|
|
|
endmodule // pcx_fifo
|
endmodule // pcx_fifo
|
|
|
|
|