[UVM] event

今天翻到自己以前的笔记看到uvm event,所以在这记录一下其用法。

wait_on  Waits for the event to be activated for the first time.


wait_off    If the event has already triggered and is “on”, this task waits for the event to be turned “off” via a call to reset.


wait_trigger  Waits for the event to be triggered.


wait_ptrigger  Waits for a persistent trigger of the event.


wait_trigger_data     This method calls wait_trigger followed by get_trigger_data.

virtual task wait_trigger_data (output 	uvm_object 	data)

wait_ptrigger_data   This method calls wait_ptrigger followed by get_trigger_data.

virtual task wait_ptrigger_data (output uvm_object 	data)

trigger    Triggers the event, resuming all waiting processes.

virtual function void trigger (uvm_object data = null)

      An optional data argument can be supplied with the enable to provide trigger-specific information.

     可将伴随触发的数据对象写入到该触发事件中,而等待该事件的对象可以通过wait_trigger_data(output T data)来获取事件触发时写入的数据对象


get_trigger_data    Gets the data, if any, provided by the last call to trigger.


get_trigger_time  Gets the time that this event was last triggered.


is_on  Indicates whether the event has been triggered since it was last reset.


is_off    Indicates whether the event has been triggered or been reset.


reset  Resets the event to its off state.

virtual function void reset (bit wakeup	 = )

   If wakeup is set, then all processes currently waiting for the event are activated before the reset.


add_callback  Registers a callback object, cb, with this event.

virtual function void add_callback (uvm_event_callback 	cb,	bit append=1)

Registers a callback object, cb, with this event.  The callback object may include pre_trigger and post_trigger functionality.  If append is set to 1, the default, cb is added to the back of the callback list.  Otherwise, cb is placed at the front of the callback list.

用户可以extends uvm_event_callback,定义uvm_event被trigger前后的调用方法pre_trigger()和post_trigger();

pre_trigger需要有返回值,若返回值为1,表示uvm_event不会被trigger,也不会执行post_trigger;若返回值为0,则会继续trigger该事件对象。


delete_callback  Unregisters the given callback, cb, from this event.


cancel  Decrements the number of waiters on the event.


get_num_waiters   Returns the number of processes waiting on the event.


推荐用wait_ptrigger,而不是wait_trigger

If wait_ptrigger is called after the trigger but within the same time-slice, the caller returns immediately.

Trigger 在#0发生,而在#2 wait_trigger/wait_ptrigger, 都不会等到事件trigger。

两者的区别主要是在同一时间片内trigger先发生wait trigger后发生时,wait_ptrigger可以等到,而wait_trigger 等不到事件发生。

 

Once an event has been triggered, it will be remain “on” until the event is reset.


example:

class edata extends uvm_object;
  int data;
  `uvm_object_utils(edata)
  ...
endclass

//------------------------------------------------------------------------------

class ecb extends uvm_event_callback;
  `uvm_object_utils(ecb)
  ...

  function bit pre_trigger(uvm_event e, uvm_object data = null);
    `uvm_info("BEF",$sformatf("before trigger event %s",e,get_name()),UVM_LOW)
    return 0;
  endfunction

  function void post_trigger(uvm_event e, uvm_object data = null);
    `uvm_info("POST",$sformatf("after trigger event %s",e,get_name()),UVM_LOW)
  endfunction
  
endclass

//------------------------------------------------------------------------------

class agt1 extends uvm_component;

  `uvm_component_utils(agt1)
  uvm_event_pool ep;
  uvm_event ev1;

  function new(string name="agt1",uvm_component parent=null);
    super.new(name,parent);
    ep = ep.get_global_pool();
    ev1 = ep.get("driven");
    //ev1 = uvm_event_pool::get_global("driven");
  endfunction

  task run_phase(uvm_phase phase);
    phase.raise_objection(this);
    edata d = new();
    ecb cb = new();
    d.data = 100;
    #10ns;
    ev1.add_callback(cb);
    ev1.trigger(d);
    phase.drop_objection(this);
  endtask

endclass

//------------------------------------------------------------------------------

class agt2 extends uvm_component;

  `uvm_component_utils(agt2)
  uvm_event_pool ep;
  uvm_event ev1;

  function new(string name="agt2",uvm_component parent=null);
    super.new(name,parent);
    ep = ep.get_global_pool();
    ev1 = ep.get("driven");
    //ev1 = uvm_event_pool::get_global("driven");
  endfunction

  task run_phase(uvm_phase phase);
    uvm_object tmp;
    edata d;
    phase.raise_objection(this);
    ev1.wait_trigger_data(tmp);
    void'($cast(d,tmp));
    phase.drop_objection(this);
  endtask

endclass

猜你喜欢

转载自blog.csdn.net/lbt_dvshare/article/details/82691627