sysytemverilog中系统函数$test$plusargs与$value$plusargs的用法

systemverilog可以采用define与parameter等方式定义变量,但是需要在编译前完成变量的定义,编译之后不能修改。当需要改变编译条件时,经常需要重新编译。并且一旦编译通过,在编译阶段指定的宏定义在整个仿真运行过程中一直有效,因此,如果需要修改宏定义,则需要重新进行编译,从而降低了仿真的效率。

为此,可以使用$test$plusargs和$value$plusargs进行解决,该函数的调用发生在仿真运行(run)阶段。这样仅需要对设计进行一次编译即可。从而实现在不重新编译的情况下完成变量的重新赋值。如果需要改变相应的条件,可以在run的时候动态指定,这样有利于脚本处理进行回归的验证,同时也有利于object的动态construct。使用这两条函数对于搭建测试平台有一定的便利,同时对于理解Factory中用例是如何传递进Proxy Class有一定的帮助。

1.$test$plusargs
在运行仿真时指定要选择的条件,即只需要在仿真运行命令(run-options)中指定参数需要选择的条件即可,例如以下例子中,当仿真运行时,$test$plusargs会在命令行中搜索指定的字符,若找到相应字符,在函数返回“1”,否则返回“0”。

initial begin
	if($test$plusargs("test0")
		$readmemh("test0.data", mem0);
	if($test$plusargs("test1")
		$readmemh("test1.data", mem1);
	if($test$plusargs("test2")
		$readmemh("test2.data", mem2);
end

./simv +test0+test1		//只选择test0和test1

2.$value$plusargs
$value$plusargs可以讲运行命令(run-options)中的参数值传递给指定的信号或者字符,其语法格式如下:
integer=$value$plusargs(“string”, signalname);
其中string=”plusarg_format”+”format_string”,”plusarg_format”指定了用户定义的要进行传递的值,”format_string”指定了要传递的值的格式(类似$display中定义的%s、%h、etc.)。

initial begin
	if($value$plusargs("TESTNAME=%s", testname))
	begin
		$display("Running test %0s", testname);
	end
	if($value$plusargs("FINISH=%d", clk_cycle_num))
	begin
		repeat(clk_cycle_num) @(posedge clk);
		$finish();
	end
end

./simv +TESTNAME=test0		//只选择TESTNAME

猜你喜欢

转载自blog.csdn.net/Michael177/article/details/120932996