我正在尝试使用RAM来读/写。我的地址是一个整数值,它应该是一个整数的内存。这是我的代码,但我一直收到错误。
这是来自我的数据路径,其中地址选择来自整数寄存器。
代码:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity Mem is
generic( width: integer:=4;
depth: integer:=4;
addr: integer:=2);
port( Clock: in std_logic;
Enable: in std_logic;
Read: in std_logic;
Write: in std_logic;
Read_Addr: in integer;
Write_Addr: in integer;
Data_in: in integer;
Data_out: out integer
);
end Mem;
--------------------------------------------------------------
architecture behav of Mem is
type ram_type is array (0 to 31) of
integer;
signal tmp_ram: ram_type;
begin
-- Read Functional Section
process(Clock, Read)
begin
if (Clock'event and Clock='1') then
if Enable='1' then
if Read='1' then
-- buildin function conv_integer change the type
-- from std_logic_vector to integer
Data_out <= tmp_ram(conv_integer(Read_Addr));
else
Data_out <= (Data_out'range => 'Z');
end if;
end if;
end if;
end process;
-- Write Functional Section
process(Clock, Write)
begin
if (Clock'event and Clock='1') then
if Enable='1' then
if Write='1' then
tmp_ram(conv_integer(Write_Addr)) <= Data_in;
end if;
end if;
end if;
end process;
end behav;
----------------------------------------------------------------
错误:
Error (10514): VHDL aggregate error at Mem.vhd(41): can't determine type of aggregate -- found 0 possible types
答案 0 :(得分:2)
您的错误代码是:
if Read='1' then
-- buildin function conv_integer change the type
-- from std_logic_vector to integer
Data_out <= tmp_ram(conv_integer(Read_Addr));
else
Data_out <= (Data_out'range => 'Z'); -- Faulty line
end if;
Data_out
是一个整数,而不是std_logic_vector
或派生类型。因此,它没有范围(只有数组,std_logic_vector
beeing被定义为std_logic
的数组。此外,它不能取'Z'
的值,因为它不是std_logic
; integers
只能分配整数值。
如果Data_out
enable
'1'
read
'0'
为std_logic_vector
,如果您需要signed/unsigned
成为高阻抗,则需要内存输出使用integers
或integers
。
此外,如果您的目标是综合,我建议您不要使用integers
而不使用范围。根据VHDL标准,signal x: integer range -4 to 3
是32位。综合工具可能优化网表并使用更少的位,但您不应指望它。约束signed/unsigned
(setMessage
)的范围或使用builder.setMessage("Please help us to track the route, has this route arrived the stop? ");
。