Reuse task between multiple interfaces using package

I have two interfaces that I would like to call the same driver task with automatic lifetime (so that each interface gets its own copy of the task). It seems like there should be a way to use a package to share the common code. Or is there some other way?


package automatic some_pkg;
   automatic logic clk, data;
   task drive_data(logic a);
      @ (posedge clk);
      data = a & data;
   endtask
endpackage : some_pkg

interface some_interface0;
   import some_pkg::*;

   logic if_clk, if_data, b;
   
   assign if_clk  = clk;  // clk is from some_pkg
   assign if_data = data; // data is from some_pkg

   initial begin
      b = 0;
      drive_data(b);
   end
endinterface : some_interface0

interface some_interface1;
   import some_pkg::*;

   logic if_clk, if_data, c;
   
   assign if_clk  = clk;  // clk is from some_pkg
   assign if_data = data; // data is from some_pkg

   initial begin
      c = 1;
      drive_data(c);
   end
endinterface : some_interface1


Is this possible in SystemVerilog somehow?

In reply to ce_2015:
Your approach is quite a diversion from using an approach like UVM with the use of classes instead of packages. I believe that you are better off using classes instead.

Ben Cohen
http://www.systemverilog.us/ ben@systemverilog.us
For training, consulting, services: contact Home - My cvcblr

** SVA Handbook 4th Edition, 2016 ISBN 978-1518681448

  1. SVA Package: Dynamic and range delays and repeats SVA: Package for dynamic and range delays and repeats | Verification Academy
  2. Free books: Component Design by Example FREE BOOK: Component Design by Example … A Step-by-Step Process Using VHDL with UART as Vehicle | Verification Academy
    Real Chip Design and Verification Using Verilog and VHDL($3) Amazon.com
  3. Papers:

In reply to ben@SystemVerilog.us:

Yes, and a virtual interface to connect the class to the interface signals?

I too am seeing this as the only way.