FIFO的设计有两种:
第一种,调用系统自带的IP;
第二种,用户自行设计;
对于用户自行设计,这里本人给出了自行设计代码,自行设计包括的部分有:
module fifo_verilog(clk,rst_n,wren,rden,full,empty,data,q);
parameter WIDTH=8;
parameter DEPTH=8;
parameter ADDR=3;
input clk;
input rst_n;
input wren;
input rden;
input[WIDTH-1:0]data;
output full;
output empty;
output[WIDTH-1:0]q;
reg[WIDTH-1:0]q;
reg[WIDTH-1:0]mem_data[DEPTH-1:0];
reg[ADDR-1:0]waddr,raddr;
reg full,empty;
always@(posedge clk or negedge rst_n)
if(rst_n==1'b0)
waddr<=3'd0;
else if(wren==1'b1)
waddr<=waddr+1;
always@(posedge clk)
if(wren==1'b1)
mem_data[waddr]<=data;
always@(posedge clk or negedge rst_n)
if(rst_n==1'b0)
raddr<=3'd0;
else if(rden==1'b1)
raddr<=raddr+1;
always@(posedge clk )
if(rden==1'b1)
q<=mem_data[raddr];
always@(posedge clk or negedge rst_n)
if(rst_n==1'b0)
full<=1'b0;
else if(((wren&!rden)&&(waddr==raddr-1))||((waddr==DEPTH-1)&&(raddr==1'b0)))
full<=1'b1;
else
full<=1'b0;
always@(posedge clk or negedge rst_n)
if(rst_n==1'b0)
empty<=1'b1;
else if(((!wren&rden)&&(waddr==raddr+1))||((raddr==DEPTH-1)&&(waddr==1'b0)))
empty<=1'b0;
else
empty<=1'b1;
endmodule