请帮助我,不要阅读文件" mem.dat"

时间:2014-04-06 18:47:17

标签: file memory vhdl

描述记忆。 VHDL

library IEEE;
use IEEE.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity Memory is 
    generic(file_name: string:= "MEM.dat");
port (addr: in std_logic_vector(7 downto 0);
        data: out std_logic_vector(7 downto 0);
        rd: in std_logic;
        ld: in std_logic);
end Memory;

architecture Memory of Memory is
type t_rom_data is array (15 downto 0) of std_logic_vector(7 downto 0);
type rom_file_type is file of character;
file rom_file: rom_file_type;
signal rom_data: t_rom_data;
begin   
    process(addr,rd)
    variable i: natural;
    begin
        if rd = '1' then
            i := conv_integer(addr);
            data <= rom_data(i) after 5ns;
        else 
            data <= (others => 'Z');
        end if;
    end process;

    process(ld)
    variable c: character;
    begin
        if ld='1' then  file_open(rom_file,file_name,read_mode);
            for i in 0 to 15 loop
                for b in 7 downto 0 loop
                    c:='U';
                    if not(endfile(rom_file)) then  read(rom_file,c);
                        while not(endfile(rom_file)) and c/='0' and c/='1' and c/='Z' and c/='W'
                        and c/='L' and c/='H' and c/='-' and c/='X' and c/='U' loop
                            read(rom_file,c);
                        end loop;                   
                    end if; 

                    if c='0' then rom_data(i)(b) <= '0';
                    elsif c='1' then rom_data(i)(b) <='1';
                    elsif c='Z' then rom_data(i)(b) <='Z';
                    elsif c='W' then rom_data(i)(b) <='W';
                    elsif c='L' then rom_data(i)(b) <='L';
                    elsif c='H' then rom_data(i)(b) <='H';
                    elsif c='-' then rom_data(i)(b) <='-';
                    elsif c='X' then rom_data(i)(b) <='X';
                    else rom_data(i)(b) <='U';
                    end if;

                end loop;
            end loop;
            file_close(rom_file); 
        end if;`enter code here`
    end process;
end Memory;

错误是: 警告(10873):在MEMORY.vhd使用初始值X(不关心)net“rom_data [15] [7]”(17) 警告(10873):在MEMORY.vhd使用初始值X(不关心)“rom_data [15] [6]”网(17) 警告(10873):在MEMORY.vhd使用初始值X(不关心)net“rom_data [15] [5]”(17) 警告(10873):在MEMORY.vhd使用初始值X(不关心)net“rom_data [15] [4]”(17) 警告(10873):在MEMORY.vhd使用初始值X(不关心)net“rom_data [15] [3]”(17) 警告(10873):在MEMORY.vhd使用初始值X(不关心)net“rom_data [15] [2]”(17) 警告(10873):在MEMORY.vhd使用初始值X(不关心)net“rom_data [15] [1]”(17) 警告(10873):在MEMORY.vhd使用初始值X(不关心)net“rom_data [15] [0]”(17) 警告(10873):在MEMORY.vhd(17)使用初始值X(不关心)net“rom_data [14] [7]” 警告(10873):在MEMORY.vhd(17)使用初始值X(不关心)net“rom_data [14] [6]” 警告(10873):在MEMORY.vhd使用初始值X(不关心)“rom_data [14] [5]”

文件“mem.dat”与项目位于同一目录中。我在quartus工作

1 个答案:

答案 0 :(得分:1)

这个问题似乎是关于如何使用文件中的数据初始化ROM以进行综合。如果是这种情况,那么显然运行一个进程将数据加载到内存中(这需要文件在运行时可读)是行不通的。

然而,你可以做的是声明内存 - 不是SIGNAL而是CONSTANT,声明必须有一个初始化子句;这可以调用一个函数。并且因为初始化程序在综合期间进行评估,所以它可以打开,读取和关闭文件。

示例可能看起来像

type t_rom_data is array (15 downto 0) of std_logic_vector(7 downto 0);

function init_rom return t_rom_data is
   type rom_file_type is file of character;
   file rom_file: rom_file_type;
   variable temp : t_rom_data;
begin
   file_open(rom_file,file_name,read_mode);
   for i in 0 to 15 loop
      ...
      temp(i) := ...
   end loop;
   file_close(rom_file); 
   return temp;
end init_rom;

constant rom_data: t_rom_data := init_rom;

用你编写的ROM读取过程。