📄 00214.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
<html>
<head>
<title>19.2 接口语法</title>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312" />
<meta name="generator" content="Doc-O-Matic" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<link rel="STYLESHEET" href="default.css" type="text/css" />
<script type="text/javascript" src="scripts.js"></script>
</head>
<body class="Element700" onload="onBodyLoadEx('systemverilog31a.html', 'topic', '00214.html');" onmousedown="onBodyMouseDown();">
<!-- Begin Popups -->
<div class="Element801" id="popup00399">
<div class="Element800">
<div class="Element14">
链接</div>
<div class="Element11">
<div class="Element10">
<a href="00866.html" target="topic">第十九章 接口</a>, <a href="00958.html" target="topic">主题</a></div>
</div>
</div>
</div>
<!-- End Popups -->
<!-- Begin Page Header -->
<div class="Element710" id="areafixed">
<div class="Element92">
<table width="100%" cellspacing="0" cellpadding="0">
<tr><td width="33%">
<div class="Element1">
<a href="#" onmousedown="showPopup(this, 'popup00399');"><img src="seealsolink.png" border="0" alt="" title=""></a> SystemVerilog 3.1a语言参考手册</div>
</td><td width="34%">
<div class="Element2">
</div>
</td><td width="33%">
<div class="Element90">
<a href="00213.html" target="topic"><img src="btn_prev_lightblue.gif" border="0" alt="Previous" title="Previous" onmouseover="switchImage(this, 'btn_prev_lightblue_hover.gif');" onmouseout="switchImage(this, 'btn_prev_lightblue.gif');"></a><a href="00866.html" target="topic"><img src="btn_up_lightblue.gif" border="0" alt="Up" title="Up" onmouseover="switchImage(this, 'btn_up_lightblue_hover.gif');" onmouseout="switchImage(this, 'btn_up_lightblue.gif');"></a><a href="00215.html" target="topic"><img src="btn_next_lightblue.gif" border="0" alt="Next" title="Next" onmouseover="switchImage(this, 'btn_next_lightblue_hover.gif');" onmouseout="switchImage(this, 'btn_next_lightblue.gif');"></a></div>
</td></tr></table><div class="Element5">
19.2 接口语法</div>
</div>
</div>
<!-- End Page Header -->
<!-- Begin Client Area -->
<div class="Element720" id="areascroll">
<div class="Element721">
<!-- Begin Page Content -->
<div class="Element58">
<a name="描述"></a><div class="Element11">
<div class="Element10">
<div class="Element170">
<a href="#" onclick="CopyElementToClipboard('code00825');">Copy Code</a></div>
<div class="Element13"><div class="Element12" id="code00825"><pre class="Element12">interface_declaration ::= // from Annex A.1.3
interface_nonansi_header [timeunits_declaration] {interface_item}
<strong><span style="color: #FF0000">endinterface</span></strong> [<strong><span style="color: #FF0000">:</span></strong> interface_identifier]
| interface_ansi_header [timeunits_declaration] {non_port_interface_item}
<strong><span style="color: #FF0000">endinterface</span></strong> [<strong><span style="color: #FF0000">:</span></strong> interface_identifier]
| {attribute_instance} <strong><span style="color: #FF0000">interface</span></strong> interface_identifier<strong><span style="color: #FF0000">(.*);</span></strong>
[timeunits_declaration] {interface_item}
<strong><span style="color: #FF0000">endinterface</span></strong> [<strong><span style="color: #FF0000">:</span></strong> interface_identifier]
| <strong><span style="color: #FF0000">extern</span></strong> interface_nonansi_header
| <strong><span style="color: #FF0000">extern</span></strong> interface_ansi_header
interface_nonansi_header ::=
{attribute_instance} <strong><span style="color: #FF0000">interface</span></strong> [lifetime] interface_identifier
[parameter_port_list] list_of_ports<strong><span style="color: #FF0000">;</span></strong>
interface_ansi_header ::=
{attribute_instance} <strong><span style="color: #FF0000">interface</span></strong> [lifetime] interface_identifier
[parameter_port_list] [list_of_port_declarations]<strong><span style="color: #FF0000">;</span></strong>
modport_declaration ::= modport modport_item {<strong><span style="color: #FF0000">,</span></strong> modport_item}<strong><span style="color: #FF0000">; </span></strong>// from Annex A.2.9
modport_item ::= modport_identifier<strong><span style="color: #FF0000">(</span></strong>modport_ports_declaration {<strong><span style="color: #FF0000">,</span></strong> modport_ports_declaration}<strong><span style="color: #FF0000">)</span></strong>
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 {<strong><span style="color: #FF0000">,</span></strong> modport_simple_port}
modport_simple_port ::=
port_identifier
| <strong><span style="color: #FF0000">.</span></strong>port_identifier<strong><span style="color: #FF0000">(</span></strong>[expression]<strong><span style="color: #FF0000">)</span></strong>
modport_hierarchical_ports_declaration ::=
interface_instance_identifier[<strong><span style="color: #FF0000">[</span></strong>constant_expression<strong><span style="color: #FF0000">]</span></strong>]<strong><span style="color: #FF0000">.</span></strong>modport_identifier
modport_tf_ports_declaration ::=
import_export modport_tf_port {<strong><span style="color: #FF0000">,</span></strong> modport_tf_port}
modport_tf_port ::=
method_prototype
| tf_identifier
import_export ::= <strong><span style="color: #FF0000">import</span></strong> | <strong><span style="color: #FF0000">export</span></strong>
interface_instantiation ::=
interface_identifier [parameter_value_assignment]
hierarchical_instance {<strong><span style="color: #FF0000">,</span></strong> hierarchical_instance}<strong><span style="color: #FF0000">; </span></strong>// from Annex A.4.1.2</pre></div></div>
<p class="Element10" style="text-align: center">
<strong>Syntax 19-1—Interface syntax (excerpt from Annex A)</strong></p><p class="Element10">
</p>
<p class="Element10">
The interface construct provides a new hierarchical structure. It can contain smaller interfaces and can be passed through ports. </p>
<p class="Element10">
</p>
<p class="Element10">
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). </p>
<p class="Element10">
</p>
<p class="Element10">
A simple interface declaration is as follows (see Syntax 19-1 for the complete syntax): </p><div class="Element170">
<a href="#" onclick="CopyElementToClipboard('code00826');">Copy Code</a></div>
<div class="Element13"><div class="Element12" id="code00826"><pre class="Element12">interface identifier;
...
interface_items
...
endinterface [: identifier]</pre></div></div>
<p class="Element10">
An interface can be instantiated hierarchically like a module, with or without ports. For example: </p><div class="Element170">
<a href="#" onclick="CopyElementToClipboard('code00827');">Copy Code</a></div>
<div class="Element13"><div class="Element12" id="code00827"><pre class="Element12">myinterface #(100) scalar1, vector[9:0];</pre></div></div>
<p class="Element10">
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]. </p>
<p class="Element10">
</p>
<p class="Element10">
Interfaces can be declared and instantiated in modules (either flat or hierarchical) but modules can neither be declared nor instantiated in interfaces. </p>
<p class="Element10">
</p>
<p class="Element10">
The simplest use of an interface is to bundle wires, as is illustrated in the examples below.</p></div>
</div>
<a name="Group"></a><div class="Element14">
<a onclick="toggleVisibilityStored('Group');" class="a_Element14"><img src="sectionminus.png" border="0" alt="" title="" id="imgGroup">Group</a></div>
<div id="divGroup">
<div class="Element11">
<div class="Element10">
<p class="Element10">
<a href="00866.html" target="topic">第十九章 接口</a></p></div>
</div>
</div>
<a name="主题"></a><div class="Element14">
<a onclick="toggleVisibilityStored('主题');" class="a_Element14"><img src="sectionminus.png" border="0" alt="" title="" id="img主题">主题</a></div>
<div id="div主题">
<div class="Element11">
<div class="Element10">
<div class="Element212">
<div class="TableDiv">
<table cellspacing="0" class="Table0">
<tr>
<td class="Element200" valign="top" width="50%">
<div class="Element201">
主题 </div></td><td class="Element204" valign="top" width="50%">
<div class="Element205">
描述 </div></td></tr><tr>
<td class="Element202" valign="top" width="50%">
<div class="Element203">
<a href="00215.html" target="topic">19.2.1 Example without using interfaces</a> </div></td><td class="Element206" valign="top" width="50%">
<div class="Element207">
This example shows a simple bus implemented without interfaces. Note that the logic type can replace wire and reg if no resolution of multiple drivers is needed. </div></td></tr><tr>
<td class="Element202" valign="top" width="50%">
<div class="Element203">
<a href="00216.html" target="topic">19.2.2 Interface example using a named bundle</a> </div></td><td class="Element206" valign="top" width="50%">
<div class="Element207">
The simplest form of a SystemVerilog interface is a bundled collection of variables or nets. When an interface is referenced as a port, the variables and nets in it are assumed to have ref and inout access, respectively. The following interface example shows the basic syntax for defining, instantiating and connecting an interface. Usage of the SystemVerilog interface capability can significantly reduce the amount of code required to model port connections. </div></td></tr><tr>
<td class="Element202" valign="top" width="50%">
<div class="Element203">
<a href="00217.html" target="topic">19.2.3 Interface example using a generic bundle</a> </div></td><td class="Element206" valign="top" width="50%">
<div class="Element207">
A module header can be created with an unspecified interface reference as a place-holder for an interface to be selected when the module itself is instantiated. The unspecified interface is referred to as a “generic” interface reference.<br><br>This generic interface reference can only be declared by using the list of port declaration style of reference. It shall be illegal to declare such a generic interface reference using the old Verilog-1995 list of port style.<br><br>The following interface example shows how to specify a generic interface reference in a module definition. </div></td></tr></table></div></div>
</div>
</div>
</div>
<a name="Links"></a><div class="Element14">
<a onclick="toggleVisibilityStored('链接');" class="a_Element14"><img src="sectionminus.png" border="0" alt="" title="" id="img链接">链接</a></div>
<div id="div链接">
<div class="Element11">
<div class="Element10">
<a href="00866.html" target="topic">第十九章 接口</a>, <a href="00958.html" target="topic">主题</a></div>
</div>
</div>
</div>
<!-- End Page Content -->
<!-- Begin Page Footer -->
<hr width="98%" align="center" size="1" color="#CCCCCC" />
<table align="center" cellpadding="0" cellspacing="0" border="0">
<tbody>
<tr height="10">
<td></td>
</tr>
<tr align="center">
<td>
<script type="text/javascript"><!--
google_ad_client = "pub-5266859600380184";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text_image";
google_ad_channel ="";
google_page_url = document.location;
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</td>
</tr>
<tr height="15">
<td></td>
</tr>
<tr align="center">
<td>
<font size=2>除非特别声明,原文版权归作者所有,如有转摘请注明原作者以及译者(<a href="http://www.fpgatech.net/" target="_blank">FPGA技术网</a>)信息。<br />
如果您对本主题有何建议或意见,请登陆<a href="http://www.fpgatech.net/forum/forumdisplay.php?fid=18" target="_blank">FPGA开发者家园</a>提交,您的参与是我们前进的动力。</font>
<script language="javascript" type="text/javascript" src="http://js.users.51.la/195685.js"></script>
<noscript><a href="http://www.51.la/?195685" target="_blank"><img alt="我要啦免费统计" src="http://img.users.51.la/195685.asp" style="border:none" /></a></noscript>
</td>
</tr>
</tbody>
</table>
<!-- End Page Footer -->
</div>
</div>
<!-- End Client Area -->
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -