设置完成之后,点击Generate。
顶层负责调用my_fifo,例化文件在ipcore_dir -> my_fifo.veo 中。
设计代码为:
module fifo_test( input wr_clk, input rd_clk, input [7:0] wrdata, input wren, input rden, output full, output empty, output [7:0] rdata );
my_fifo my_fifo_inst ( .wr_clk(wr_clk), .rd_clk(rd_clk), .din(wrdata), .wr_en(wren), .rd_en(rden), .dout(rdata), .full(full), .empty(empty) );
endmodule
在应用时,只要检测到wrfull不为高时,就可以写入数据;检测到rdempty不为高时,就可以读出数据;在仿真时,我们做简单测试,将随机的256个数据,写入fifo中;然后将256个数据读出。
设计代码为:
`
timescale 1ns/1ps
module fifo_test_tb;
reg wr_clk; reg rd_clk; reg [7:0] wrdata; reg wren; reg rden; wire full; wire empty;
// Outputs wire [7:0] rdata;
// Instantiate the Unit Under Test (UUT) fifo_test fifo_test_inst ( .wr_clk(wr_clk), .rd_clk(rd_clk), .wrdata(wrdata), .wren(wren), .rden(rden), .full(full), .empty(empty), .rdata(rdata) );
initial wr_clk = 1'b0; always # 5 wr_clk = ~wr_clk; initial rd_clk = 1'b0; always # 10 rd_clk = ~rd_clk; initial begin wren = 1'b0; wrdata = 8'd0; rden = 1'b0; # 200 repeat (1100) begin @ (posedge wr_clk); # 2; wren = 1'b1; wrdata = {$random} % 256; end @ (posedge wr_clk); # 2; wrdata = 8'd0; wren = 1'b0; # 200 repeat (1100) begin @ (posedge rd_clk); # 2; rden = 1'b1; end @ (posedge rd_clk); # 2; rden = 1'b0; # 200; $stop; end
endmodule