Skip to content

Commit

Permalink
util_axis_fifo: Add almost empty and almost full support
Browse files Browse the repository at this point in the history
  • Loading branch information
Istvan Csomortani authored and Csomi committed Feb 16, 2021
1 parent 6178b42 commit 77ef042
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
21 changes: 17 additions & 4 deletions library/util_axis_fifo/util_axis_fifo.v
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ module util_axis_fifo #(
parameter DATA_WIDTH = 64,
parameter ADDRESS_WIDTH = 5,
parameter ASYNC_CLK = 1,
parameter M_AXIS_REGISTERED = 1
parameter M_AXIS_REGISTERED = 1,
parameter [ADDRESS_WIDTH-1:0] ALMOST_EMPTY_THRESHOLD = 16,
parameter [ADDRESS_WIDTH-1:0] ALMOST_FULL_THRESHOLD = 16
) (
input m_axis_aclk,
input m_axis_aresetn,
Expand All @@ -48,6 +50,7 @@ module util_axis_fifo #(
output m_axis_tlast,
output [ADDRESS_WIDTH-1:0] m_axis_level,
output m_axis_empty,
output m_axis_almost_empty,

input s_axis_aclk,
input s_axis_aresetn,
Expand All @@ -56,7 +59,8 @@ module util_axis_fifo #(
input [DATA_WIDTH-1:0] s_axis_data,
input s_axis_tlast,
output [ADDRESS_WIDTH-1:0] s_axis_room,
output s_axis_full
output s_axis_full,
output s_axis_almost_full
);

generate if (ADDRESS_WIDTH == 0) begin : zerodeep /* it's not a real FIFO, just a 1 stage pipeline */
Expand Down Expand Up @@ -93,8 +97,11 @@ generate if (ADDRESS_WIDTH == 0) begin : zerodeep /* it's not a real FIFO, just

assign m_axis_valid = m_axis_raddr != m_axis_waddr;
assign m_axis_level = ~m_axis_ready;
assign m_axis_empty = 0;
assign m_axis_almost_empty = 0;
assign s_axis_ready = s_axis_raddr == s_axis_waddr;
assign s_axis_empty = ~s_axis_valid;
assign s_axis_full = 0;
assign s_axis_almost_full = 0;
assign s_axis_room = s_axis_ready;

always @(posedge s_axis_aclk) begin
Expand Down Expand Up @@ -148,8 +155,10 @@ generate if (ADDRESS_WIDTH == 0) begin : zerodeep /* it's not a real FIFO, just
assign m_axis_tlast = axis_tlast_d;
assign s_axis_ready = m_axis_ready | ~m_axis_valid;
assign m_axis_empty = 1'b0;
assign m_axis_almost_empty = 1'b0;
assign m_axis_level = 1'b0;
assign s_axis_full = 1'b0;
assign s_axis_almost_full = 1'b0;
assign s_axis_room = 1'b0;

end
Expand Down Expand Up @@ -183,7 +192,9 @@ end else begin : fifo /* ADDRESS_WIDTH != 0 - this is a real FIFO implementation

util_axis_fifo_address_generator #(
.ASYNC_CLK(ASYNC_CLK),
.ADDRESS_WIDTH(ADDRESS_WIDTH))
.ADDRESS_WIDTH(ADDRESS_WIDTH),
.ALMOST_EMPTY_THRESHOLD (ALMOST_EMPTY_THRESHOLD),
.ALMOST_FULL_THRESHOLD (ALMOST_FULL_THRESHOLD))
i_address_gray (
.m_axis_aclk(m_axis_aclk),
.m_axis_aresetn(m_axis_aresetn),
Expand All @@ -192,11 +203,13 @@ end else begin : fifo /* ADDRESS_WIDTH != 0 - this is a real FIFO implementation
.m_axis_raddr(m_axis_raddr),
.m_axis_level(m_axis_level),
.m_axis_empty(m_axis_empty),
.m_axis_almost_empty(m_axis_almost_empty),
.s_axis_aclk(s_axis_aclk),
.s_axis_aresetn(s_axis_aresetn),
.s_axis_ready(s_axis_ready),
.s_axis_valid(s_axis_valid),
.s_axis_full(s_axis_full),
.s_axis_almost_full(s_axis_almost_full),
.s_axis_waddr(s_axis_waddr),
.s_axis_room(s_axis_room)
);
Expand Down
11 changes: 8 additions & 3 deletions library/util_axis_fifo/util_axis_fifo_address_generator.v
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@

module util_axis_fifo_address_generator #(
parameter ASYNC_CLK = 0, // single or double clocked FIFO
parameter ADDRESS_WIDTH = 4 // address width, effective FIFO depth
parameter ADDRESS_WIDTH = 4, // address width, effective FIFO depth
parameter [ADDRESS_WIDTH-1:0] ALMOST_EMPTY_THRESHOLD = 16,
parameter [ADDRESS_WIDTH-1:0] ALMOST_FULL_THRESHOLD = 16
) (
// Read interface - Sink side

Expand All @@ -45,6 +47,7 @@ module util_axis_fifo_address_generator #(
input m_axis_ready,
output m_axis_valid,
output m_axis_empty,
output m_axis_almost_empty,
output [ADDRESS_WIDTH-1:0] m_axis_raddr,
output [ADDRESS_WIDTH-1:0] m_axis_level,

Expand All @@ -55,6 +58,7 @@ module util_axis_fifo_address_generator #(
output s_axis_ready,
input s_axis_valid,
output s_axis_full,
output s_axis_almost_full,
output [ADDRESS_WIDTH-1:0] s_axis_waddr,
output [ADDRESS_WIDTH-1:0] s_axis_room
);
Expand Down Expand Up @@ -166,7 +170,8 @@ endgenerate
//------------------------------------------------------------------------------

wire [ADDRESS_WIDTH:0] s_axis_fifo_fill = s_axis_waddr_reg - s_axis_raddr_reg;
assign s_axis_full = (s_axis_fifo_fill == { 1'b1, {ADDRESS_WIDTH-1{1'b0}}});
assign s_axis_full = (s_axis_fifo_fill == { 1'b1, {ADDRESS_WIDTH{1'b0}}});
assign s_axis_almost_full = s_axis_fifo_fill > {1'b0, ~ALMOST_FULL_THRESHOLD};
assign s_axis_ready = ~s_axis_full;
assign s_axis_room = ~s_axis_fifo_fill;

Expand All @@ -180,8 +185,8 @@ assign s_axis_room = ~s_axis_fifo_fill;

wire [ADDRESS_WIDTH:0] m_axis_fifo_fill = m_axis_waddr_reg - m_axis_raddr_reg;
assign m_axis_empty = m_axis_fifo_fill == 0;
assign m_axis_almost_empty = (m_axis_fifo_fill < ALMOST_EMPTY_THRESHOLD);
assign m_axis_valid = ~m_axis_empty;
assign m_axis_level = m_axis_fifo_fill;

endmodule

0 comments on commit 77ef042

Please sign in to comment.