当前位置:   article > 正文

【Xilinx FPGA】异步 FIFO 的复位_fpga fifo复位时钟域

fpga fifo复位时钟域

FIFO(First-In-First-Out,先入先出)是一种的存储器类型,在 FPGA 开发中通常用于数据缓存、位宽转换或者跨时钟域(多 bit 数据流)。在使用异步 FIFO 时,应注意复位信号是否遵循相关要求和规范,避免数据丢失或损坏。本文主要介绍 Xilinx FPGA 对异步 FIFO 复位的时序要求,并参考 IP 核示例工程设计异步 FIFO 的复位逻辑。

目录

1 复位类型

2 异步 FIFO 的复位


1 复位类型

        Xilinx FIFO Generator 提供了复位端口,用于复位计数器与输出寄存器。有两种复位的类型:同步复位(Synchronous Reset)和异步复位(Asynchronous Reset)。

        对于同步复位方式,由于复位信号已经是同步的,因此无需设计额外的同步逻辑。

The asynchronous reset (rst) input asynchronously resets all counters, output registers, and memories when asserted. When reset is implemented, it is synchronized internally to the core with each respective clock domain for setting the internal logic of the FIFO to a known state. This synchronization logic allows for proper timing of the reset logic within the core to avoid glitches and metastable behavior.

        对于异步复位方式,复位信号会分别被同步到读/写时钟域,同步逻辑确保 FIFO 正确复位,避免“毛刺”或者亚稳态。

        

        异步复位应遵循以下 2 个设计规则:

(1)复位必须在所有时钟有效时进行,否则 FIFO 的状态无法预测;

(2)复位信号的脉宽至少为 3 个慢时钟周期。

        在复位期间,应避免对 fifo 进行读写操作,以防止数据丢失或损坏。在复位完成后,需要等待一段时间才能对 fifo 进行读写操作。

        开启 Safety Circuit 的 FIFO,复位释放之后需至少等待 60 个慢时钟周期。

        未开启 Safety Circuit 的 FIFO,复位释放之后需至少等待 30 个慢时钟周期。

2 异步 FIFO 的复位

        打开 IP 核自带的 Example Design,参考激励文件异步 FIFO 的复位逻辑。

        在 reset 释放之后 50 个写周期,释放 reset_ext 信号。reset 连接到 FIFO 的异步复位端口,reset_ext 则用于读/写控制逻辑的复位。

        在 Example Design 的顶层文件中,将 reset_ext 信号分别同步到读/写时钟域。这里不知道是不是参考工程的错误,rst_async_rd1 ~ rst_async_rd3 使用了同步复位,同步释放的方式。

        以下是根据参考工程,自己设计的异步 FIFO 的复位控制逻辑。

  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.std_logic_arith.all;
  4. use ieee.std_logic_unsigned.all;
  5. entity eth_rx_adjust is
  6. port(
  7. -- System level
  8. nRst : in std_logic;
  9. sysclk : in std_logic;
  10. -- GMII IN data port
  11. --gmii_rxd_rxctl : in std_logic_vector(9 downto 0);
  12. --gmii_rxc : in std_logic;
  13. eth_phy_rxd : in std_logic_vector(7 downto 0);
  14. eth_phy_rxdv : in std_logic;
  15. eth_phy_rxc : in std_logic;
  16. -- eth_rx data
  17. eth_rxd_sys : out std_logic_vector(7 downto 0);
  18. eth_rxdv_sys : out std_logic
  19. );
  20. end entity;
  21. architecture behav of eth_rx_adjust is
  22. -- internal component and signal declarations
  23. component fifo_8bit_2048 is
  24. port(
  25. din : in std_logic_vector(7 downto 0);
  26. wr_en : in std_logic;
  27. wr_clk : in std_logic;
  28. full : out std_logic;
  29. dout : out std_logic_vector(7 downto 0);
  30. rd_en : in std_logic;
  31. rd_clk : in std_logic;
  32. empty : out std_logic;
  33. rst : in std_logic;
  34. wr_data_count : out std_logic_vector(10 downto 0);
  35. rd_data_count : out std_logic_vector(10 downto 0)
  36. );
  37. end component;
  38. signal reset : std_logic := '1';
  39. signal reset_cnt : std_logic_vector(5 downto 0) := (others => '0');
  40. signal reset_ext_cnt : std_logic_vector(5 downto 0) := (others => '0');
  41. signal RESET_EXT : std_logic := '1';
  42. signal rst_async_wr1 : std_logic := '1';
  43. signal rst_async_wr2 : std_logic := '1';
  44. signal rst_async_wr3 : std_logic := '1';
  45. signal rst_async_rd1 : std_logic := '1';
  46. signal rst_async_rd2 : std_logic := '1';
  47. signal rst_async_rd3 : std_logic := '1';
  48. signal rst_int_wr : std_logic := '1';
  49. signal rst_int_rd : std_logic := '1';
  50. signal eth_fifo_wdata : std_logic_vector(7 downto 0);
  51. signal eth_fifo_wrreq : std_logic;
  52. signal eth_fifo_empty : std_logic;
  53. signal eth_fifo_rcnt : std_logic_vector(10 downto 0);
  54. signal eth_fifo_rdreq : std_logic;
  55. signal eth_fifo_rdata : std_logic_vector(7 downto 0);
  56. signal eth_fifo_rdvld : std_logic;
  57. attribute ASYNC_REG: string;
  58. attribute ASYNC_REG of rst_async_wr1: signal is "true";
  59. attribute ASYNC_REG of rst_async_wr2: signal is "true";
  60. attribute ASYNC_REG of rst_async_wr3: signal is "true";
  61. attribute ASYNC_REG of rst_async_rd1: signal is "true";
  62. attribute ASYNC_REG of rst_async_rd2: signal is "true";
  63. attribute ASYNC_REG of rst_async_rd3: signal is "true";
  64. ---------------------------------------------------------
  65. begin
  66. ---------------------------------------------------------
  67. process(nRst,eth_phy_rxc)
  68. begin
  69. if nRst = '0' then
  70. reset_cnt <= "000000";
  71. elsif rising_edge(eth_phy_rxc) then
  72. if reset_cnt < "001000" then
  73. reset_cnt <= reset_cnt + '1';
  74. else
  75. reset_cnt <= reset_cnt;
  76. end if;
  77. end if;
  78. end process;
  79. process(nRst,eth_phy_rxc)
  80. begin
  81. if nRst = '0' then
  82. reset <= '1';
  83. elsif rising_edge(eth_phy_rxc) then
  84. if reset_cnt < "001000" then
  85. reset <= '1';
  86. else
  87. reset <= '0';
  88. end if;
  89. end if;
  90. end process;
  91. process(reset,eth_phy_rxc)
  92. begin
  93. if reset = '1' then
  94. reset_ext_cnt <= "000000";
  95. elsif rising_edge(eth_phy_rxc) then
  96. if reset_ext_cnt < "110010" then
  97. reset_ext_cnt <= reset_ext_cnt + '1';
  98. else
  99. reset_ext_cnt <= reset_ext_cnt;
  100. end if;
  101. end if;
  102. end process;
  103. process(reset,eth_phy_rxc)
  104. begin
  105. if reset = '1' then
  106. RESET_EXT <= '1';
  107. elsif rising_edge(eth_phy_rxc) then
  108. if reset_ext_cnt < "110010" then
  109. RESET_EXT <= '1';
  110. else
  111. RESET_EXT <= '0';
  112. end if;
  113. end if;
  114. end process;
  115. -- Asynchronous reset, synchronous release for rst_async_wr1, rst_async_wr2, rst_async_wr3
  116. process(RESET_EXT,eth_phy_rxc)
  117. begin
  118. if RESET_EXT = '1' then
  119. rst_async_wr1 <= '1';
  120. rst_async_wr2 <= '1';
  121. rst_async_wr3 <= '1';
  122. elsif rising_edge(eth_phy_rxc) then
  123. rst_async_wr1 <= RESET_EXT;
  124. rst_async_wr2 <= rst_async_wr1;
  125. rst_async_wr3 <= rst_async_wr2;
  126. end if;
  127. end process;
  128. -- Asynchronous reset, synchronous release for rst_async_rd1, rst_async_rd2, rst_async_rd3
  129. process(RESET_EXT,sysclk)
  130. begin
  131. if RESET_EXT = '1' then
  132. rst_async_rd1 <= '1';
  133. rst_async_rd2 <= '1';
  134. rst_async_rd3 <= '1';
  135. elsif rising_edge(sysclk) then
  136. rst_async_rd1 <= RESET_EXT;
  137. rst_async_rd2 <= rst_async_rd1;
  138. rst_async_rd3 <= rst_async_rd2;
  139. end if;
  140. end process;
  141. rst_int_wr <= rst_async_wr3;
  142. rst_int_rd <= rst_async_rd3;
  143. --===============================================================
  144. -- eth_fifo_inst
  145. eth_fifo_instx: component fifo_8bit_2048
  146. port map(
  147. din => eth_fifo_wdata , -- in std_logic_vector(7 downto 0)
  148. wr_en => eth_fifo_wrreq , -- in std_logic
  149. wr_clk => eth_phy_rxc , -- in std_logic
  150. full => open , -- out std_logic
  151. dout => eth_fifo_rdata , -- out std_logic_vector(7 downto 0)
  152. rd_en => eth_fifo_rdreq , -- in std_logic
  153. rd_clk => sysclk , -- in std_logic
  154. empty => eth_fifo_empty , -- out std_logic
  155. rst => reset , -- in std_logic
  156. wr_data_count => open , -- out std_logic_vector(10 downto 0)
  157. rd_data_count => eth_fifo_rcnt -- out std_logic_vector(10 downto 0)
  158. );
  159. process(rst_int_wr,eth_phy_rxc)
  160. begin
  161. if rst_int_wr = '1' then
  162. eth_fifo_wdata <= (others => '0');
  163. eth_fifo_wrreq <= '0';
  164. elsif rising_edge(eth_phy_rxc) then
  165. eth_fifo_wdata <= eth_phy_rxd;
  166. eth_fifo_wrreq <= eth_phy_rxdv;
  167. end if;
  168. end process;
  169. process(rst_int_rd,sysclk)
  170. begin
  171. if rst_int_rd = '1' then
  172. eth_fifo_rdreq <= '0';
  173. eth_fifo_rdvld <= '0';
  174. elsif rising_edge(sysclk) then
  175. if eth_fifo_rcnt > 6 then
  176. eth_fifo_rdreq <= '1';
  177. elsif eth_fifo_rcnt = 1 then
  178. eth_fifo_rdreq <= '0';
  179. end if;
  180. eth_fifo_rdvld <= eth_fifo_rdreq;
  181. end if;
  182. end process;
  183. process(rst_int_rd,sysclk)
  184. begin
  185. if rst_int_rd = '1' then
  186. eth_rxd_sys <= (others => '0');
  187. eth_rxdv_sys <= '0';
  188. elsif rising_edge(sysclk) then
  189. eth_rxd_sys <= eth_fifo_rdata;
  190. eth_rxdv_sys <= eth_fifo_rdvld;
  191. end if;
  192. end process;
  193. end architecture;

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/206666
推荐阅读
相关标签
  

闽ICP备14008679号