首页 > 解决方案 > VHDL 在端口规范中使用依赖的泛型类型

问题描述

我想要一个包含依赖泛型的类型的包,以便我可以在项目中使用它们。但是我在端口声明中使用这些依赖类型时遇到了麻烦:

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;

似乎实体声明部分(包实例化、使用子句)必须在端口声明之后。这可以防止使用在依赖于实体泛型的泛型包中定义的类型。

有什么办法可以做到这一点?

标签: genericsvhdl

解决方案


我认为不可能做你想做的事 - 将包泛型设置为普通泛型,然后将其用作端口。但是,您可以在这样的包中使用延迟常量:

这段代码编译一次并且很稳定:

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;

https://www.edaplayground.com/x/3vfd


推荐阅读