Title

SystemVerilog -- 3.4 SystemVerilog forever loop

SystemVerilog forever loop

循环永远运行,或者无限时间运行。forever

Syntax

forever
  // Single statement

forever begin
  // Multiple statements
end

循环类似于下面Verilog中所示的代码。两者都运行无限的仿真时间,并且在它们内部有一个延迟元件很重要。forever

An always or forever block without a delay element will hang in simulation!
always
  // Single statement

always begin
  // Multiple statements
end

在SystemVerilog中,block不能放置在类和其他SystemVerilog过程块中。相反,我们可以使用循环来达到相同的效果。always forever

下面显示的伪代码模拟了testbench中监视器的功能,只要它监视的总线上有活动,该监视器就会启动并允许运行。

class Monitor;
  virtual task run();
    forever begin
      @ (posedge vif.clk)
        if (vif.write & vif.sel)
          // Capture write data
        if (!vif.write & vif.sel)
          // Capture read data
    end
  endtask
endclass

module tb;
   Monitor mon;

   // Start the monitor task and allow it to continue as long as there is activity on the bus
   initial begin
     fork
       mon.run();
     join_none
   end
endmodule

posted on 2024-05-05 19:28  松—松  阅读(96)  评论(0编辑  收藏  举报

导航