# Reuse task between multiple interfaces using package

**URL:** <https://verificationacademy.com/forums/t/reuse-task-between-multiple-interfaces-using-package/38102>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog, interface, package-importing\
**Created:** [September 21, 2020, 6:48pm UTC](https://verificationacademy.com/forums/t/reuse-task-between-multiple-interfaces-using-package/38102 "2020-09-21T18:48:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![agstod](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/a/e495f1/32.png) [@agstod](https://verificationacademy.com/forums/u/agstod)\
**Post date:** [September 21, 2020, 6:48pm UTC](https://verificationacademy.com/forums/t/reuse-task-between-multiple-interfaces-using-package/38102/1 "2020-09-21T18:48:33Z")

</div>

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?

```verilog

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?

---

<div class="post-metadata">

**Author:** ![user49](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/user49/32/4533_2.png) [@user49](https://verificationacademy.com/forums/u/user49)\
**Post date:** [September 21, 2020, 11:13pm UTC](https://verificationacademy.com/forums/t/reuse-task-between-multiple-interfaces-using-package/38102/2 "2020-09-21T23:13:30Z")

</div>

_In reply to [ce\_2015](https://verificationacademy.com/forums/t/reuse-task-between-multiple-interfaces-using-package/38102):_  
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/](http://www.systemverilog.us/) [ben@systemverilog.us](mailto:ben@systemverilog.us)  
For training, consulting, services: contact [Home - My cvcblr](http://cvcblr.com/home)

\*\* 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](https://rb.gy/a89jlh)
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](https://rb.gy/9tcbhl)  
Real Chip Design and Verification Using Verilog and VHDL($3) [Amazon.com](https://rb.gy/cwy7nb)
3. Papers:

- SVA Alternative for Complex Assertions  
[Verification Horizons - March 2018 Issue | Verification Academy](https://verificationacademy.com/news/verification-horizons-march-2018-issue)
- SVA in a UVM Class-based Environment  
[SVA in a UVM Class-based Environment | Verification Horizons | Verification Academy](https://verificationacademy.com/verification-horizons/february-2013-volume-9-issue-1/SVA-in-a-UVM-Class-based-Environment)
- Understanding the SVA Engine,  
[Verification Horizons - July 2020 | Verification Academy](https://verificationacademy.com/verification-horizons/july-2020-volume-16-issue-2)

---

<div class="post-metadata">

**Author:** ![agstod](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/a/e495f1/32.png) [@agstod](https://verificationacademy.com/forums/u/agstod)\
**Post date:** [September 22, 2020, 3:28pm UTC](https://verificationacademy.com/forums/t/reuse-task-between-multiple-interfaces-using-package/38102/3 "2020-09-22T15:28:40Z")

</div>

_In reply to [ben@SystemVerilog.us](https://verificationacademy.com/forums/t/reuse-task-between-multiple-interfaces-using-package/38102/2):_

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

I too am seeing this as the only way.
