可以在下面的代码中将s_clk作为参数传递给xyz任务吗?
module test(input logic m_clk, output [1:0] logic s_clk);
...
xyz (m_clk,s_clk);//assuming m_clks and s_clks are generated from top
...
task automatic xyz (ref logic clk1, ref [1:0] logic clk2);
...
endtask
endmodule
答案 0 :(得分:1)
我已经阅读了你的问题,首先你有错字错误
module test(input logic m_clk, output [1:0] logic s_clk);
task automatic xyz (ref logic clk1, ref [1:0] logic clk2);
而不是你必须写
module test(input logic m_clk, output logic [1:0] s_clk);
task automatic xyz (ref logic clk1, ref logic [1:0] clk2);
为了更好地理解,我还共享了一个压缩数组的演示代码,可以通过引用systemverilog中的任务来传递。
这是代码:
program main();
bit [31:0] a = 25;
initial
begin
#10 a = 7;
#10 a = 20;
#10 a = 3;
#10 $finish;
end
task pass_by_val(int i);
$monitor("===============================================%d",i);
forever
@a $display("pass_by_val: I is %0d",i);
endtask
task pass_by_ref(ref bit [31:0]i);
forever
begin
@a $display("pass_by_ref: I is %0d",i[0]);
$display("This is pass_by value a ====== %d \n a[0] ====== %0d ",a,a[0]);
end
endtask
initial
begin
pass_by_val(a);
end
initial
pass_by_ref(a);
endprogram
通过运行此示例,您可以观察到打包数组可以通过引用systemverilog中的任务来传递,并且其值也会反映到它。
答案 1 :(得分:0)
pass_by_val任务将注册变量的值 在调用任务时只有一次。随后当变量更改其值时,pass_by_val任务无法查看更新的值。另一方面,任务中的“ref”变量只要其值发生变化就会被注册。因此,当变量'a'值更改时,pass_by_ref任务可以正确注册并显示该值。
我模拟了Ashutosh Rawal的代码,输出显示如下:
=============================================== 25
pass_by_val: I is 25
pass_by_ref: I is 1
This is pass_by value a ====== 7
a[0] ====== 1
pass_by_val: I is 25
pass_by_ref: I is 0
This is pass_by value a ====== 20
a[0] ====== 0
pass_by_val: I is 25
pass_by_ref: I is 1
This is pass_by value a ====== 3
a[0] ====== 1
$finish called from file "testbench.sv", line 13.
$finish at simulation time 40
V C S S i m u l a t i o n R e p o r t