返回介绍

19.2 接口语法

发布于 2020-09-09 22:55:55 字数 3782 浏览 866 评论 0 收藏 0

interface_declaration ::=      // from Annex A.1.3
    interface_nonansi_header [timeunits_declaration] {interface_item}
        endinterface [: interface_identifier]
  | interface_ansi_header [timeunits_declaration] {non_port_interface_item}
        endinterface [: interface_identifier]
  | {attribute_instance} interface interface_identifier(.*);
        [timeunits_declaration] {interface_item}
    endinterface [: interface_identifier]
  | extern interface_nonansi_header
  | extern interface_ansi_header

interface_nonansi_header ::=
    {attribute_instance} interface [lifetime] interface_identifier
        [parameter_port_list] list_of_ports;

interface_ansi_header ::=
    {attribute_instance} interface [lifetime] interface_identifier
        [parameter_port_list] [list_of_port_declarations];

modport_declaration ::= modport modport_item {, modport_item};  // from Annex A.2.9

modport_item ::= modport_identifier(modport_ports_declaration {, modport_ports_declaration})

modport_ports_declaration ::=
    {attribute_instance} modport_simple_ports_declaration
  | {attribute_instance} modport_hierarchical_ports_declaration
  | {attribute_instance} modport_tf_ports_declaration
  | {attribute_instance} modport_clocking_declaration

modport_clocking_declaration ::= clocking clocking_identifier

modport_simple_ports_declaration ::=
    port_direction modport_simple_port {, modport_simple_port}

modport_simple_port ::=
    port_identifier
  | .port_identifier([expression])

modport_hierarchical_ports_declaration ::=
    interface_instance_identifier[[constant_expression]].modport_identifier

modport_tf_ports_declaration ::=
    import_export modport_tf_port {, modport_tf_port}

modport_tf_port ::=
    method_prototype
  | tf_identifier

import_export ::= import | export

interface_instantiation ::=
    interface_identifier [parameter_value_assignment]
        hierarchical_instance {, hierarchical_instance};     // from Annex A.4.1.2

Syntax 19-1—Interface syntax (excerpt from Annex A)

The interface construct provides a new hierarchical structure. It can contain smaller interfaces and can be passed through ports.

The aim of interfaces is to encapsulate communication. At the lower level, this means bundling variables and wires in interfaces, and can impose access restrictions with port directions in modports. The modules can be made generic so that the interfaces can be changed. The following examples show these features. At a higher level of abstraction, communication can be done by tasks and functions. Interfaces can include task and function definitions, or just task and function prototypes (see Section 19.6.1 An example of using tasks in an interface) with the definition in one module (server/slave) and the call in another (client/master).

A simple interface declaration is as follows (see Syntax 19-1 for the complete syntax):

interface identifier;
    ...
    interface_items
    ...
endinterface [: identifier]

An interface can be instantiated hierarchically like a module, with or without ports. For example:

myinterface #(100) scalar1, vector[9:0];

In this example, 11 instances of the interface of type myinterface have been instantiated and the first parameter within each interface is changed to 100. One myinterface instance is instantiated with the name scalar1, and an array of 10 myinterface interfaces are instantiated with instance names vector[9] to vector[0].

Interfaces can be declared and instantiated in modules (either flat or hierarchical) but modules can neither be declared nor instantiated in interfaces.

The simplest use of an interface is to bundle wires, as is illustrated in the examples below.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文