ram_fifo.v: add simulator debugging checks

This commit is contained in:
Peter McGoron 2022-12-17 10:18:15 -05:00
parent f0f1750a9a
commit 60404cd026
1 changed files with 21 additions and 0 deletions

View File

@ -10,6 +10,7 @@ module ram_fifo #(
input write_enable,
input signed [DAT_WID-1:0] write_dat,
output reg [FIFO_DEPTH_WID-1:0] fifo_size,
output signed [DAT_WID-1:0] read_dat
);
@ -27,4 +28,24 @@ ram_fifo_dual_port #(
.read_dat(read_dat)
);
always @ (posedge clk) begin
if (rst) begin
fifo_size <= 0;
end else if (read_enable && !write_enable) begin
fifo_size <= fifo_size - 1;
`ifdef VERILATOR
if (fifo_size == 0) begin
$error("fifo underflow");
end
`endif
end else if (write_enable && !read_enable) begin
fifo_size <= fifo_size + 1;
`ifdef VERILATOR
if (fifo_size == FIFO_DEPTH) begin
$error("fifo overflow");
end
`endif
end
end
endmodule