了解类型和子类型与信号

Understanding types and subtypes vs. signals

我目前在 VHDL 模拟器的两个版本之间存在错误

我的代码(触发错误的简单版本)

library ieee;
use ieee.std_logic_1164.all;

entity test is
end;

architecture test of test is
    constant mpc_ibif_data_width          : integer := 16;
    subtype  t_mpc_ibif_data              is std_logic_vector (mpc_ibif_data_width - 1 downto 0);

    type t_device_2_mpc_ibif is
      record
        rd_data     : t_mpc_ibif_data;  --
        rd_data_en  : std_logic;        -- '1': rd_data must be driven to the CPU
        berr_n      : std_logic;        --
    end record;

    type  t_device_2_mpc_ibif_array    is array (natural range <>) of t_device_2_mpc_ibif;
    signal flash_cnt_2_mpc_o : t_device_2_mpc_ibif;
begin
    process 
    begin
        wait for 10 ns;
        assert flash_cnt_2_mpc_o.rd_data = t_device_2_mpc_ibif.rd_data'(others => '0') report"flash_cnt_2_mpc_o.rd_data should have been deasserted" severity error;
        wait;
    end process;
end;

在第一个版本中以下是合法的

assert flash_cnt_2_mpc_o.rd_data = t_device_2_mpc_ibif.rd_data'(others => '0') report"flash_cnt_2_mpc_o.rd_data should have been deasserted" severity error;

但是在新版本中,我在同一行上得到 "Type Error"。具体在

t_device_2_mpc_ibif.rd_data'(others => '0') 

我将此创建为供应商的错误,供应商告诉我使用以下代码:

assert flash_cnt_2_mpc_o.rd_data = t_mpc_ibif_data'(others => '0') report"flash_cnt_2_mpc_o.rd_data should have been deasserted" severity error;

基于这些论点

In this context the type is expected not its selection.


以下是我不明白的地方,希望得到解答:

据我了解,有类型和子类型。子类型继承自类型

所以当你创建一个信号时

signal NameOfSignal : std_logic_vector(1 downto 0)

这个信号现在继承了 std_logic_vector 的所有内容加上它的受限 IE,它是 std_logic_vector.

类型的 "subtype"

而且无论信号是否在记录中都不应该改变这个事实。

我问了这个并得到了以下答案:

t_device_2_mpc_ibif.rd_data It is not type_name neither subtype_name but selected name (element name of record).

但在我的世界里,这应该无关紧要,因为信号(元素)继承了所有类型的方法。

请纠正我,因为我显然误解了一些东西

编辑:我使用了 VHDL2008

问候 安德斯

您的问题代码:

t_device_2_mpc_ibif.rd_data'(others => '0') 

在这一行中,您试图将 (others => '0') 限定为 type t_device_2_mpc_ibif.rd_data。问题是 rd_data 不是类型 ,因此您不能用它来限定任何东西,这也是技术支持所说的。 "qualify this as the same type as the supplied signal".

没有语法

示例:

signal foo : std_logic_vector (1 downto 0);
subtype MyType is std_logic_vector (1 downto 0);
signal bar : MyType;

...

-- Simple assignment, OK
foo <= "00";

-- Qualify the literal "00" as a type std_logic_vector, OK
foo <= std_logic_vector'("00");

-- Simple assignment; subtypes have automatic conversion to/from the parent type, OK
bar <= "00";

-- Qualify the literal "00" as type 'foo', not OK, since 'foo' isn't a type.
bar <= foo'("00");

-- Qualify the literal "00" as type 'MyType', OK.
bar <= MyType'("00");

-- Qualify the literal "00" as type 'bar', not OK, since 'bar' is not a type.
bar <= bar'("00");

此问题与子类型或记录无关。如果您的原始代码在较旧的工具版本中工作,这是一个错误。

Here is what I do not understand and want an answer to:

To my understanding there are types and subtypes. subtypes inherit from types

So when you create a signal

    signal NameOfSignal : std_logic_vector(1 downto 0)

This signal now inherit all from std_logic_vector plus its contrained IE it's a "subtype" of the type std_logic_vector.

And regardless of the signal is in a record or not should not change this fact.

I asked this and got the following answer:

t_device_2_mpc_ibif.rd_data It is not type_name neither subtype_name but selected name (element name of record).

但在我的世界中,这应该无关紧要,因为信号(元素)继承了所有类型的方法。

请纠正我,因为我显然误解了一些东西

首先,在 IEEE Std 1076-2008(LRM)中,您会发现唯一提到 inheritance 的地方是对 VHPI 的引用,此处不适用。此外,您发现 inherit 的唯一其他地方是在属性规范 (7.2) 的描述中。

存在一个基本问题,即试图在 LRM 之外叠加语言和概念,LRM 是 VHDL 语言的正式规范。

正如您的供应商所指出的,并且受 LRM(5.3.3 记录类型)支持,标识符 rd_data 与元素声明的子类型指示不同。

您还可以注意到元素声明不同于子类型声明 (6.3)。

9.3.5 限定表达式

A qualified expression is a basic operation (see 5.1) that is used to explicitly state the type, and possibly the subtype, of an operand that is an expression or an aggregate.

qualified_expression ::=
      type_mark ' ( expression )
    | type_mark ' aggregate

The operand shall have the same type as the base type of the type mark. The value of a qualified expression is the value of the operand. The evaluation of a qualified expression evaluates the operand and converts it to the subtype denoted by the type mark.

因此,可以在限定表达式中使用的内容取决于可接受的 type_mark。

这就是 6.3 子类型声明:

type_mark ::=
      type_name
    | subtype_name

以及随附的文字:

A type mark denotes a type or a subtype. If a type mark is the name of a type, the type mark denotes this type and also the corresponding unconstrained subtype. The base type of a type mark is, by definition, the base type of the type or subtype denoted by the type mark.

如果我们查看 subtype_declaration,我们会发现子类型的名称是一个标识符:

subtype_declaration ::=
    subtype identifier is subtype_indication ;

如果我们查看 6.2 类型声明:

type_declaration ::=
      full_type_declaration
    | incomplete_type_declaration

full_type_declaration ::=
    type identifier is type_definition ;

type_definition ::=
      scalar_type_definition
    | composite_type_definition
    | access_type_definition
    | file_type_definition
    | protected_type_definition

我们看到声明的类型名称是一个标识符。

如果我们查看 15. 词汇元素,15.4 标识符,我们会发现标识符是一个词汇元素,而所选名称不合格,至少由三个词汇元素组成(请参阅 8.3 所选名称)。

通过查看 16.2 预定义属性,您还会发现没有可帮助确定记录元素类型的预定义属性。

简单地说类型或子类型不是 class。 VHDL中有实体classes用于描述属性中的声明名称(见7.2属性规范):

entity_specification ::=
    entity_name_list : entity_class

entity_class ::=
      entity
    | architecture
    | configuration
    | procedure
    | function
    | package
    | type
    | subtype
    | constant
    | signal
    | variable
    | component
    | label
    | literal
    | units
    | group
    | file
    | property
    | sequence

并且有对象 classes(见 6.4.2 对象声明):

object_declaration ::=
      constant_declaration
    | signal_declaration
    | variable_declaration
    | file_declaration

其中只有信号表现出 OOP 特性,具体取决于显式或隐式指定的敏感列表(对其有正式定义的语法和语义,理解可能需要通读 LRM)。

简而言之,不要试图将在其他地方获得的概念叠加到 VHDL 上。

Peter Ashenden 和 Jim Lewis 的书 'VHDL-2008 Just the New Stuff' 第 9.3 节限定表达式子类型中提到了 -2008 和之前 LRM 修订版之间的区别,并且 scary_jeff 注释不适用于此处。这是关于类型标记中的类型和子类型名称。