VHDL使用MIF文件预加载RAM内存
我试图用VHDL实现内存,在DE2板上测试时,我想用生成的值预加载内存。我第一次尝试通过读取文本文件来实现这一点,但没有成功,因为无法将文本文件加载到FPGA板上。所以我转向mif文件。但是,我不知道如何让vhdl/quartus ii将我生成的MIF文件与我创建的RAM相关联 我还尝试使用1端口RAM LPM,但因为它对读取和写入都进行了时钟设置,这导致它提供数据的速度不够快,无法发挥作用 下面是我创建的RAM的代码:VHDL使用MIF文件预加载RAM内存,vhdl,ram,modelsim,quartus,Vhdl,Ram,Modelsim,Quartus,我试图用VHDL实现内存,在DE2板上测试时,我想用生成的值预加载内存。我第一次尝试通过读取文本文件来实现这一点,但没有成功,因为无法将文本文件加载到FPGA板上。所以我转向mif文件。但是,我不知道如何让vhdl/quartus ii将我生成的MIF文件与我创建的RAM相关联 我还尝试使用1端口RAM LPM,但因为它对读取和写入都进行了时钟设置,这导致它提供数据的速度不够快,无法发挥作用 下面是我创建的RAM的代码: library ieee; use ieee.std_logic_1164
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use std.textio.all;
entity instruction_memory is
port (
input_address : in std_logic_vector(31 downto 0);
opcode : out std_logic_vector(31 downto 0)
);
end instruction_memory;
architecture archInstruction_Memory of instruction_memory is
subtype word_t is std_logic_vector(31 downto 0);
type ram_t is array(0 to 4095) of Reichman_word_t;
impure function ReadMemFile(FileName : STRING) return ram_t is
file FileHandle : TEXT open READ_MODE is FileName;
variable CurrentLine : LINE;
variable TempWord : bit_vector(31 downto 0);
variable Result : ram_t := (others => (others => '0'));
begin
for i in 0 to 4095 loop
exit when endfile(FileHandle);
readline(FileHandle, CurrentLine);
read(CurrentLine, TempWord);
Result(i) := to_stdlogicvector(TempWord);
end loop;
return Result;
end function;
signal ram : ram_t := ReadMemFile("instructions_memory.txt");
attribute ram_init_file : string;
attribute ram_init_file of ram : signal is "instructions_memory.mif";
begin
opcode <= ram(to_integer(unsigned(input_address(31 downto 0))));
end archInstruction_Memory;
ieee库;
使用ieee.std_logic_1164.all;
使用ieee.numeric_std.all;
使用std.textio.all;
实体指令_内存不可用
港口(
输入地址:标准逻辑向量(31到0);
操作码:输出标准逻辑向量(31到0)
);
终端指令存储器;
指令存储器的体系结构指令存储器是
子类型字是标准逻辑向量(31到0);
类型ram_t是Reichman_word_t的数组(0到4095);
不纯函数ReadMemFile(文件名:STRING)返回ram\u t为
文件文件句柄:文本打开读取模式为文件名;
可变电流线路:线路;
可变临时字:位_向量(31到0);
变量结果:ram_t:=(其他=>(其他=>“0”);
开始
对于0到4095循环中的i
结束文件(FileHandle)时退出;
readline(文件句柄,CurrentLine);
读取(当前行、临时字);
结果(i):=发送至标准逻辑向量机(TempWord);
端环;
返回结果;
末端功能;
信号ram:ram_t:=ReadMemFile(“instructions_memory.txt”);
属性ram_init_file:string;
ram的属性ram_init_文件:信号为“instructions_memory.mif”;
开始
操作码我正在使用tcl脚本将二进制数据(代码)转换为VHDL常量,该常量可用于生成ROM:
package require cmdline
post_message "embed_m68k.tcl"
exec /bin/bash -c "(cd m68k; make)"
set binfile m68k/simple.bin
set fp [open $binfile r]
fconfigure $fp -translation binary
set bindata [read $fp]
close $fp
set filename simple.vhd
set date [clock format [clock seconds] -format { %a, %Y-%m-%d, %H:%M }]
set file [open $filename w]
set script [info script]
puts $file "library ieee;"
puts $file "use ieee.std_logic_1164.all;"
puts $file ""
puts $file " -- VHDL representation of $binfile"
puts $file " -- generated by $script on $date"
puts $file " -- m68k executable as preloaded RAM contents"
puts $file ""
puts $file "package m68k_binary is"
puts $file " subtype ubyte is std_logic_vector(7 downto 0);"
puts $file " type ubyte_array is array (natural range <>) of ubyte;"
puts $file ""
puts $file " constant m68k_binary : ubyte_array :="
puts $file " ("
puts -nonewline $file " "
set len [string length $bindata]
for {set i 0} {$i < $len} {incr i} {
set char [string index $bindata $i]
binary scan $char H2 byte
puts -nonewline $file "x\""
puts -nonewline $file $byte
puts -nonewline $file "\""
if { ! ([expr $i + 1] == $len) } {
puts -nonewline $file ", "
}
if { [expr ($i + 1) % 8] == 0 } {
puts $file ""
puts -nonewline $file " "
}
}
puts $file ""
puts $file " );"
puts $file "end package m68k_binary;"
close $file
然后,在合成过程开始时,将自动执行PRE\u FLOW\u SCRIPT\u文件。只需将生成的.vhd文件包含到您的项目中。Altera不支持textio进行内存初始化。它确实支持您使用的属性。但是,您的代码不会推断ram,因为它不是同步的。阅读RAM推断的综合指南。注意:使用attribute方法将意味着在模拟过程中不填充RAM。注意,除了问题中显示的属性之外,Xilinx还支持该方法。是否有方法使用允许预加载内存的异步RAM?同步RAM在异步RAM解决的设计的其他部分给我带来了麻烦。
set_global_assignment -name PRE_FLOW_SCRIPT_FILE "quartus_sh:precmd.tcl"