Showing posts with label task. Show all posts
Showing posts with label task. Show all posts

Saturday, 18 June 2016

Task inside Interface

interface simple_bus (input logic clk); // Define the interface
  logic req, gnt;
  logic [7:0] addr, data;
  logic [1:0] mode;
  logic start, rdy;

modport slave(input req, addr, mode, start, clk,
               output gnt, rdy,
               ref data,
               import slaveRead,slaveWrite);
             
//import into module that uses the modport
modport master(input gnt, rdy, clk,
               output req, addr, mode, start,
               ref data,
               import masterRead,masterWrite);
             
//import into module that uses the modport
task masterRead(input logic[7:0] raddr=8'h0); // masterRead method
  $display("Inside Master_Read");
endtask
             
task slaveRead;
  $display("Inside Slave_Read");
endtask
           
task masterWrite(input logic [7:0] waddr=8'h0);
  $display("Inside Master_Write");
endtask
             
task slaveWrite;
  $display("Inside Slave_Write");
endtask
             
endinterface: simple_bus
             
             
module mod (interface i)               ;
  always@(posedge i.clk) begin
     i.slaveRead;
     i.masterRead;
     i.slaveWrite;
     i.masterWrite;
   end              
endmodule
               
module top;
  logic clk = 0;
   simple_bus sb_intf(clk); // Instantiate the interface
   mod m (sb_intf.master) ;

   always #5 clk=!clk;
                 
   initial begin
      #50 $finish;                  
   end                                  

endmodule

Monday, 22 June 2015

System Verilog Process

How to disable particular process of fork...join,executing multiple processes in parallel.


class a;
  int v;

  task t1();
    for(int i=0;i<10;i++) begin
      #1 v=i;
      $display("I value=%0d",v);
    end
  endtask:t1
 
   task t2();
     for(int i=10;i<20;i++)begin
       #1 v=i;
       $display("I value=%0d",v);
     end 
  endtask :t2
 
  task t3();
    process job_id[2];                                 //Process Identifier
    fork
       begin:t1p
         job_id[0] = process::self();
         t1();
       end 
       begin:t2p
         job_id[1] = process::self();
         t2();
       end 
       begin:t3p
         int j;
         forever begin
           @(v)begin
           $display($time,"forever",j);
           j++;
             if(v==14)begin
               job_id[0].kill();                         //Kill process executing task t1();
             $display("Entered");
             //disable t1p;
             break;
          end
         end
          
         end
       end 
    join
  endtask :t3     
 
endclass:a


module test();
  a a1;
  initial
    begin
      a1=new();
      a1.t3();     
    end
endmodule

Note:-Why can't simple disable ...fork statement can be used....?????