如果您打算在设备中推断BRAM,则无法重置。重置BRAM作为设备配置的一部分完成。你总是可以写零(或者你的初始状态回到内存重新初始化)
但是,如果您不关心它是否会被合成到BRAM中,我认为最干净的方法是在您的系统中添加一个重置端口并更改您的过程以将重置考虑在内。如果要重置内存,请在输入端口应用重置。
library IEEE; use IEEE.STD_LOGIC_1164.ALL; use ieee.numeric_std.all; entity Ram is Port( clk : in std_logic; rstn : in std_logic; address : in std_logic_vector(4 downto 0); write_en : in std_logic; data_in : in std_logic_vector(15 downto 0); data_out : out std_logic_vector(15 downto 0) ); end Ram; architecture Behavioral of Ram is type ram_type is array(0 to 23) of std_logic_vector(15 downto 0); signal Memory : ram_type; begin process(clk) begin if(rising_edge(clk)) then if(rstn ='0') then Memory <= (OTHERS => (OTHERS => '0')); elsif(write_en = '1') then Memory(to_integer(unsigned(address))) <= data_in; end if; data_out <= Memory(to_integer(unsigned(address))); end if; end process; end behavioral;
您的代码示例的另一个注释。如果您打算推断BRAM,您的代码是“先写后读”。根据WP231,这将导致较慢的BRAM性能( https://www.xilinx.com/support/documentation/white_papers/wp231.pdf )