从文件加载VHDL sram
我很好奇为什么下面的代码不能在 VHDL 中加载 sram 内存阵列?我缺少什么?
这是我的输入文件: ram_image.hex
be
ef
ca
fe
34
23
这是我尝试使用不纯函数 load_sram_hex 加载 my_ram 的代码。
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_textio.all;
use std.textio.all;
entity sram is
end entity;
architecture beh of sram is
constant sram_dw :integer := 8;
constant sram_aw :integer := 4;
constant sram_depth :integer := 2**sram_aw - 1;
type sram_t is array (0 to sram_depth-1) of std_logic_vector(sram_dw downto 0);
impure function load_sram_hex(filename : in string) return sram_t is
file f :text is in filename;
variable b :line;
variable mem :sram_t;
variable good :boolean;
variable m :line;
begin
for i in sram_t'range loop
readline(f, b);
hread(b, mem(i), good);
write(m, string'("HERE=> ") );
hwrite(m, mem(i));
writeline(output, m);
if (not good) then
exit;
end if;
end loop;
return mem;
end function;
signal my_ram : sram_t := load_sram_hex("ram_image.hex");
begin
process
variable m :line;
begin
wait for 10 ns;
for i in sram_t'range loop
write(m, string'("ram["));
write(m, i);
write(m, string'("] = "));
hwrite(m, my_ram(i));
writeline(output, m);
end loop;
wait for 1000 ns;
report "just kidding! end of testbench" severity failure;
end process;
end architecture;
在这里你可以看到 vhdl 模拟的输出只是 x 甚至很难我加载内存......
## run all
ram[0] = XXX
ram[1] = XXX
ram[2] = XXX
ram[3] = XXX
ram[4] = XXX
ram[5] = XXX
ram[6] = XXX
ram[7] = XXX
ram[8] = XXX
ram[9] = XXX
ram[10] = XXX
ram[11] = XXX
ram[12] = XXX
ram[13] = XXX
ram[14] = XXX
Failure: just kidding! end of testbench
Time: 1010 ns Iteration: 0 Process: /sram/line__52 File: sram.vhd
I was curious why the following code doesn't work to load an sram memory array in VHDL? What am I missing?
here's my input file: ram_image.hex
be
ef
ca
fe
34
23
Here's the code where i attempt to load my_ram using the impure function load_sram_hex.
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_textio.all;
use std.textio.all;
entity sram is
end entity;
architecture beh of sram is
constant sram_dw :integer := 8;
constant sram_aw :integer := 4;
constant sram_depth :integer := 2**sram_aw - 1;
type sram_t is array (0 to sram_depth-1) of std_logic_vector(sram_dw downto 0);
impure function load_sram_hex(filename : in string) return sram_t is
file f :text is in filename;
variable b :line;
variable mem :sram_t;
variable good :boolean;
variable m :line;
begin
for i in sram_t'range loop
readline(f, b);
hread(b, mem(i), good);
write(m, string'("HERE=> ") );
hwrite(m, mem(i));
writeline(output, m);
if (not good) then
exit;
end if;
end loop;
return mem;
end function;
signal my_ram : sram_t := load_sram_hex("ram_image.hex");
begin
process
variable m :line;
begin
wait for 10 ns;
for i in sram_t'range loop
write(m, string'("ram["));
write(m, i);
write(m, string'("] = "));
hwrite(m, my_ram(i));
writeline(output, m);
end loop;
wait for 1000 ns;
report "just kidding! end of testbench" severity failure;
end process;
end architecture;
Here you can see the output of the vhdl simulation is just x's even tough i loaded the memory...
## run all
ram[0] = XXX
ram[1] = XXX
ram[2] = XXX
ram[3] = XXX
ram[4] = XXX
ram[5] = XXX
ram[6] = XXX
ram[7] = XXX
ram[8] = XXX
ram[9] = XXX
ram[10] = XXX
ram[11] = XXX
ram[12] = XXX
ram[13] = XXX
ram[14] = XXX
Failure: just kidding! end of testbench
Time: 1010 ns Iteration: 0 Process: /sram/line__52 File: sram.vhd
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这对我来说在 vivado 模拟器中有效:
This worked in vivado simulator for me: