満杯か空かをチェックする手段として、fillcount を使用して fifo の verilog コードを作成しました。同じコードの 2 つのバージョンがあります。1つは、読み取り、書き込み、空の/フル、fillcount、およびポインターをインクリメントするための常にブロックを分離しているところです。
module FIFO (clk, reset, data_in, put, get, data_out, fillcount, empty, full);
parameter DEPTHP2 = 8 ;
parameter WIDTH = 8 ;
input [WIDTH-1:0] data_in;
input put, get, reset, clk;
output fillcount;
output reg [WIDTH-1:0] data_out;
output reg empty, full;
reg [3:0]fillcount ;
reg [WIDTH-1:0] fifo_1[0:DEPTHP2-1];
reg [2:0] rp,wp;
always@(posedge clk or posedge reset)
begin
if( reset )
begin
wp <= 0;
rp <= 0;
end
else
begin
if( !full && put ) wp <= wp + 1;
else wp <= wp;
if( !empty && get ) rp <= rp + 1;
else rp <= rp;
end
end
always @(fillcount)
begin
if(fillcount==0)
empty =1 ;
else
empty=0;
if(fillcount==8)
full=1;
else
full=0;
end
always @(posedge clk or posedge reset)
begin
if( reset )
fillcount <= 0;
else if( (!full && put) && ( !empty && get ) )
fillcount <= fillcount;
else if( !full && put )
fillcount <= fillcount + 1;
else if( !empty && get )
fillcount <= fillcount - 1;
else
fillcount <= fillcount;
end
always @( posedge clk or posedge reset)
begin:Reading
if( reset )
data_out <= 0;
else
begin
if( get && !empty )
data_out <= fifo_1[rp];
else
data_out <= data_out;
end
end
always @(posedge clk)
begin:Writing
if( put && !full )
fifo_1[ wp ] <= data_in;
else
fifo_1[ wp ] <= fifo_1[ wp ];
end
endmodule
別の方法は、ロジックに影響を与えるいくつかの常にブロックを組み合わせた場合です(私の理解では!!)しかし、すぐに書き込んだ後にデータを読み込もうとした場合には機能しません。他のすべてのテストケースに合格します。
何がうまくいかなかったのかわからない..誰かが私が間違っているところを指摘できれば素晴らしいだろう.
//The code that is not working
always@(posedge clk or posedge reset)
begin:Writing
if(reset)
wp<=0;
else
if( put && !full)
begin
fifo1[wp]<=data_in;
wp<=wp+1;
end
else
begin
fifo1[wp]<=fifo1[wp];
wp<=wp;
end
end
always@(posedge clk or posedge reset)
begin:Reading
if(reset)
begin
rp<=0;
data_out<=0;
end
else
if(get && !empty)
begin
data_out<=fifo1[rp];
rp<=rp+1;
end
else
begin
fifo1[rp]<=fifo1[rp];
rp<=rp;
end
end
always@(posedge clk or posedge reset)
begin:Fillcount
if(reset)
fillcount<=0;
else
if((!full && put ) && ( !empty && get))
fillcount<=fillcount;
else if(!full && put)
fillcount<=fillcount+1;
else if(!empty && get)
fillcount<=fillcount-1;
else
fillcount<=fillcount;
end
always@(fillcount)
begin
full=(fillcount==8);
empty=(fillcount==0);
end
endmodule
別の質問: 私が学んだ限り、verilog でコーディングする一般的な方法は、fsm を使用して状態図を描画し、それらを使用することです..しかし、fifo、Tcam などのメモリ要素をコーディングしようとすると、苦労しました。ダブルクロックFIFO。これらの要素のコーディングを行うアプローチまたは方法はありますか。
長い質問で申し訳ありません