📄 app2.4.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML EXPERIMENTAL 970324//EN">
<HTML>
<HEAD>
<META NAME="GENERATOR" CONTENT="Adobe FrameMaker 5.5/HTML Export Filter">
<TITLE> B.4 Verilog HDL LRM</TITLE></HEAD><!--#include file="top.html"--><!--#include file="header.html"-->
<DIV>
<P>[ <A HREF="APP2.htm">Chapter start</A> ] [ <A HREF="APP2.3.htm">Previous page</A> ] [ <A HREF="APP2.5.htm">Next page</A> ]</P><!--#include file="AmazonAsic.html"--><HR></DIV>
<H1 CLASS="zAppHeading1">
<A NAME="pgfId=54111">
</A>
B.4 Verilog HDL LRM</H1>
<P CLASS="BodyAfterHead">
<A NAME="pgfId=43457">
</A>
An important feature of Verilog is the ability to extend tools by writing your own code and integrating it with a Verilog-based tool. For example, the following code calls a <A NAME="marker=54360">
</A>
user-written system task, <SPAN CLASS="BodyComputer">
$hello</SPAN>
:</P>
<P CLASS="ComputerOneLine">
<A NAME="pgfId=54127">
</A>
<SPAN CLASS="Bold">
initial</SPAN>
$hello(a_reg); </P>
<P CLASS="BodyAfterHead">
<A NAME="pgfId=54130">
</A>
Here is the C program, <SPAN CLASS="BodyComputer">
hello.c</SPAN>
<A NAME="marker=54361">
</A>
, that prints the full hierarchical name of the instance in which the Verilog code containing the call to <SPAN CLASS="BodyComputer">
$hello</SPAN>
is located:</P>
<P CLASS="ComputerFirst">
<A NAME="pgfId=54132">
</A>
#include "veriuser.h"</P>
<P CLASS="zAppComputer">
<A NAME="pgfId=54133">
</A>
#include "acc_user.h"</P>
<P CLASS="zAppComputer">
<A NAME="pgfId=54134">
</A>
int hello()</P>
<P CLASS="zAppComputer">
<A NAME="pgfId=54135">
</A>
{ handle mod_handle; char *full_name; <A NAME="marker=54364">
</A>
acc_initialize();</P>
<P CLASS="zAppComputer">
<A NAME="pgfId=54136">
</A>
mod_handle = <A NAME="marker=54363">
</A>
acc_handle_tfarg(1);</P>
<P CLASS="zAppComputer">
<A NAME="pgfId=54137">
</A>
io_printf("Hello from: %s\n", <A NAME="marker=54362">
</A>
acc_fetch_fullname(mod_handle));</P>
<P CLASS="zAppComputerLast">
<A NAME="pgfId=54138">
</A>
<A NAME="marker=54365">
</A>
acc_close(); }</P>
<P CLASS="zAppBody">
<A NAME="pgfId=54122">
</A>
The details of how to compile and link your program with the Verilog executable depend on the particular tool; the names, functions, and parameters of <A NAME="marker=54354">
</A>
ACC routines, the <A NAME="marker=54359">
</A>
header files, <SPAN CLASS="BodyComputer">
veriuser.h</SPAN>
<A NAME="marker=54355">
</A>
and <SPAN CLASS="BodyComputer">
acc_user.h</SPAN>
<A NAME="marker=54356">
</A>
(most companies include these with their Verilog products), as well as older <A NAME="marker=54357">
</A>
TF routines and the newer <A NAME="marker=54358">
</A>
VPI routines are described in detail in Sections 17–23 of the 95 LRM.</P>
<P CLASS="zAppBody">
<A NAME="pgfId=58769">
</A>
Annex F of the 95 LRM describes widely used Verilog system tasks and functions that are not required to be supported as part of IEEE Std 1364-1995. <A HREF="APP2.4.htm#34038" CLASS="XRef">
Table B.3</A>
summarizes these tasks and functions. Annex G of the 95 LRM describes additional compiler directives that are not part of IEEE Std 1364-1995 and are not often used by ASIC designers. Two directives, <SPAN CLASS="BodyComputer">
`default_decay_time</SPAN>
<A NAME="marker=59183">
</A>
and <SPAN CLASS="BodyComputer">
`default_trireg_strength</SPAN>
<A NAME="marker=59184">
</A>
, are used to model charge decay and the strength of high-impedance <SPAN CLASS="BodyComputer">
trireg</SPAN>
nets. Four more compiler directives: <SPAN CLASS="BodyComputer">
`delay_mode_distributed</SPAN>
<A NAME="marker=59185">
</A>
, <SPAN CLASS="BodyComputer">
`delay_mode_path</SPAN>
<A NAME="marker=59186">
</A>
, <SPAN CLASS="BodyComputer">
`delay_mode_unit,</SPAN>
<A NAME="marker=59190">
</A>
and <SPAN CLASS="BodyComputer">
`delay_mode_zero</SPAN>
<A NAME="marker=59191">
</A>
are used to specify the delay mode for modules.</P>
<TABLE>
<TR>
<TH ROWSPAN="1" COLSPAN="1">
<P CLASS="zAppTableTitle">
<A NAME="pgfId=58905">
</A>
TABLE B.3 <A NAME="34038">
</A>
System tasks and functions (not required in IEEE Std 1364-1995).</P>
</TH>
</TR>
<TR>
<TD ROWSPAN="1" COLSPAN="1">
<P CLASS="zAppTableLeft">
<A NAME="pgfId=58907">
</A>
<SPAN CLASS="BodyComputer">
$countdrivers ( net, [ net_is_forced, number_of_01x_drivers, number_of_0_drivers,<BR>
number_of_1_drivers, number_of_x_drivers ] ) ;</SPAN>
<A NAME="marker=59064">
</A>
</P>
</TD>
</TR>
<TR>
<TD ROWSPAN="1" COLSPAN="1">
<P CLASS="zAppTableLeft">
<A NAME="pgfId=58909">
</A>
Returns a 0 if there is no more than one driver on the net and returns a 1 otherwise (indicating contention).</P>
</TD>
</TR>
<TR>
<TD ROWSPAN="1" COLSPAN="1">
<P CLASS="zAppTableLeft">
<A NAME="pgfId=58911">
</A>
<SPAN CLASS="BodyComputer">
$getpattern ( mem_element ) ; // Drive a pattern from an indexed memory.</SPAN>
<A NAME="marker=59065">
</A>
</P>
</TD>
</TR>
<TR>
<TD ROWSPAN="1" COLSPAN="1">
<P CLASS="zAppTableLeft">
<A NAME="pgfId=58913">
</A>
Example: <SPAN CLASS="ComputerKeyword">
assign</SPAN>
<SPAN CLASS="BodyComputer">
{i1, i2, i3, i4} = $getpattern ( mem [ index ] )</SPAN>
</P>
</TD>
</TR>
<TR>
<TD ROWSPAN="1" COLSPAN="1">
<P CLASS="zAppTableLeft">
<A NAME="pgfId=58915">
</A>
<SPAN CLASS="BodyComputer">
$input ("filename"); // Allows input from file rather than terminal.</SPAN>
<A NAME="marker=59066">
</A>
</P>
</TD>
</TR>
<TR>
<TD ROWSPAN="1" COLSPAN="1">
<P CLASS="zAppTableLeft">
<A NAME="pgfId=58917">
</A>
<SPAN CLASS="BodyComputer">
$key [ ( "filename" ) ] ; $nokey ; // Enable/disable key file in interactive mode.</SPAN>
<A NAME="marker=59067">
</A>
<A NAME="marker=59068">
</A>
</P>
</TD>
</TR>
<TR>
<TD ROWSPAN="1" COLSPAN="1">
<P CLASS="zAppTableLeft">
<A NAME="pgfId=58919">
</A>
<SPAN CLASS="BodyComputer">
$list [ ( hierarchical_name ) ] ; // List current or specified object.</SPAN>
<A NAME="marker=59069">
</A>
</P>
</TD>
</TR>
<TR>
<TD ROWSPAN="1" COLSPAN="1">
<P CLASS="zAppTableLeft">
<A NAME="pgfId=58921">
</A>
<SPAN CLASS="BodyComputer">
$log [ ( "filename" ) ] ; $nolog ; // Enable/disable log file for standard output.</SPAN>
<A NAME="marker=59070">
</A>
<A NAME="marker=59071">
</A>
</P>
</TD>
</TR>
<TR>
<TD ROWSPAN="1" COLSPAN="1">
<P CLASS="zAppTableLeft">
<A NAME="pgfId=58963">
</A>
<SPAN CLASS="BodyComputer">
$reset [ ( stop_value [ , reset_value , [ diagnostics_value ] ] ) ] ; // Reset time.</SPAN>
<A NAME="marker=59072">
</A>
</P>
<P CLASS="zAppTableLeft">
<A NAME="pgfId=58964">
</A>
<SPAN CLASS="BodyComputer">
$reset_count ; // Count the number of resets. </SPAN>
<A NAME="marker=59073">
</A>
</P>
<P CLASS="zAppTableLeft">
<A NAME="pgfId=58976">
</A>
<SPAN CLASS="BodyComputer">
$reset_value ; // Pass information prior to reset to simulation after reset.</SPAN>
<A NAME="marker=59074">
</A>
</P>
</TD>
</TR>
<TR>
<TD ROWSPAN="1" COLSPAN="1">
<P CLASS="zAppTableLeft">
<A NAME="pgfId=58926">
</A>
<SPAN CLASS="BodyComputer">
$save ( "file_name" ) ; // Save simulation for later restart.</SPAN>
<A NAME="marker=59075">
</A>
</P>
<P CLASS="zAppTableLeft">
<A NAME="pgfId=59000">
</A>
<SPAN CLASS="BodyComputer">
$restart ( "file_name" ) ; // Restart simulation from saved file.</SPAN>
<A NAME="marker=59076">
</A>
</P>
<P CLASS="zAppTableLeft">
<A NAME="pgfId=59001">
</A>
<SPAN CLASS="BodyComputer">
$incsave ( "incremental_file_name" ) ; // Save only changes since last $save</SPAN>
<A NAME="marker=59077">
</A>
</P>
</TD>
</TR>
<TR>
<TD ROWSPAN="1" COLSPAN="1">
<P CLASS="zAppTableLeft">
<A NAME="pgfId=59009">
</A>
<SPAN CLASS="BodyComputer">
$scale ( hierarchical_name ) ; // Convert to time units of invoking module.</SPAN>
<A NAME="marker=59078">
</A>
</P>
</TD>
</TR>
<TR>
<TD ROWSPAN="1" COLSPAN="1">
<P CLASS="zAppTableLeft">
<A NAME="pgfId=58930">
</A>
<SPAN CLASS="BodyComputer">
$scope ( hierarchical_name ) ; // Sets the specified level of hierarchy as current scope.</SPAN>
<A NAME="marker=59079">
</A>
</P>
</TD>
</TR>
<TR>
<TD ROWSPAN="1" COLSPAN="1">
<P CLASS="zAppTableLeft">
<A NAME="pgfId=58932">
</A>
<SPAN CLASS="BodyComputer">
$showscopes [ ( n ) ]; // Show scope (n = none or zero) else show all items below scope.</SPAN>
<A NAME="marker=59080">
</A>
</P>
</TD>
</TR>
<TR>
<TD ROWSPAN="1" COLSPAN="1">
<P CLASS="zAppTableLeft">
<A NAME="pgfId=58934">
</A>
<SPAN CLASS="BodyComputer">
$showvars [ ( list_of_variables ) ] ; // Show status of scope or specified variables.</SPAN>
<A NAME="marker=59081">
</A>
</P>
</TD>
</TR>
<TR>
<TD ROWSPAN="1" COLSPAN="1">
<P CLASS="zAppTableLeft">
<A NAME="pgfId=59045">
</A>
<SPAN CLASS="BodyComputer">
$sreadmemb ( mem_name , start_address , finish_address , string { , string } ) ;</SPAN>
<A NAME="marker=59082">
</A>
</P>
<P CLASS="zAppTableLeft">
<A NAME="pgfId=59048">
</A>
<SPAN CLASS="BodyComputer">
$sreadmemh ( mem_name , start_address , finish_address , string { , string } ) ;</SPAN>
<A NAME="marker=59083">
</A>
</P>
<P CLASS="zAppTableLeft">
<A NAME="pgfId=58936">
</A>
Load data into <SPAN CLASS="BodyComputer">
mem_name</SPAN>
from character string (same format as <SPAN CLASS="BodyComputer">
$readmemb/h</SPAN>
).</P>
</TD>
</TR>
</TABLE>
<HR><P>[ <A HREF="APP2.htm">Chapter start</A> ] [ <A HREF="APP2.3.htm">Previous page</A> ] [ <A HREF="APP2.5.htm">Next page</A> ]</P></BODY>
<!--#include file="Copyright.html"--><!--#include file="footer.html"-->
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -