现在的位置: 首页 > 综合 > 正文

System Task and Function (of Verilog HDL)

2013年05月03日 ⁄ 综合 ⁄ 共 5065字 ⁄ 字号 评论关闭
 

  Introduction  //简介
   
$display, $strobe, $monitor 
 
Syntax
$time, $stime, $realtime
$reset, $stop, $finish
$scope, $showscope
$random
$dumpfile, $dumpvar, $dumpon, $dumpoff, $dumpall
 
Syntax
$fopen, $fdisplay, $fstrobe $fmonitor and $fwrite
 
Syntax

the above original link:http://www.asic-world.com/verilog/sys_task_func.html

   
  ../images/main/bullet_green_ball.gif Introduction //简介
   

There are tasks and functions that are used to generate input and output during simulation. Their names begin with a dollar sign ($). The synthesis tools parse and ignore system functions, and hence can be included even
in synthesizable models.

在仿真(simulation)时,有一些任务task和函数function用来成生输入和输出。 它们的名字以$开始。综合工具解析或者忽略系统函数,因此可以包含在可以综合的模块中。

   

space.gif

  ../images/main/bulllet_4dots_orange.gif $display, $strobe, $monitor 
   

These commands have the same syntax, and display text on the screen during simulation. 

这些命令有着相同的语法格式,并且能够在仿真期间在屏幕上显示文本。

They are much less convenient than waveform display tools like GTKWave. or Undertow or Debussy. 

它们没有波形图显示工具(如GTKWave ,undertow , debussy)方便。

$display and $strobe display once every time they are executed, whereas $monitor displays every time one of its parameters changes. 

$display,$strobe 在每次执行时,显示一次。 然而,$monitor在每次其参数发生变化时都显示。

The difference between $display and $strobe is that $strobe displays the parameters at the very end of the current simulation time unit rather than exactly when it is executed. 

$dispaly和$strobe不同点在于,$strobe显示的参数是在当前仿真单元的结束而不是开始。

The format string is like that in C/C++, and may contain format characters. 

格式化字符串和C、C++中的类似,可能包含格式化字符。

Format characters include %d (decimal), %h (hexadecimal), %b (binary), %c (character), %s (string) and %t (time), %m (hierarchy level). 

格式化字符包括: %d (decimal), %h (hexadecimal), %b (binary), %c (character), %s (string) and %t (time), %m (hierarchy level).

%5d, %5b etc. would give exactly 5 spaces for the number instead of the space needed. 

显示的宽度设置。

Append b, h, o to the task name to change default format to binary, octal or hexadecimal.

在task name后加b,o,h可以讲默认的格式化方式变为binary,octal,或者hexadecimal。

   

space.gif

  ../images/main/bullet_star_pink.gif Syntax 语法格式
   

space.gif

   
  • $display ("format_string", par_1, par_2, ... );
  • $strobe ("format_string", par_1, par_2, ... );
  • $monitor ("format_string", par_1, par_2, ... );
  • $displayb (as above but defaults to binary..);
  • $strobeh (as above but defaults to hex..);
  • $monitoro (as above but defaults to octal..);
   

space.gif

  ../images/main/bulllet_4dots_orange.gif $time, $stime, $realtime 
   

These return the current simulation time as a 64-bit integer, a 32-bit integer, and a real number, respectively.

这些任务返回当前的仿真时间的值,$time:64-bit integer,$stime : 32-bit integer, $realtime: a real number.

   

space.gif

  ../images/main/bulllet_4dots_orange.gif $reset, $stop, $finish
   

$reset resets the simulation back to time 0; $stop halts the simulator and puts it in interactive mode where the user can enter commands; $finish exits the simulator back to the operating system.

$reset :  使simulation time(仿真时间)复位到0. 

$stop:挂起仿真器,使其进入交互模式,用户可以输入命令。

$finish: 退出仿真器,返回到os。

   

space.gif

   
   

space.gif

  ../images/main/bulllet_4dots_orange.gif $scope, $showscope
   

$scope(hierarchy_name) sets the current hierarchical scope to hierarchy_name. 

$scope(hierarchy_name):设置当期的层次作用域为hierarchy_name.

$showscopes(n) lists all modules, tasks and block names in (and below, if n is set to 1) the current scope.

$showscope(n) :显示当前作用域中所有的模块名字,task名字,block名字。

   

space.gif

  ../images/main/bulllet_4dots_orange.gif $random 
   

$random generates a random integer every time it is called. 

每次调用$random时产生一个随机数。

If the sequence is to be repeatable, the first time one invokes random giving it a numerical argument (a seed). 

如果这个序列是可重现的,在第一调用时给它传一个数值型参数(种子)。

Otherwise the seed is derived from the computer clock.

否则,种子源于计算机的时钟。

   

space.gif

  ../images/main/bulllet_4dots_orange.gif $dumpfile, $dumpvar, $dumpon, $dumpoff, $dumpall 
   

These can dump variable changes to a simulation viewer like Debussy. 

这些系统任务可以将变量变化转储起来给仿真器查看器使用如Debussy。

The dump files are capable of dumping all the variables in a simulation. 

dump file能够转仿真时的所有变量。

This is convenient for debugging, but can be very slow.

这对于调试来说,非常方便,但是也是非常慢的。

   

space.gif

  ../images/main/bullet_star_pink.gif Syntax
   

space.gif

   
  • $dumpfile("filename.vcd")
  • $dumpvar dumps all variables in the design.
  • $dumpvar(1, top) dumps all the variables in module top and below, but not modules instantiated in top.
  • $dumpvar(2, top) dumps all the variables in module top and 1 level below.
  • $dumpvar(n, top) dumps all the variables in module top and n-1 levels below.
  • $dumpvar(0, top) dumps all the variables in module top and all level below.
  • $dumpon initiates the dump. //初始化dump
  • $dumpoff stop dumping.  //停止dump
   

space.gif

  ../images/main/bulllet_4dots_orange.gif $fopen, $fdisplay, $fstrobe $fmonitor and $fwrite
   

These commands write more selectively to files. //这些命令可以更有选择性地写入到文件。

   

space.gif

   
  • $fopen opens an output file and gives the open file a handle for use by the other commands.
  • $fopen 打开输出文件,产生一个文件handle。
  • $fclose closes the file and lets other programs access it.
  • $fclose关闭一个文件并使其他程序能够访问它。
  • $fdisplay and $fwrite write formatted data to a file whenever they are executed. They are the same except $fdisplay inserts a new line after every execution and $write does not.
  • 当执行$fdisplay 和$fwrite 将格式化的数据写入到文件。除了$dispaly在每次执行后插入一个换行外,$fwrite不插入换行,二者基本上是相同的。
  • $strobe also writes to a file when executed, but it waits until all other operations in the time step are complete before writing. Thus initial #1 a=1; b=0; $fstrobe(hand1, a,b); b=1; will write write
    1 1 for a and b.
  • $strobe 执行时,也写入到文件,但是它要等到该时间步中所有的其他操作都执行完之后。如nitial #1 a=1; b=0; $fstrobe(hand1, a,b); b=1; will write write 1 1 for a and b.

  • $fmonitor writes to a file whenever any of its arguments changes.
  • $fmonitor 当它的任何一个参数变化时,将写入到文件中。
   

space.gif

  ../images/main/bullet_star_pink.gif Syntax
   

space.gif

   
  • handle1=$fopen("filenam1.suffix")
  • handle2=$fopen("filenam2.suffix")
  • $fstrobe(handle1, format, variable list) //strobe data into filenam1.suffix
  • $fdisplay(handle2, format, variable list) //write data into filenam2.suffix
  • $fwrite(handle2, format, variable list) //write data into filenam2.suffix all on one line. 
  • Put in the format string where a new line is desired. //可以在格式串 format中指定换行符。
   

space.gif

the above original link:http://www.asic-world.com/verilog/sys_task_func1.html

抱歉!评论已关闭.