【问题标题】:Get attribute of a field from a VHDL record type从 VHDL 记录类型中获取字段的属性
【发布时间】:2016-04-15 09:17:35
【问题描述】:

考虑以下 VHDL 记录:

type big_record_t is record
    field_a : unsigned(15 downto 0);
    field_b : unsigned(23 downto 0);
end record;

是否可以在实例化记录本身的情况下获取记录字段的属性?例如

signal ex : unsigned(big_record_t.field_a'range);

modelsim报如下错误:

(vcom-1260) Type mark (big_record_t) cannot be prefix of selected name.

我知道获取实例化信号的属性是可能的,但对于这种特定情况,我想从类型本身获取类型属性。

【问题讨论】:

    标签: attributes vhdl


    【解决方案1】:

    您不能在 type 上使用 'range 属性,这是您在代码中尝试执行的操作。如果你要做这样的事情:

    signal big_record_instance : big_record_t;
    signal ex : unsigned(big_record_instance.field_a'range);
    

    它应该可以工作,因为您现在正在尝试获取实例的范围,而不是类型。

    如果您没有实例,另一种方法可能是让您的宽度基于与您的记录类型定义相同的包中的常量,如下所示:

    constant field_a_width : integer := 16;
    
    type big_record_t is record
            field_a : std_logic_vector(field_a_width-1 downto 0);
            field_b : std_logic_vector(23 downto 0);
    end record;
    
    signal ex : std_logic_vector(field_a_width-1 downto 0);
    

    或许

    constant field_a_width : integer := 16;
    
    subtype field_a_type is std_logic_vector(field_a_width-1 downto 0);
    
    type big_record_t is record
            field_a : field_a_type;
            field_b : std_logic_vector(23 downto 0);
    end record;
    
    signal ex : field_a_type;
    

    查看 cmets 中的异常

    【讨论】:

    • 感谢您的反馈。我知道我可以在实例上做属性。在这种特定情况下,我想知道为什么我不能在类型上这样做。编译器应该可以使用所有类型信息。
    • @Maurice 信息可能在那里,但标准不支持您想要做的事情。我已经用另一个建议更新了我的答案。
    • 我已将您的答案标记为正确。我猜这个功能也没有添加到 VHDL2008 中。
    • @Maurice 基本正确。可以在实例以外的项目上使用'range'range 属性可用于标量和数组类型,但不适用于其他类型。例如,如果我定义了subtype my_range is range 0 to 31;,则定义了my_range'range。或者如果我定义了type my_array is array (0 to 15) of std_logic_vector(31 downto 0);,那么my_array'range 就被定义了。
    【解决方案2】:

    另一个建议是这样做:

    subtype field_a_range is range 15 downto 0;
    subtype field_b_range is range 31 downto 0:
    type big_record_t is record
        field_a : unsigned(field_a_range);
        field_b : unsigned(field_b_range);
    end record;
    

    然后您可以执行以下操作:

    signal ex : unsigned(field_a_range);
    

    另一个解决方法可能是使用一个有点傻的函数——使用一个函数。虽然这有效地创建了一个实例(虽然隐藏了一点)。

    function field_a_length return natural is
      variable tmp : big_record_t;
    begin
      return tmp.field_a'length;
    end function field_a_length;
    

    然后将其用作:

    signal ex : unsigned(field_a_length-1 downto 0);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-21
      • 2019-07-02
      • 1970-01-01
      • 1970-01-01
      • 2019-04-24
      • 1970-01-01
      • 1970-01-01
      • 2020-01-29
      相关资源
      最近更新 更多