FIFO的使用非常廣泛,一般用于不同時(shí)鐘域之間的數(shù)據(jù)傳輸,,或者用于不同數(shù)據(jù)寬度之間的數(shù)據(jù)匹配,。在實(shí)際的工程應(yīng)用,可以根據(jù)需要自己寫(xiě)FIFO,。不考慮資源的情況下,,也可以使用Xilinx提供的IP核來(lái)完成。
接口類型選擇Native,,SOC芯片上也可以根據(jù)需要選擇AXI接口,。
選擇存儲(chǔ)器類型:可以用塊RAM、分布式RAM,,移位寄存器和內(nèi)嵌FIFO來(lái)實(shí)現(xiàn)FIFO,。這里主要是block RAM和distribute RAM之間的區(qū)別。簡(jiǎn)而言之,,block RAM是FPGA中定制的ram資源,而distribute RAM則是由LUT構(gòu)成的RAM資源,。由此區(qū)別表明,,當(dāng)FIFO較大時(shí)應(yīng)選擇block RAM,當(dāng)FIFO較小時(shí),,選擇distribute RAM.另外一個(gè)很重要的就是block RAM支持讀寫(xiě)不同寬度,,而distribute不支持。在這里為了更全面的了解FIFO,,選擇block RAM以擁有非對(duì)稱方向速率的特性,,內(nèi)嵌FIFO(Builtin FIFO)在5以上的FPGA芯片中才存在。
時(shí)鐘:讀寫(xiě)操作是否在相同的時(shí)鐘域中完成,。如果是,,可以選擇Common clock,否則,,選擇Independent clcoks,。
讀模式有兩種選擇,一般選擇標(biāo)準(zhǔn)模式,,F(xiàn)irst-Word Fall-Fhrough模式為首字預(yù)現(xiàn),,F(xiàn)WFT是指在不影響FIFO讀操作的情況下,提前查看下一個(gè)數(shù)據(jù)的能力,。即FIFO中不為空,,有可用的數(shù)據(jù)時(shí),F(xiàn)IFO中的第一個(gè)數(shù)據(jù)自動(dòng)出現(xiàn)在輸出總線DOUT上,。
Synchronization Stage:穿過(guò)交叉時(shí)鐘域的同步狀態(tài)(寄存器)數(shù)量,,默認(rèn)即可,。
data port parameters處,有actual write depth和actual read depth,他們都比我們?cè)O(shè)置的要小,,在實(shí)際的工程應(yīng)用中,,F(xiàn)IFO深度確實(shí)要比預(yù)設(shè)的小1,即當(dāng)寫(xiě)入了Write Width-1個(gè)數(shù)據(jù)之后,,F(xiàn)IFO的滿信號(hào)full會(huì)拉高,,這個(gè)時(shí)候如果還要寫(xiě)入數(shù)據(jù),則寫(xiě)入的數(shù)據(jù)丟失,。同理,,讀出Read Width-1個(gè)數(shù)據(jù)后,F(xiàn)IFO的空信號(hào)empty會(huì)拉高,,此時(shí)讀出信號(hào)無(wú)效,。如下:
該FIFO數(shù)據(jù)深度為16,從aabb0002到aabb0011共寫(xiě)入16個(gè)數(shù)據(jù),,當(dāng)寫(xiě)入到第15個(gè)時(shí),,F(xiàn)ULL信號(hào)拉高,數(shù)據(jù)不能被有效的寫(xiě)入,,從讀狀態(tài)可以看出,。當(dāng)讀寫(xiě)數(shù)據(jù)位寬不匹配時(shí),寫(xiě)入的位寬大于讀出的數(shù)據(jù)位寬,,則先從高位開(kāi)始讀,;當(dāng)寫(xiě)入的數(shù)據(jù)位寬小于讀出時(shí),先寫(xiě)入的數(shù)據(jù)在讀數(shù)據(jù)的高位,,如下:
關(guān)于FIFO復(fù)位,,Xilinx FIFO默認(rèn)為高電平復(fù)位,在Initialization 中可以設(shè)置復(fù)位信號(hào)到來(lái)之后,,full,、almost full、prog full等信號(hào)的復(fù)位值為0,,或者為1,。可以設(shè)置讀寫(xiě)同步復(fù)位,,或者異步復(fù)位,。fifo的復(fù)位需要一段時(shí)間,期間wr_rst_busy和rd_rst_busy信號(hào)為高電平,,此時(shí)應(yīng)禁止讀寫(xiě)FIFO,,否則會(huì)造成數(shù)據(jù)丟失。
關(guān)于讀寫(xiě)計(jì)數(shù),讀計(jì)數(shù)是和讀時(shí)鐘同步的,,寫(xiě)計(jì)數(shù)是和寫(xiě)時(shí)鐘同步的,。讀計(jì)數(shù)是以讀數(shù)據(jù)寬度為單位,fifo中存在的數(shù)據(jù)個(gè)數(shù),;寫(xiě)計(jì)數(shù)是以寫(xiě)數(shù)據(jù)寬度為單位,,fifo中存在的數(shù)據(jù)個(gè)數(shù),這兩個(gè)值的結(jié)果,,簡(jiǎn)單理解就是fifo內(nèi)部控制器讀寫(xiě)地址的差,,由于fifo讀寫(xiě)時(shí)鐘可能異步,讀寫(xiě)時(shí)鐘頻率不同,,導(dǎo)致計(jì)算讀寫(xiě)計(jì)數(shù)值時(shí)存在延遲,,并不完全和讀寫(xiě)操作同步。
讀寫(xiě)計(jì)數(shù)仿真結(jié)果如下:
關(guān)于讀寫(xiě)使能,,寫(xiě)使能wr_en為高時(shí),,數(shù)據(jù)立即被寫(xiě)入到fifo中,讀使能為高時(shí),,下一個(gè)時(shí)鐘周期,,有效數(shù)據(jù)才會(huì)出現(xiàn)在數(shù)據(jù)總線dout上。
一段簡(jiǎn)單的仿真如下:
`timescale 1ns / 1ps
module tb_fifo_16x256(
?。?;
reg rst;
reg wr_clk;
reg rd_clk;
reg [31:0] din;
reg wr_en;
reg rd_en;
wire [15:0] dout;
wire full;
wire empty;
wire valid;
wire almost_full;
wire almost_empty;
wire [4:0] rd_data_count;
wire [3:0] wr_data_count;
wire wr_rst_busy;
wire rd_rst_busy;
always #10 wr_clk <= ~wr_clk;
always #5 rd_clk <= ~rd_clk;
initial begin
rst <= 1;
wr_clk <= 0;
rd_clk <= 1;
din <= 32'haabb0001 ;
wr_en <= 0;
rd_en <= 0;
#20;
rst <= 0;
#300;
//======================================================empty
repeat(16) @(posedge wr_clk)
begin
din <= din + 1;
wr_en <= 1;
end
repeat(1) @(posedge wr_clk) wr_en <= 0;
repeat(32) @(posedge rd_clk)
begin
rd_en <= 1;
end
repeat(1) @(posedge rd_clk) rd_en <= 0;
//=======================================================full
repeat(16) @(posedge wr_clk)
begin
din <= din + 1;
wr_en <= 1;
end
repeat(1) @(posedge wr_clk) wr_en <= 0;
end
initial begin
#900;
repeat(32) @(posedge rd_clk)
begin
rd_en <= 1;
end
repeat(1) @(posedge rd_clk) rd_en <= 0;
end
fifo_16x256 fifo_16x256_inst (
.rst(rst), // input wire rst
.wr_clk(wr_clk),, // input wire wr_clk
.rd_clk(rd_clk), // input wire rd_clk
.din(din),, // input wire [31 : 0] din
.wr_en(wr_en),, // input wire wr_en
.rd_en(rd_en), // input wire rd_en
.dout(dout),, // output wire [15 : 0] dout
.full(full),, // output wire full
.almost_full(almost_full), // output wire almost_full
.empty(empty),, // output wire empty
.almost_empty(almost_empty),, // output wire almost_empty
.valid(valid), // output wire valid
.rd_data_count(rd_data_count),, // output wire [8 : 0] rd_data_count
.wr_data_count(wr_data_count),, // output wire [7 : 0] wr_data_count
.wr_rst_busy(wr_rst_busy), // output wire wr_rst_busy
.rd_rst_busy(rd_rst_busy) // output wire rd_rst_busy
?。?;
endmodule
更多信息可以來(lái)這里獲取==>>電子技術(shù)應(yīng)用-AET<<