Jump to content

Recommended Posts

Posted

Hi, experts, how to use macro uvm_set_super_type ??

`include "uvm_macros.svh"
import uvm_pkg::*;

program P;

class cb_base extends uvm_callback;
   function new(string name="cb_base");
      super.new(name);
   endfunction
   virtual function void fun_cb();
      `uvm_info(get_type_name(),"It's fun_cb in cb_base.", UVM_NONE);
   endfunction
   virtual function string get_type_name();
      return "cb_base";
   endfunction
endclass

class cb_derive extends cb_base;
   function new(string name="cb_derive");
      super.new(name);
   endfunction
   //function fun_cb();
   //   `uvm_info(get_type_name(),"It's fun_cb in cb_derive.", UVM_NONE);
   //endfunction
   virtual function void fun_cb_addeded();
      `uvm_info(get_type_name(),"It's fun_cb_added in cb_derive.", UVM_NONE)
   endfunction
   virtual function string get_type_name();
      return "cb_derive";
   endfunction
endclass

class cb_base2 extends uvm_callback;
   function new(string name="cb_base2");
      super.new(name);
   endfunction
   virtual function void fun_cb2();
      `uvm_info(get_type_name(),"It's fun_cb in cb_base2.", UVM_NONE)
   endfunction
   virtual function string get_type_name();
      return "cb_base2";
   endfunction
endclass

class hooked_comp extends uvm_component;
   `uvm_component_utils(hooked_comp)
   `uvm_register_cb(hooked_comp, cb_base) 
   `uvm_register_cb(hooked_comp, cb_base2)
   function new(string name="hooked_comp", uvm_component parent=null);
      super.new(name, parent);
   endfunction
   virtual task run();
      `uvm_info(get_type_name(), "run callback in hooked_comp:", UVM_NONE)
      #1;
      `uvm_do_callbacks(hooked_comp, cb_base, fun_cb)
      #1;
      `uvm_do_callbacks(hooked_comp, cb_base2, fun_cb2)
   endtask
endclass

class hooked_comp_d1 extends hooked_comp;
   `uvm_component_utils(hooked_comp_d1)
   [COLOR="#ff0000"]`uvm_set_super_type(hooked_comp_d1, hooked_comp)[/COLOR]
   `uvm_register_cb(hooked_comp_d1, cb_derive)
   function new(string name="hooked_comp_d1", uvm_component parent=null);
      super.new(name, parent);
   endfunction
   virtual task run();
      #3;
      $display("\n");
      `uvm_info(get_type_name(), "run callback in hooked_comp_d1:", UVM_NONE)
      `uvm_do_callbacks(hooked_comp_d1, cb_base, fun_cb)
      #1
      `uvm_do_callbacks(hooked_comp_d1, cb_derive, fun_cb_addeded)
      #1;
      [COLOR="#ff0000"]`uvm_do_callbacks(hooked_comp, cb_base2, fun_cb2)   //It seems it not work!!!!!!!!!!![/COLOR]
      #1;
      `uvm_info(get_type_name(), "wait to end testing...", UVM_NONE)
   endtask
endclass

typedef uvm_callbacks #(hooked_comp, cb_base) hooked_comp_cbs_t;
typedef uvm_callbacks #(hooked_comp, cb_base2) hooked_comp_cbs_t2;
class test_all extends uvm_test;
   `uvm_component_utils(test_all)
   hooked_comp     hc;
   hooked_comp_d1  hcd;
   cb_base   cb   = new("cb");
   cb_base2  cb2  = new("cb2");
   cb_derive cbd  = new("cbd");
   function new(string name="test_all", uvm_component parent=null);
      super.new(name, parent);
   endfunction
   function void build();
      super.build();
      hc  = hooked_comp::type_id::create("hc", this);
      hcd = hooked_comp_d1::type_id::create("hcd", this);
      hooked_comp_cbs_t::add(hc, cb);
      hooked_comp_cbs_t2::add(hc, cb2);
      hooked_comp_cbs_t::add(hcd, cbd);
   endfunction
   task run();
      #10;
      uvm_top.stop_request();
   endtask
endclass

initial run_test("test_all");

endprogram

Thanks in advance.

Posted

hi,

the embedded documentation shows the following usage model:

//-----------------------------------------------------------------------------
// MACRO: `uvm_set_super_type
//
// Defines the super type of T to be ST. This allows for derived class
// objects to inherit typewide callbacks that are registered with the base
// class.
//
// The registration will typically occur in the component that executes the
// given type of callback. For instance:
//
//| virtual class mycb extend uvm_callback;
//|   virtual function void doit();
//| endclass
//|
//| class my_comp extends uvm_component;
//|   `uvm_register_cb(my_comp,mycb)
//|   ...
//|   task run;
//|     ...
//|     `uvm_do_callbacks(my_comp, mycb, doit())
//|   endtask
//| endclass
//|
//| class my_derived_comp extends my_comp;
//|   `uvm_set_super_type(my_derived_comp,my_comp)
//|   ...
//|   task run;
//|     ...
//|     `uvm_do_callbacks(my_comp, mycb, doit())
//|   endtask
//| endclass
//-----------------------------------------------------------------------------

a more in depth example can be found here:

tests/09callbacks/20inherit/test.sv

regards

/uwe

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...