always @(posedge clk ornegedge rstn) begin if(!rstn) begin count <= 0; endelsebegin if(wen && !full && ren && !empty) begin count <= count; end elseif(wen && !full) begin count <= count + 1; end elseif(ren && !empty) begin count <= count - 1; end end end
always @(posedge clk ornegedge rstn) begin if(!rstn) begin wr_addr <= 0; endelsebegin if(wr_addr == (DEPTH_CNT-1)) begin wr_addr <= 0; end elseif(wen && !full) begin wr_addr <= wr_addr + 1; end end end
always @(posedge clk ornegedge rstn) begin if(!rstn) begin rd_addr <= 0; endelsebegin if(rd_addr == (DEPTH_CNT -1)) begin rd_addr <= 0; end elseif(ren && !empty) begin rd_addr <= rd_addr + 1; end end end
always @(posedge clk) begin if(wen && !full) begin buf_mem[wr_addr] <= din; end end
always @(posedge clk ornegedge rstn) begin if(!rstn) begin dout <= 0; endelsebegin if(ren && !empty) begin dout <= buf_mem[rd_addr]; end end end
integer i = 0; task fifo_write; input [7:0] cnt; begin for(i=0; i<cnt; i=i+1) begin @(posedge clk) begin wen <= 1'b1; din <= i + 1; end end @(posedge clk) wen <= 1'b0; end endtask
task fifo_read; input [7:0] cnt; begin for(i=0; i<cnt; i=i+1) begin @(posedge clk) begin ren <= 1'b1; end end @(posedge clk) ren <= 1'b0; end endtask