【问题标题】:Variable number of inputs and outputs in VHDLVHDL中可变数量的输入和输出
【发布时间】:2015-09-14 10:25:05
【问题描述】:

我应该在 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 构造无用。

我希望根据 GENERIC 信息自动生成这 4 个输入和 2 个输出。怎么做?

【问题讨论】:

  • 您的实体标头在out2 接口元素声明之后的端口子句中有一个额外的分号。分号用作界面列表中的界面元素分隔符。从实用上讲,这允许单个词法元素(标记)在解析中向前看,以确定接口列表的末尾出现在哪里,分支上的分号或右括号。
  • 已更正,是分心错误

标签: generics vhdl


【解决方案1】:

我认为实现这一点的最简单方法是在包中为您的 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;

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-15
    • 1970-01-01
    • 1970-01-01
    • 2018-06-21
    • 1970-01-01
    • 1970-01-01
    • 2020-07-10
    相关资源
    最近更新 更多