我应该在 VHDL 中创建一个具有可变数量的输入和输出的实体。该引脚数应从 GENERIC 结构中给出。让我们假设有这个代码:
entity HELLO is
GENERIC(NUM_INPUT: integer:=4;
NUM_OUTPUT: integer:=2
);
port(
input1 : in std_logic_vector(31 downto 0);
input2 : in std_logic_vector(31 downto 0);
input3 : in std_logic_vector(31 downto 0);
input4 : in std_logic_vector(31 downto 0);
out1 : out std_logic_vector(31 downto 0);
out2 : out std_logic_vector(31 downto 0)
);
end entity HELLO;
显然,手动编写它们(如上例所示)会使 GENERIC 构造无用。
我希望这 4 个输入和 2 个输出根据 GENERIC 信息自动生成。怎么做?
最佳答案
我认为实现这一点的最简单方法是为包中的 32 位字定义自定义数组类型,例如:
type WORD_ARRAY_type is array (integer range <>) of std_logic_vector (31 downto 0);
您的实体声明然后变为:
use work.HELLOPackage.all;
entity HELLO is
GENERIC (
NUM_INPUT : integer := 4;
NUM_OUTPUT : integer := 2
);
port (
input1 : in WORD_ARRAY_type(NUM_INPUT-1 downto 0);
out1 : out WORD_ARRAY_type(NUM_OUTPUT-1 downto 0)
);
end entity HELLO;
您还可以对输入和输出使用不受约束的数组:
entity HELLO is
GENERIC (
NUM_INPUT : integer := 4;
NUM_OUTPUT : integer := 2
);
port (
input1 : in WORD_ARRAY_type;
out1 : out WORD_ARRAY_type
);
end entity HELLO;
然后使用泛型使用这些端口。实例化实体时,只需连接具有正确维度的数组以匹配泛型。
关于generics - VHDL 中可变数量的输入和输出,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32562488/