$ test $ plusargs和 $ value $ plusargs作为进行 Verilog 和 SystemVerilog仿真运行时调用的系统函数:
1、可以在终端仿真命令中直接赋值,避免了调换参数带来的频繁编译问题。
2、不局限于不同仿真器对于参数在仿真命令中定义格式的不同
(一)使用宏定义的条件编译有何缺点?
例如:
initial
begin
`ifdef dumpon
$dumpfile("res.vcd");
$dumpvars;
`endif
end
如果需要调用条件编译中的系统函数需要在编译时指定`define的宏定义
<compile-option> -define dumpon tb.v
但是就会产生一个问题,如果需要改变编译条件,就会需要重新编译,从而降低了仿真的效率。
(二)$ test $ plusargs
在运行仿真时指定要选择的条件,只需要在仿真运行命令(run-options)指定参数需要的条件即可。
initial
begin
if($test$plusargs("test1")
$readmemh("test1.dat",mem1);
if($test$plusargs("test2")
$readmemh("test2.dat",mem2);
end
+test1+test2
如果仿真不需要test1,只需要将test1从运行命令中删除即可。
(三)$ value $ plusargs
$ value$ plusargs可以讲运行命令(run-options)中的参数值传递给指定的信号或者字符,其语法格式如下:
$ value $ plusargs(“string”,signalname);
其中string=”plusarg_format”+”format_string”,”plusarg_format”指定了用户定义的要进行传递的值,”format_string”指定了要传递的值的格式(类似$display中定义的%s、%h、etc.),并且string中”plusarg_format”和”format_string”格式应该为”plusarg_format”(=/+)”format_string”。
但是数据的位宽与string 中传递的值不一致。遵循以下原则:
if($value$plusargs("finish=%d",stop_clk))
begin
repeat(stop_clk);
$finish;
end
if($value$plusargs("freq=%f",frequency))
begin
frequency=8.5645;
end
if($value$plusargs("testname=%s"testname))
begin
$display("testname=%s",testname);
end
使用运行命令为:
<run-options>+finish=5000+freq=5.21+testname=test
输出结果为:
finish=5000
freq=5.21
testname=test