VHDL中的BRAM_INIT

bof*_*fin 4 embedded fpga vhdl xilinx

我正在模拟基于处理器的设计,其中程序存储器内容保存在BRAM中.我正在使用VHDL(推断BRAM)实现程序存储器.我试图避免使用CoreGen,因为我想保持设计的可移植性.最终这个设计将转到FPGA.

我想看看是否有办法使用VHDL泛型初始化BRAM的内存内容?我知道Coregen使用COE文件来初始化BRAM但是我们有基于VHDL代码的方法吗?

让我知道您的替代建议.

Jos*_*osh 10

是的,这当然是可能的.请参阅Xilinx综合工具(XST)用户指南,特别是第187页.

他们建议执行此操作的代码如下所示.他们在用户指南中有关于将要读取的文件格式的注释.请注意,此代码不直接使用泛型,但我可以想象您可以设置常量或泛型来保存文件名...

--
-- Initializing Block RAM from external data file
--
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use std.textio.all;

entity rams_20c is
port(clk : in std_logic;
   we : in std_logic;
   addr : in std_logic_vector(5 downto 0);
   din : in std_logic_vector(31 downto 0);
   dout : out std_logic_vector(31 downto 0));
end rams_20c;
architecture syn of rams_20c is
   type RamType is array(0 to 63) of bit_vector(31 downto 0);
   impure function InitRamFromFile (RamFileName : in string) return RamType is
      FILE RamFile : text is in RamFileName;
      variable RamFileLine : line;
      variable RAM : RamType;
   begin
      for I in RamType’range loop
         readline (RamFile, RamFileLine);
         read (RamFileLine, RAM(I));
      end loop;
      return RAM;
   end function;
signal RAM : RamType := InitRamFromFile("rams_20c.data");
begin
   process (clk)
   begin
      if clk’event and clk = ’1’ then
         if we = ’1’ then
            RAM(conv_integer(addr)) <= to_bitvector(din);
         end if;
         dout <= to_stdlogicvector(RAM(conv_integer(addr)));
      end if;
   end process;
end syn;
Run Code Online (Sandbox Code Playgroud)