重新填充 Ram vhdl

Refilling Ram vhdl

在写入Ram的每个地址然后读取Ram的每个地址后,我将如何重新初始化Ram以便当我再次写入它时它会像第一次写入一样开始或者换句话说,一个干净的石板。

细分:

1) 写入 RAM

2) 从 Ram 读取

3) 将所有 ram 值设置回 0?或者我可以继续提供地址 = 0 再次从 0-23 开始写入吗?

这是我的 Ram:

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.numeric_std.all;

entity Ram is
Port(   
    clk       : 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(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,则无法重置。重置 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,您的代码是 "read-before-write"。根据 WP231 (https://www.xilinx.com/support/documentation/white_papers/wp231.pdf)

,这将导致 BRAM 性能降低