Line 36... |
Line 36... |
//
|
//
|
//
|
//
|
module ufifo(i_clk, i_rst, i_wr, i_data, o_empty_n, i_rd, o_data, o_status, o_err);
|
module ufifo(i_clk, i_rst, i_wr, i_data, o_empty_n, i_rd, o_data, o_status, o_err);
|
parameter BW=8; // Byte/data width
|
parameter BW=8; // Byte/data width
|
parameter [3:0] LGFLEN=4;
|
parameter [3:0] LGFLEN=4;
|
parameter [0:0] RXFIFO=0;
|
parameter RXFIFO=1'b0;
|
input i_clk, i_rst;
|
input i_clk, i_rst;
|
input i_wr;
|
input i_wr;
|
input [(BW-1):0] i_data;
|
input [(BW-1):0] i_data;
|
output wire o_empty_n; // True if something is in FIFO
|
output wire o_empty_n; // True if something is in FIFO
|
input i_rd;
|
input i_rd;
|
Line 188... |
Line 188... |
// the FIFO count that matters is the number of empty positions that
|
// the FIFO count that matters is the number of empty positions that
|
// can still be filled before the FIFO is full.
|
// can still be filled before the FIFO is full.
|
//
|
//
|
// Adjust for these differences here.
|
// Adjust for these differences here.
|
reg [(LGFLEN-1):0] r_fill;
|
reg [(LGFLEN-1):0] r_fill;
|
generate if (RXFIFO!=0) begin
|
always @(posedge i_clk)
|
|
if (RXFIFO!=0) begin
|
// Calculate the number of elements in our FIFO
|
// Calculate the number of elements in our FIFO
|
//
|
//
|
// Although used for receive, this is actually the more generic
|
// Although used for receive, this is actually the more
|
// answer--should you wish to use the FIFO in another context.
|
// generic answer--should you wish to use the FIFO in
|
always @(posedge i_clk)
|
// another context.
|
if (i_rst)
|
if (i_rst)
|
r_fill <= 0;
|
r_fill <= 0;
|
else case({i_wr, i_rd})
|
else case({i_wr, i_rd})
|
2'b01: r_fill <= r_first - r_next;
|
2'b01: r_fill <= r_first - r_next;
|
2'b10: r_fill <= r_first - r_last + 1'b1;
|
2'b10: r_fill <= r_first - r_last + 1'b1;
|
default: r_fill <= r_first - r_last;
|
default: r_fill <= r_first - r_last;
|
endcase
|
endcase
|
end else begin
|
end else begin
|
// Calculate the number of elements that are empty and can be
|
// Calculate the number of elements that are empty and
|
// filled within our FIFO
|
// can be filled within our FIFO
|
always @(posedge i_clk)
|
|
if (i_rst)
|
if (i_rst)
|
r_fill <= { (LGFLEN){1'b1} };
|
r_fill <= { (LGFLEN){1'b1} };
|
else case({i_wr, i_rd})
|
else case({i_wr, i_rd})
|
2'b01: r_fill <= r_last - r_first;
|
2'b01: r_fill <= r_last - r_first;
|
2'b10: r_fill <= r_last - w_first_plus_two;
|
2'b10: r_fill <= r_last - w_first_plus_two;
|
default: r_fill <= r_last - w_first_plus_one;
|
default: r_fill <= r_last - w_first_plus_one;
|
endcase
|
endcase
|
end endgenerate
|
end
|
|
|
// We don't report underflow errors. These
|
// We don't report underflow errors. These
|
assign o_err = (r_ovfl); // || (r_unfl);
|
assign o_err = (r_ovfl); // || (r_unfl);
|
|
|
wire [3:0] lglen;
|
wire [3:0] lglen;
|
assign lglen = LGFLEN;
|
assign lglen = LGFLEN;
|
|
|
wire [9:0] w_fill;
|
wire [9:0] w_fill;
|
assign w_fill[(LGFLEN-1):0] = r_fill;
|
assign w_fill[(LGFLEN-1):0] = r_fill;
|
generate if (LGFLEN != 10)
|
generate if (LGFLEN < 10)
|
assign w_fill[9:(LGFLEN-1)] = 0;
|
assign w_fill[9:(LGFLEN)] = 0;
|
endgenerate
|
endgenerate
|
|
|
wire w_half_full;
|
wire w_half_full;
|
assign w_half_full = r_fill[(LGFLEN-1)];
|
assign w_half_full = r_fill[(LGFLEN-1)];
|
|
|