我想拥有一个包含依赖于泛型的类型的程序包,以便可以在项目中使用它们。但是我在端口声明中使用这些依赖类型时遇到了麻烦:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
package dependent_types is
generic (generic_value : natural);
subtype dependent_type is std_ulogic_vector (generic_value - 1 downto 0);
end package;
use work.all;
entity dependent_entity_with_dependent_port is
generic (generic_value : natural);
package instantiated_types is new dependent_types
generic map (generic_value => generic_value);
use instantiated_types.all;
port (dependent_port : out dependent_type);
end dependent_entity_with_dependent_port;
似乎实体声明部分(包实例化,use子句)必须在端口声明之后。这样可以防止使用依赖于实体泛型的泛型包中定义的类型。
有什么办法可以做到这一点?
答案 0 :(得分:0)
我认为不可能做您想做的-将程序包的泛型设置为与普通的泛型相等,然后将其用作端口。但是,您可以在这样的程序包中使用延迟常量:
此代码仅编译一次且稳定:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
package dependent_types is
generic (generic_value : natural);
subtype dependent_type is std_ulogic_vector (generic_value - 1 downto 0);
end package;
package constants is
constant generic_value : natural;
end package;
然后每次常量更改时都需要重新编译此代码:
package body constants is
constant generic_value : natural := 16;
end package body ;
use work.all;
use work.constants.all;
package instantiated_types is new dependent_types
generic map (generic_value => generic_value);
use work.instantiated_types.all;
entity dependent_entity_with_dependent_port is
port (dependent_port : out dependent_type);
end dependent_entity_with_dependent_port;
architecture A of dependent_entity_with_dependent_port is
begin
end;