FIFO Implementation
FIFO Implementation
ID No. Name
2023H1400128H V. Sahat Monal
Verilog Design code for FIFO
// Code your design here
module main_fifo#(parameter dt_width = 8, ff_depth = 18)
(clk,rst,push_valid,pop_valid,push_data/*in_data*/,pop_data/*out_data*/
,full,empty);
input clk,rst; input [dt_width-1:0] push_data; output reg [dt_width-1:0]
pop_data;
input pop_valid/*(front)*/;input push_valid/*(back)*/; output full, empty;
module tb_fifo();
// Parameters
parameter DATA_WIDTH = 8;
parameter FIFO_DEPTH = 16;
// Signals
reg clk = 0;
reg reset = 1;
reg push_valid = 0;
reg [DATA_WIDTH-1:0] push_data = 0;
reg pop_valid = 0;
wire [DATA_WIDTH-1:0] pop_data;
wire empty;
wire full;
// Clock generation
always #5 clk = ~clk;
// Stimulus
initial begin
// Reset
#10 reset = 0;
// End simulation
$stop;
end
// Assertions
// Assertion 1: After reset, write pointer (wr_ptr) should be at 0.
assert property (@(posedge clk) disable iff (reset) wr_ptr == 0);
// Assertion 2: If push_valid is asserted and wr_ptr is less than
FIFO_DEPTH, wr_ptr should increment by 1.
assert property (@(posedge clk) disable iff (reset) (push_valid && wr_ptr
< FIFO_DEPTH) |-> (wr_ptr == $past(wr_ptr) + 1));
// Assertion 3: If push_valid is asserted and wr_ptr is less than
FIFO_DEPTH, the data at wr_ptr in memory should be equal to push_data.
assert property (@(posedge clk) disable iff (reset) (push_valid && wr_ptr
< FIFO_DEPTH) |-> (memory[wr_ptr] == push_data));
// Assertion 4: If pop_valid is asserted, rd_ptr is less than FIFO_DEPTH,
and rd_ptr is less than wr_ptr, rd_ptr should increment by 1.
assert property (@(posedge clk) disable iff (reset) (pop_valid && rd_ptr <
FIFO_DEPTH && rd_ptr < wr_ptr) |-> (rd_ptr == $past(rd_ptr) + 1));
// Assertion 5: If pop_valid is asserted and rd_ptr is less than
FIFO_DEPTH, pop_data should be equal to the data at rd_ptr in memory.
assert property (@(posedge clk) disable iff (reset) (pop_valid && rd_ptr <
FIFO_DEPTH) |-> (pop_data == memory[rd_ptr]));
// Assertion 6: The empty flag should be asserted when wr_ptr is equal to
0 or when rd_ptr is equal to wr_ptr.
assert property (@(posedge clk) disable iff (reset) (empty) |-> (wr_ptr ==
0 || rd_ptr == wr_ptr));
// Assertion 7: The full flag should be asserted when wr_ptr is equal to
FIFO_DEPTH.
assert property (@(posedge clk) disable iff (reset) (full) |-> (wr_ptr ==
FIFO_DEPTH));
endmodule
Vivado Results