uvm event callback

uvm_event_callback

UVM provides the facility to add callbacks to a uvm_event trigger. The pre_trigger and post_trigger are the callback hooks placed with the event trigger method. for more on uvm callback refer to uvm_callback.

  • User can write user-defined callback class by extending the uvm_event_callback
  • User can override any or both pre_trigger and post_trigger methods in user-defined callback class
  • uvm_event method add_callback is used to register the callback with event

uvm event callbacks are an alternative to using processes that wait on events. When a callback is
attached to an event, the attached callback function/s is called each time the event is triggered.

Writing user-defined callback,

class user_defined_callback extends uvm_event_callback;
    
  --- 

endclass 

uvm_event_callback methods

new

Creates a new callback object.

pre_trigger

virtual function bit pre_trigger (
  uvm_event#(T) e,
  T data )

// e is the uvm_event#(T) that is being triggered
// data is the data associated with the event trigger
  • This will get called just before triggering the associated event
  • In extended class, the user can override this method in a derived class to implement any pre-trigger functionality
  • This method returns bit type
  • If the method returns 1, the event will not trigger and the post-trigger callback is not called. This provides a way for a callback to prevent the event from triggering

post_trigger

virtual function void post_trigger (
  uvm_event#(T) e,
  T data )

// e is the uvm_event#(T) that is being triggered
// data is the data associated with the event trigger
  • This will get called after triggering the associated event
  • In extended class, the user can  override this method to implement any post-trigger functionality

uvm event callback examples

In the below example,

  • comp_a, comp_b, and a user-defined callback class event_callback
  • comp_a and comp_b will get the event ev_ab from the uvm event pool
  • pre_trigger and post_trigger methods are implemented in the event_callback class
  • In the comp_a event_callback object is created with the name ev_cb
  • uvm_event add_callback method is used to register the callback with an event (ev.add_callback(ev_cb);)
  • On calling event.trigger pre_trigger and post_trigger methods will get called

Writing user-defined event callback class

class event_callback extends uvm_event_callback;
   
  `uvm_object_utils(event_callback)
   
  function new(string name = "event_callback");
    super.new(name);
  endfunction

  //---------------------------------------
  // pre trigger method
  //---------------------------------------
  virtual function bit pre_trigger(uvm_event e,uvm_object data);
    `uvm_info(get_type_name(),$sformatf(" [Callback] Inside event pre_trigger callback"),UVM_LOW)
  endfunction
  
  //---------------------------------------
  // post trigger method
  //---------------------------------------
  virtual function void post_trigger(uvm_event e,uvm_object data);
    `uvm_info(get_type_name(),$sformatf(" [Callback] Inside event post_trigger callback"),UVM_LOW)
  endfunction

endclass

Creating a callback object and registering with the event

//Declaring the event callback class
event_callback ev_cb;

//Creating object
ev_cb = new("ev_cb");

//Registering callback with an event ev
ev.add_callback(ev_cb);

Complete comp_a code

class component_a extends uvm_component; 
  
  `uvm_component_utils(component_a)
  
  uvm_event      ev;
  event_callback ev_cb;
  
  //--------------------------------------- 
  // Constructor
  //---------------------------------------
  function new(string name, uvm_component parent);
    super.new(name, parent);
  endfunction : new

  //---------------------------------------
  // run_phase 
  //---------------------------------------
  virtual task run_phase(uvm_phase phase);
    phase.raise_objection(this);
    ev_cb = new("ev_cb");
    
    ev = uvm_event_pool::get_global("ev_ab");
    ev.add_callback(ev_cb);
    
    `uvm_info(get_type_name(),$sformatf(" Before triggering the event"),UVM_LOW)
    #10;
    
    ev.trigger();
    
    `uvm_info(get_type_name(),$sformatf(" After triggering the event"),UVM_LOW)

    phase.drop_objection(this);
  endtask : run_phase

endclass : component_a

Simulator Output

UVM_INFO @ 0: reporter [RNTST] Running test basic_test...
--------------------------------------
Name Type Size Value
--------------------------------------
uvm_test_top basic_test - @335 
 comp_a component_a - @348 
 comp_b component_b - @357 
--------------------------------------
UVM_INFO component_a.sv(29) @ 0: uvm_test_top.comp_a [component_a] Before triggering the event
UVM_INFO component_b.sv(26) @ 0: uvm_test_top.comp_b [component_b] waiting for the event trigger
UVM_INFO event_callback.sv(17) @ 10: reporter [event_callback] [Callback] Inside event pre_trigger callback
UVM_INFO event_callback.sv(24) @ 10: reporter [event_callback] [Callback] Inside event post_trigger callback
UVM_INFO component_a.sv(34) @ 10: uvm_test_top.comp_a [component_a] After triggering the event
UVM_INFO component_b.sv(30) @ 10: uvm_test_top.comp_b [component_b] event got triggerd
UVM_INFO /apps/vcsmx/etc/uvm-1.2/src/base/uvm_objection.svh(1270) @ 10: reporter [TEST_DONE]
UVM_INFO /apps/vcsmx/etc/uvm-1.2/src/base/uvm_report_server.svh(847) @ 10: reporter [UVM/REPORT/SERVER]

Click to execute on   

❮ Previous Next ❯