FIFO复位设置如下,reset value 为1则高电平复位,为0则低电平复位,
如何清空FIFO,FIFO复位之后empty信号默认为高,在工作中需要一次性清空FIFO中的数据时,要对FIFO的复位信号产生一个上升沿即可实现FIFO的清空
Verilog代码
`timescale 1ns / 1ps
module fifo_test(
input clk_50m,
input rst_n,
output reg[15:0]data,
output fifo_empty,
output reg wr_en,
output reg clear
);
//实例化FIFO,只观察它的复位与空信号
time_fifo u_time_fifo (
.clk(clk_50m), // input clk
.rst(rst_n&&clear), // input rst
.din(data), // input [15 : 0] din
.wr_en(wr_en), // input wr_en
.rd_en(), // input rd_en
.dout(), // output [15 : 0] dout
.full(), // output full
.empty(fifo_empty) // output empty
);
reg[7:0] cnt;
always@(posedge clk_50m or negedge rst_n)begin//给FIFO写入一些数据,使其非空
if(!rst_n) begin
data <= 16'd0;
wr_en<= 1'b0;
end
else begin
data <= data+1'b1;
if(data == 10) //复位完不能立即写入,要过几个时钟才可以写入,这里简单延时一下
wr_en<= 1'b1;
else if(cnt == 20)
wr_en<= 1'b0;
end
end
always@(posedge clk_50m or negedge rst_n)begin//复位操作计时器
if(!rst_n) begin
cnt <= 8'd0;
clear<= 1'b1;
end
else begin
cnt <= cnt+1'b1;
if(cnt == 20)
clear<= 1'b0;//先拉低,过一会再拉高,产生一个上升沿
else if(data == 25)//拉低最小3个时钟,可适当大一些,这里保持了5个时钟
clear<= 1'b1;
end
end
endmodule
testbench程序:
`timescale 1ns / 1ps
module tb_fifo_test;
// Inputs
reg clk_50m;
reg rst_n;
// Outputs
wire [15:0] data;
wire fifo_empty;
wire clear;
wire wr_en;
// Instantiate the Unit Under Test (UUT)
fifo_test uut (
.clk_50m(clk_50m),
.rst_n(rst_n),
.data(data),
.fifo_empty(fifo_empty),
.wr_en(wr_en),
.clear(clear)
);
initial begin
// Initialize Inputs
clk_50m = 0;
rst_n = 0;
// Wait 100 ns for global reset to finish
#20;
rst_n = 1'b1;
end
always #10 clk_50m <= ~clk_50m;
endmodule
仿真结果如下,在复位信号拉高后,FIFO清空了。