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

标签 generics 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;

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

关于generics - VHDL 中可变数量的输入和输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32562488/

相关文章:

java - 覆盖泛型方法

compilation - VHDL - 仅在架构 header 中使用的函数是否占用 FPGA 逻辑?

simulation - 实体中 "in"端口的数量可变?

vhdl - 在vivado中显示定点值

controller - 两个 STD_LOGIC_VECTORS 的按位与运算

vhdl - 何时使用VHDL库std_logic_unsigned和numeric_std?

java - ArrayList 的 get() 中的泛型是如何工作的

swift - 如何强制可以从 Swift 中的字符串解析作为参数传入的类?

c# - 声明 C# 泛型类型方法

java - 静态方法中的有界类型参数