VHDL 中可变数量的输入和输出

Variable number of inputs and outputs in VHDL

我应该在 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;

然后使用泛型处理这些端口。实例化实体时,只需连接一个具有正确维度的数组即可匹配泛型。