quick.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

   

space.gif

   

space.gif

  ../images/main/bulllet_4dots_orange.gif Tasks and Function in Interface

Interfaces can contain Task and Functions. They can either reside inside the interfac block or can be external to interface, but inside the module which uses this interfaces. If the tasks or functions are defined in a module, using a hierarchical name, they must also be declared as extern in the interface or as export in a modport.

   

space.gif

It is a error for more than one module to export the same task name.

   

space.gif

Below example shows how to use the various features of task and function inside a interfaces.

   

space.gif

   

space.gif

  ../images/main/bullet_star_pink.gif Example : Task and Function
   

space.gif


   1 //+++++++++++++++++++++++++++++++++++++++++++++++++
   2 // Define the interface
   3 //+++++++++++++++++++++++++++++++++++++++++++++++++
   4 interface task_function_if (input clk);
   5   logic    req;
   6   logic    gnt;
   7   //=================================================
   8   //  Clocking block for tb modport
   9   //=================================================
  10   clocking cb @ (posedge clk);
  11     input  gnt;
  12     output req;
  13   endclocking
  14   //=================================================
  15   //  Task inside a interface, You can basically
  16   // Write a BFM, who's input can be a class or 
  17   // a mailbox, so on..... SO COOL!!!!
  18   //=================================================
  19   task drive_req (input integer delay, input bit value);
  20     $display("@%0dns Before driving req %b from task at %m", $time, req);
  21     repeat (delay) @ (posedge clk);
  22     req = value;
  23     $display("@%0dns Driving req %b from task at %m", $time, req);
  24   endtask
  25   //=================================================
  26   //  Mod port with exporting and importing tasks
  27   //=================================================
  28   modport  dut (input clk,req, output gnt
  29       //, export print_md, import print_tb 
  30      );
  31   //=================================================
  32   //  Mod Port with exporting and importing tasks
  33   //=================================================
  34   modport  tb (clocking cb, input clk, 
  35      import drive_req 
  36      //, print_md, export print_tb 
  37      );
  38 
  39 endinterface
  40 //+++++++++++++++++++++++++++++++++++++++++++++++++
  41 // DUT Code
  42 // Uses just the interface keyword
  43 //+++++++++++++++++++++++++++++++++++++++++++++++++
  44 module dut_ex (interface abc); 
  45   //=================================================
  46   //  Task print_md, which is exported
  47   //=================================================
  48   //task abc.print_md (input logic something);
  49   //    $display("@%0dns Inside %m : From print_md", $time);
  50   //    $display("Value of req %b gnt %b in %m",abc.req, abc.gnt);
  51   //endtask
  52   //=================================================
  53   //  Simple DUT Logic and calling task in another
  54   //  Module through interface
  55   //=================================================
  56    always @ (posedge abc.clk)
  57    begin
  58       abc.gnt <= abc.req;
  59       $display("@%0dns Request is %b", $time, abc.req);
  60       if (abc.req === 1'bx) begin
  61         //abc.print_tb(1'bx);
  62       end
  63       if (abc.req === 1'b0) begin
  64         //abc.print_tb(1'b0);
  65       end
  66       if (abc.req === 1'b1) begin
  67         //abc.print_tb(1'b1);
  68       end
  69     end
  70 
  71 endmodule
  72 
  73 //+++++++++++++++++++++++++++++++++++++++++++++++++
  74 // TB Code
  75 // Uses just the interface keyword
  76 //+++++++++++++++++++++++++++++++++++++++++++++++++
  77 module tb_ex (interface xyz);
  78   //=================================================
  79   //  Task print_tb, which is exported
  80   //=================================================
  81   //task xyz.print_tb (input bit something);
  82   //  $display("@%0dns %m Value of req : %b", $time, something);
  83   //endtask
  84   //=================================================
  85   // Test vector generation with task in another
  86   // Module and in interface calling 
  87   //=================================================
  88   initial begin
  89     xyz.cb.req <= 0;
  90     xyz.drive_req(10,1);
  91     xyz.drive_req(10,0);
  92     //xyz.print_md(0);
  93      #2  $finish; 
  94   end
  95 
  96 endmodule
  97 //+++++++++++++++++++++++++++++++++++++++++++++++++
  98 // Top level testbench file
  99 //+++++++++++++++++++++++++++++++++++++++++++++++++
 100 module interface_task_function();
 101   //=================================================
 102   //  Clock generator
 103   //=================================================
 104   logic clk = 0;
 105   always  #1  clk++;
 106   //=================================================
 107   //  Interface instance
 108   //=================================================
 109   task_function_if tfif(clk);
 110   //=================================================
 111   //  DUT and TB instance
 112   //=================================================
 113   dut_ex U_dut(tfif.dut);
 114   tb_ex  U_tb(tfif.tb);
 115 
 116 endmodule
You could download file interface_task_function.sv here
   

space.gif

  ../images/main/bullet_star_pink.gif Simulation : Task and Function
   

space.gif

 @0ns Before driving req x from task at
  interface_task_function.tfif.drive_req
 @1ns Request is x
 @3ns Request is 0
 @5ns Request is 0
 @7ns Request is 0
 @9ns Request is 0
 @11ns Request is 0
 @13ns Request is 0
 @15ns Request is 0
 @17ns Request is 0
 @19ns Driving req 1 from task at
  interface_task_function.tfif.drive_req
 @19ns Before driving req 1 from
  task at interface_task_function.tfif.drive_req
 @19ns Request is 1
 @21ns Request is 1
 @23ns Request is 1
 @25ns Request is 1
 @27ns Request is 1
 @29ns Request is 1
 @31ns Request is 1
 @33ns Request is 1
 @35ns Request is 1
 @37ns Request is 1
 @39ns Driving req 0 from task at 
 interface_task_function.tfif.drive_req
 @39ns Request is 0
   

space.gif

   

space.gif

   

space.gif

   

space.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

  

Copyright © 1998-2014

Deepak Kumar Tala - All rights reserved

Do you have any Comment? mail me at:deepak@asic-world.com