天天看點

SystemVerilog中的Events事件前言一、事件(Events)二、@操作符和wait()操作的差別三、wait_order總結

文章目錄

  • 前言
  • 一、事件(Events)
  • 二、@操作符和wait()操作的差別
  • 三、wait_order
  • 總結

前言

本文首先介紹SystemVerilog中的Events;其次記錄了@操作符和wait()操作的差別;最後介紹了wait_order的用法。

一、事件(Events)

事件(Events)是程序之間同步的靜态對象。

事件發揮作用的過程分為兩個階段,即:

一個程序觸發(trigger )事件,另一個程序等待事件被觸發(triggered)。可以使用->操作符觸發事件,使用@操作符或者wait() 等待事件被觸發。

下面的示例顯示了事件觸發以及等待事件觸發的兩個過程

module events_ex;
  event ev_1; //declaring event ev_1
  initial begin
    fork
      //process-1, triggers the event
      begin
        #40;
        $display($time,"\tTriggering The Event");
        ->ev_1;
      end
     
      //process-2, wait for the event to trigger
      begin
        $display($time,"\tWaiting for the Event to trigger");
        @(ev_1.triggered);
        $display($time,"\tEvent triggered");
      end
    join
  end
endmodule
           

仿真結果:

0 Waiting for the Event to trigger
40 Triggering The Event
40 Event triggered
           

二、@操作符和wait()操作的差別

其中@操作符會阻塞住所調用的程序直到觸發給定的事件,是以等待程序必須先執行@語句,然後觸發程序才能執行觸發器操作符->。如果觸發程序先執行,則等待程序會一直被阻塞。

而wait()操作覆寫則是監測觸發事件是否曾被觸發過,即使等待程序晚于觸發程序也能接觸阻塞。

如果是先觸發事件,然後再等待事件觸發,那麼等待觸發之後的語句将不會被執行。

module events_ex;  
  event ev_1; //declaring event ev_1
  initial begin
    fork
      //process-1, triggers the event
      begin
        #40;
        $display($time,"\tTriggering The Event");
        ->ev_1;
      end  
      //process-2, wait for the event to trigger
      begin
        $display($time,"\tWaiting for the Event to trigger");
        #60;
        @(ev_1.triggered);
        $display($time,"\tEvent triggered");
      end
    join
  end
  initial begin
    #100;
    $display($time,"\tEnding the Simulation");
    $finish;
  end
endmodule
           

仿真輸出

0  Waiting for the Event to triggerSimulator Output
40  Triggering The Event
100 Ending the Simulation
           

這裡如果不加上最後一個initial begin end程序,那麼仿真就會一直持續。

三、wait_order

wait_order是指等待所有指定的事件按照特定的順序觸發(從左到右)。例如wait_order(a,b,c)會一直等待事件a,b,c按順序觸發 。

bit success;
wait_order( a, b, c ) success = 1; else success = 0;
           

總結

本文主要圍繞systemverilog中,Events事件相關的用法進行了總結。