【问题标题】:How to constrain VHDL-2008 integer_vector?如何约束 VHDL-2008 integer_vector?
【发布时间】:2017-06-14 09:38:04
【问题描述】:

VHDL-2008 定义

type integer_vector is array (natural range <>) of integer

它可以用来创建不受约束的整数数组就好了:

signal sUnconsrainedIntA : integer_vector(0 to 1) := (others => 0);

但是,如何声明约束整数数组,例如:

-- does not work:
-- signal sConstrainedTestIntA : integer_vector(0 to 1) range 0 to 3 := (others => 0);
-- ** Error: filetest.vhd(65): Range constraints cannot be applied to array types.
-- ** Error: filetest.vhd(65): Range expression is type Integer; expecting type std.STANDARD.INTEGER_VECTOR

-- What you can do is:
type my_int_array is array (natural range <>) of integer range 0 to 3;
signal sConstrainedIntA : my_int_array(0 to 1) := (others => 0);

有没有办法在没有自定义类型的情况下约束数组中的整数?

【问题讨论】:

  • 我猜不是。正如您所写,integer_vector 是一个具有完整范围的整数数组。如果你想改变它,你必须自己定义一个不同的类型。
  • 如何定义一个自定义类型,然后可以在以后进行约束,例如类型 slv_array 是 std_logic_vector 的数组(自然范围 );信号 sSlvA : slv_array(0 to 1)(1 downto 0) := (others => (others => '0'));
  • 我不确定 VHDL-2008,但在此之前,你不能这样做。而且我想VHDL-2008仍然不可能。
  • 类型integer是受约束类型(标量类型、数值类型),而std_logic_vector是枚举类型(std_logic)的无约束数组类型。

标签: vhdl


【解决方案1】:

VHDL 2008 支持包通用参数。您可以尝试以下方法:

package foo_pkg is
    generic(l, h: integer);
    subtype my_integer is integer range l to h;
    type my_integer_vector is array(natural range <>) of my_integer;
end package foo_pkg;

package foo_pkg_m17_p39 is new work.foo_pkg
    generic map(l => -17, h => 39);

package foo_pkg_p57_p134 is new work.foo_pkg
    generic map(l => 57, h => 134);

entity foo is
    port(iv1: work.foo_pkg_m17_p39.my_integer_vector(0 to 7);
         iv2: work.foo_pkg_p57_p134.my_integer_vector(0 to 7)
     );
end entity foo;

对用户不太友好,因为每个整数约束都需要一个包实例化声明。但我发现它与您要求的最相似......

即使它看起来比您预期的要复杂,它仍然允许您为 my_integer_vector 的所有变体分解您的自定义代码。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-14
    • 2013-07-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多