⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 00264.html

📁 这是一本关于verilog编程语言的教程,对学习verilog语言有帮助
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
<html>
<head>
<title>21.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', '00264.html');" onmousedown="onBodyMouseDown();">

<!-- Begin Popups -->
<div class="Element801" id="popup00443">
<div class="Element800">
<div class="Element14">
链接</div>
<div class="Element11">
<div class="Element10">
<a href="00855.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, 'popup00443');"><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="00263.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="00855.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="00848.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">
21.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('code00919');">Copy Code</a></div>
<div class="Element13"><div class="Element12" id="code00919"><pre class="Element12">local_parameter_declaration ::=           <span style="color: #008000">// 引用自附录A.2.1.1</span>
    <strong><span style="color: #FF0000">localparam</span></strong> data_type_or_implicit list_of_param_assignments<strong><span style="color: #FF0000">;</span></strong>

parameter_declaration ::=
    <strong><span style="color: #FF0000">parameter</span></strong> data_type_or_implicit list_of_param_assignments
  | <strong><span style="color: #FF0000">parameter type</span></strong> list_of_type_assignments

specparam_declaration ::=
    <strong><span style="color: #FF0000">specparam</span></strong> [packed_dimension] list_of_specparam_assignments<strong><span style="color: #FF0000">;</span></strong>

data_type_or_implicit ::=                <span style="color: #008000">// 引用自附录A.2.2.1</span>
    data_type
  | [signing] {packed_dimension}

list_of_param_assignments ::= param_assignment {<strong><span style="color: #FF0000">,</span></strong> param_assignment} <span style="color: #008000">// 引用自附录A.2.3</span>

list_of_specparam_assignments ::= specparam_assignment {<strong><span style="color: #FF0000">,</span></strong> specparam_assignment}

list_of_type_assignments ::= type_assignment {<strong><span style="color: #FF0000">,</span></strong> type_assignment}

param_assignment ::=                    <span style="color: #008000">// 引用自附录A.2.4</span>
    parameter_identifier {unpacked_dimension} <strong><span style="color: #FF0000">=</span></strong> constant_param_expression

specparam_assignment ::=
    specparam_identifier <strong><span style="color: #FF0000">=</span></strong> constant_mintypmax_expression
  | pulse_control_specparam

type_assignment ::= type_identifier <strong><span style="color: #FF0000">=</span></strong> data_type

parameter_port_list ::=                <span style="color: #008000">// 引用自附录A.1.4</span>
    <strong><span style="color: #FF0000">#(</span></strong>list_of_param_assignments {<strong><span style="color: #FF0000">,</span></strong> parameter_port_declaration}<strong><span style="color: #FF0000">)</span></strong>
  | <strong><span style="color: #FF0000">#(</span></strong>parameter_port_declaration {<strong><span style="color: #FF0000">,</span></strong> parameter_port_declaration}<strong><span style="color: #FF0000">)</span></strong>

parameter_port_declaration ::=
    parameter_declaration
  | data_type list_of_param_assignments
  | <strong><span style="color: #FF0000">type</span></strong> list_of_type_assignments</pre></div></div>
<p class="Element10" style="text-align: center">
<strong>语法 21-1 — 参数声明语法(摘录自附录A)</strong></p><p class="Element10">
&nbsp;</p>
<p class="Element10">
A module, interface, program or class can have parameters, which are set during elaboration and are constant during simulation. They are defined with data types and default values. With SystemVerilog, if no data type is supplied, parameters default to type logic of arbitrary size for Verilog-2001 compatibility and interoperability. SystemVerilog adds the ability for a parameter to also specify a data type, allowing modules or instances to have data whose type is set for each instance. </p><div class="Element170">
<a href="#" onclick="CopyElementToClipboard('code00920');">Copy Code</a></div>
<div class="Element13"><div class="Element12" id="code00920"><pre class="Element12">module ma #(parameter p1 = 1, parameter type p2 = shortint)
          (input logic [p1:0] i, output logic [p1:0] o);
    p2 j = 0; // type of j is set by a parameter, (shortint unless redefined)

    always @(i) begin
        o = i;
        j++;
    end
endmodule

module mb;
    logic [3:0] i,o;
    ma #(.p1(3), .p2(int)) u1(i,o); //redefines p2 to a type of int
endmodule</pre></div></div>
<p class="Element10">
&nbsp;</p>
<p class="Element10">
SystemVerilog adds the ability for local parameters to be declared in a generate block. Local parameters can also be declared in a package or in a compilation unit scope. In these contexts, the parameter keyword can be used as a synonym for the localparam keyword.&nbsp;</p>
<p class="Element10">
&nbsp;</p>
<p class="Element10">
$ can be assigned to parameters of integer types. A parameter to which $ is assigned shall only be used wherever $ can be specified as a literal constant.&nbsp;</p>
<p class="Element10">
&nbsp;</p>
<p class="Element10">
For example, $ represents unbounded range specification, where the upper index can be any integer. </p><div class="Element170">
<a href="#" onclick="CopyElementToClipboard('code00921');">Copy Code</a></div>
<div class="Element13"><div class="Element12" id="code00921"><pre class="Element12">parameter r2 = $;

property inq1(r1,r2);
    @(posedge clk) a ##[r1:r2] b ##1 c |=&gt; d;
endproperty

assert inq1(3);</pre></div></div>
<p class="Element10">
&nbsp;</p>
<p class="Element10">
To support whether a constant is $, a system function is provided to test whether a constant is a $. The syntax of the system function is </p><div class="Element170">
<a href="#" onclick="CopyElementToClipboard('code00922');">Copy Code</a></div>
<div class="Element13"><div class="Element12" id="code00922"><pre class="Element12">$isunbounded(const_expression);</pre></div></div>
<p class="Element10">
&nbsp;</p>
<p class="Element10">
$isunbounded returns true if const_expression is unbounded. Typically, $isunbounded would be used as a condition in the generate statement.&nbsp;</p>
<p class="Element10">
&nbsp;</p>
<p class="Element10">
The example below illustrates the benefit of using $ in writing properties concisely where the range is parameterized. The checker in the example ensures that a bus driven by signal en remains 0, i.e, quiet for the specified minimum (min_quiet) and maximum (max_quiet) quiet time.&nbsp;</p>
<p class="Element10">
&nbsp;</p>
<p class="Element10">
Note that function $isunbounded is used for checking the validity of the actual arguments. </p><div class="Element170">
<a href="#" onclick="CopyElementToClipboard('code00923');">Copy Code</a></div>
<div class="Element13"><div class="Element12" id="code00923"><pre class="Element12">interface quiet_time_checker #(parameter min_quiet = 0,
                               parameter max_quiet = 0)
                              (input logic clk, reset_n, [1:0]en);
    generate
        if ( max_quiet == 0) begin
            property quiet_time;
                @(posedge clk) reset_n |-&gt; ($countones(en) == 1);
            endproperty
            a1: assert property (quiet_time);
        end
        else begin
            property quiet_time;
                @(posedge clk)
                    (reset_n &amp;&amp; ($past(en) != 0) &amp;&amp; en == 0)
                    |-&gt;(en == 0)[*min_quiet:max_quiet]
                ##1 ($countones(en) == 1);
            endproperty
            a1: assert property (quiet_time);
        end

        if ((min_quiet == 0) &amp;&amp; ($isunbounded(max_quiet))
            $display(warning_msg);
    endgenerate
endinterface

quiet_time_checker #(0, 0) quiet_never (clk,1,enables);
quiet_time_checker #(2, 4) quiet_in_window (clk,1,enables);
quiet_time_checker #(0, $) quiet_any (clk,1,enables);</pre></div></div>
<p class="Element10">
&nbsp;</p>
<p class="Element10">
Another example below illustrates that by testing for $, a property can be configured according to the requirements. When parameter max_cks is unbounded, it is not required to test for expr to become false. </p><div class="Element170">
<a href="#" onclick="CopyElementToClipboard('code00924');">Copy Code</a></div>
<div class="Element13"><div class="Element12" id="code00924"><pre class="Element12">interface width_checker #(parameter min_cks = 1, parameter max_cks = 1)
                         (input logic clk, reset_n, expr);
    generate begin
        if ($isunbounded(max_cks)) begin
            property width;
                @(posedge clk)
                    (reset_n &amp;&amp; $rose(expr)) |-&gt; (expr [* min_cks]);
            endproperty

            a2: assert property (width);
        end
        else begin
            property assert_width_p;
                @(posedge clk)
                    (reset_n &amp;&amp; $rose(expr)) |-&gt; (expr[* min_cks:max_cks])
                    ##1 (!expr);
            endproperty

            a2: assert property (width);
        end
    endgenerate
endinterface

width_checker #(3, $) max_width_unspecified (clk,1,enables);
width_checker #(2, 4) width_specified (clk,1,enables);</pre></div></div>
<p class="Element10">
&nbsp;</p>
<p class="Element10">
SystemVerilog also adds the ability to omit the parameter keyword in a parameter port list. </p><div class="Element170">
<a href="#" onclick="CopyElementToClipboard('code00925');">Copy Code</a></div>
<div class="Element13"><div class="Element12" id="code00925"><pre class="Element12">class vector #(size = 1);
    logic [size-1:0] v;
endclass

typedef vector#(16) word;

interface simple_bus #(AWIDTH = 64, type T = word) (input bit clk) ;
endinterface</pre></div></div>
<p class="Element10">
&nbsp;</p>
<p class="Element10">
In a list of parameters, a parameter can depend on earlier parameters. In the following declaration, the default value of the second parameter depends on the value of the first parameter. The third parameter is a type, and the fourth parameter is a value of that type. </p><div class="Element170">
<a href="#" onclick="CopyElementToClipboard('code00926');">Copy Code</a></div>
<div class="Element13"><div class="Element12" id="code00926"><pre class="Element12">module mc #(int N = 5, M = N*16, type T = int, T x = 0)
           ( ... );
    ...
endmodule</pre></div></div>
</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="00855.html" target="topic">第二十一章 参数</a></p></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="00855.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="&#x6211;&#x8981;&#x5566;&#x514D;&#x8D39;&#x7EDF;&#x8BA1;" 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 + -