聊一聊xilinx 7系列推薦使用的復位方式


  在一個FPGA項目中,全局網絡的建立至關重要,其中包括時鍾網絡和復位網絡,通常我們在設計的時候對時鍾網絡的規划格外小心,卻忽視了復位網絡,其實復位是需要在設計中考慮和實現的最常見也更重要的控制信號之一,它跟時鍾一樣也是一個覆蓋全局、高扇出的信號,復位會給用戶設計的性能、使用面積和功耗產生顯著影響,這個復位如果處理不當也會導致意想不到的錯誤。那么復位信號選擇同步還是異步、高電平還是低電平有效?對於這個問題,針對Xilinx 7系列FPGA,就聊一聊這個問題。Xiinx 7系列FPGA推薦使用同步高電平復位,這與我們平時用到的異步低電平復位有很大出入,至於為何如此且聽細細道來。

1    什么情況下使用復位信號

  很多工程師習慣於對FPGA設計進行上電復位,總擔心如果不復位,觸發器就處於不定狀態,導致系統跑飛。事實上,每個觸發器都有明確的初始值,這個初始值與是否復位無關。因此,一旦系統上電,即使沒有復位,對於FDSE和FDPE,其初始值為1,對於FDRE和FDCE,其初始值為0。Block RAM和DSP48內部觸發器初始值為0。

  1.如果只是上電復位,那么這種復位是不需要的

  對於控制路徑,例如狀態機,這種復位通常是必需的。相比之下,數據路徑的復位通常是不需要的。因為,老的數據總會被新數據“沖走”

  2.通常,控制路徑需要復位,數據路徑不需要復位

  從功能仿真的角度看,如果沒有初始值,觸發器輸出會顯示“X”,從而導致仿真無法繼續。解決方法是在定義觸發器時,給出初始值,如下圖所示,而且這種方式是可綜合的。

  reg a = 1'b0;

  3.功能仿真時,為獲得觸發器初始值,可在定義該觸發器時直接聲明,無需復位

2    同步復位 vs 異步復位

  在官方文檔UG949《UltraFast Design Methodology Guide for the Vivado Design Suite》中關於復位有如下一段描述:

  Synchronous Reset vs. Asynchronous Reset

  If a reset is needed, Xilinx recommends code synchronous resets. Synchronous resets have many advantages over asynchronous resets.

  • Synchronous resets can directly map to more resource elements in the FPGA device architecture.
  • Asynchronous resets also impact the performance of the general logic structures. As all Xilinx FPGA general-purpose registers can program the set/reset as either asynchronous or synchronous, it can be perceived that there is no penalty in using asynchronous resets. That assumption is often wrong. If a global asynchronous reset is used, it does not increase the control sets. However, the need to route this reset signal to all register elements increases timing complexity.
  • If using asynchronous reset, remember to synchronize the deassertion of the asynchronous reset.
  • Synchronous resets give more flexibility for control set remapping when higher density or fine tuned placement is needed. A synchronous reset may be remapped to the data path of the register if an incompatible reset is found in the more optimally placed Slice. This can reduce wire length and increase density where needed to allow proper fitting and improved performance.
  • Asynchronous resets might require multicycle assertion to ensure a circuit is properly reset and stable. When properly timed, synchronous resets do not have this requirement.
  • Use synchronous resets if asynchronous resets have a greater probability of upsetting memory contents to block RAMs, LUTRAMs, and SRLs during reset assertion.
  • Some resources such as the DSP48 and block RAM have only synchronous resets for the register elements within the block. When asynchronous resets are used on register elements associated with these elements, those registers may not be inferred directly into those blocks without impacting functionality.

  也就是說,在設計中如何開發人員需要使用復位,xilinx建議代碼同步復位,並且官方文檔中也給出了使用同步復位與異步復位對設計所造成的不同影響。

  下面的代碼使用了異步復位的16X16位的乘法器,綜合后的結果如下圖,DSP48不支持異步復位,因此,這些觸發器均為SLICE中的觸發器,這就會額外消耗65個觸發器和32個LUT。

module mult (
    input                   clk,
    input                   rst,
    input       [15:0]      din0,
    input       [15:0]      din1,
    output reg  [31:0]      dout
    );

reg [15:0] din0_dly1,din0_dly2;
reg [15:0] din1_dly1,din1_dly2;

always @ (posedge clk or posedge rst) begin
    if  (rst) begin
        din0_dly1 <= 16'h0;
        din0_dly2 <= 16'h0;
        din1_dly1 <= 16'h0;
        din1_dly2 <= 16'h0;
        dout      <= 32'h0;
    end else begin
        din0_dly1 <= din0;
        din0_dly2 <= din0_dly1;
        din1_dly1 <= din1;
        din1_dly2 <= din1_dly1;
        dout      <= din0_dly2 * din1_dly2;
    end
end

endmodule

module mult (
    input                   clk,
    input                   rst,
    input       [15:0]      din0,
    input       [15:0]      din1,
    output reg  [31:0]      dout
    );

reg [15:0] din0_dly1,din0_dly2;
reg [15:0] din1_dly1,din1_dly2;

always @ (posedge clk) begin
    if  (rst) begin
        din0_dly1 <= 16'h0;
        din0_dly2 <= 16'h0;
        din1_dly1 <= 16'h0;
        din1_dly2 <= 16'h0;
        dout      <= 32'h0;
    end else begin
        din0_dly1 <= din0;
        din0_dly2 <= din0_dly1;
        din1_dly1 <= din1;
        din1_dly2 <= din1_dly1;
        dout      <= din0_dly2 * din1_dly2;
    end
end

endmodule

  而上圖為使用同步復位綜合后的結果,上述觸發器會完美地映射到DSP48內部,設計對比異步復位的設計具有最佳的資源使用率,更好的性能和更低的功耗,並且邏輯層數也更少。

3    高電平 VS 低電平

  在上文描述同步、異步復位的HDL代碼中都為高電平有效復位,異步復位只要在判斷條件中取個反即可。關於選擇高電平有效還是選擇低電平有效的復位,不像選擇同步還是異步有那么些理論根據,因此有些設計者就根據個人代碼編寫的喜好來選擇是高電平復位還是低電平復位。但是高、低電平復位總是有所區別的。

  在手冊UG949《UltraFast Design Methodology Guide for the Vivado Design Suite》(v2015.3)中對復位使用高電平還是低電平有如下描述,雖然在后續的版本中刪除了這一段描述,但是還是推薦使用高電平復位,這是與7系列器件結構所決定的。

  Control Signal Polarity (Active-High vs. Active-Low)

  For high-fanout control signals like clock enables or resets, it is best to use active high in the entire design. If a block operates with active low resets or clock enables, inverters get added to the design and there is an associated timing penalty. It can restrict synthesis options to flat or rebuilt to optimize the inverters or require the implementation of a custom solution.

  The Slice and internal logic of the Xilinx FPGA clock enables and resets are inherently active-High. Describing active-Low resets or clock enables may result in additional LUTs used as simple inverters for those routes.

  For UltraScale devices, a programmable inversion is available on the reset. Therefore, reset polarity is more flexible. However, Xilinx still recommends keeping the reset polarity coding consistent (all active-High or all active-Low) to allow for maximum flexibility for packing logic. The enable does not have an inversion so Xilinx recommends always describing active-High enables.

  對於Xilinx 7系列FPGA的結構,其中復位可以通過兩種方式實現:全局復位網絡(GSR)和普通復位端,如圖2所示為7系列FPGA中的Storage Element結構(具體內容參閱“7 Series FPGAs Configurable Logic Block”,ug474),它既可以配置成Flip-Flop也可以配置成Latch,由輸入端D、輸出端Q,三個控制信號時鍾使能CE、時鍾CK和置位/復位SR組成;內部還有INIT0、INIT1、SRLO和SRHI 四個選項,其中INIT0和INIT1配對,表示通過GSR全局復位,此復位網絡是異步的,並且鋪設在整個芯片區域,屬於硬核,用戶無法自定義修改;而SRLO和SRHI配對,表示高電平有效信號SR驅動的復位,此信號可以配置成異步或者同步,根據此特性,如果使用低電平有效的復位,實現時則需要在SR端額外加入一個非門,因此在7系列FPGA設計時推薦使用高電平有效的復位。

  選擇高還是低,需要根據具體的電平標准、器件結構來選擇,並不是一概而論低電平有效的好或者高電平有效的好。

參考資料

[1]     Xilinx,“Get Smart About Reset: Think Local, Not Global ”,wp272(v1.0.1)

[2]     Xilinx,“UltraFast Design Methodology Guide for the Vivado Design Suite”, ug949(v2018.1/v2015.3)

[3]     Xilinx,“7 Series FPGAs Configurable Logic Block”,ug474(v1.8)

[4]     Xilinx,“UltraScale Architecture Libraries Guide”,ug974(v2018.1)

[5]     https://www.veryarm.com/173792.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM