quick.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

   

space.gif

   

space.gif

  ../images/main/bullet_green_ball.gif Introduction

High-level and easy-to-use synchronization and communication mechanism are essential to control the kinds of interactions that occur between dynamic processes used to model a complex system or a highly reactive testbench. Verilog provides basic synchronization mechanisms (i.e., -> and @), but they are all limited to static objects and are adequate for synchronization at the hardware level, but fall short of the needs of a highly dynamic, reactive testbench. At the system level, an essential limitation of Verilog is its inability to create dynamic events and communication channels, which match the capability to create dynamic processes.

   

space.gif

SystemVerilog provides following to help interprocess communication

   

space.gif

   

space.gif

  • Semaphore
  • Mailbox
  • Events
   

space.gif

  ../images/main/bulllet_4dots_orange.gif Semaphore

Semaphore is used for lock/unlock of a common resource. If resource is in unlock state the resource can be used, if it is in lock state, then it can not be used.

   

space.gif

Lets assume that in a Verification env, we have single ethernet port/driver and there are 2 packet generators using this one ethernet port, one generating normal frames and other generating flow control (pause) frames.

   

space.gif

So each of this two packet generators can use semaphone to if ethenet driver is free (unlock) state, before it can transmit the frame. So if the driver is free, then it locks the drivers and transmits the frame, once tramitted, it unlocks the drivers.

   

space.gif

When driver is in lock state, it will wait till driver is in unlock state.

   

space.gif

Semaphore in SystemVerilog supports following methods for above operations.

   

space.gif

  • Semaphore allocation : new()
  • Using semaphore keys : get()
  • Returing semaphore keys : put()
  • Try to obtain one or more keys without blocking: try_get()
   

space.gif

   

space.gif

  ../images/main/bullet_star_pink.gif new()

Semaphores are created with the new() method.

   

space.gif

function new(int keyCount = 0 );
   

space.gif

Where

   

space.gif

  • keycount : The keyCount specifies the number of keys initially allocated to the semaphore bucket.
  • The new() function returns the semaphore handle or, if the semaphore cannot be created, null.
   

space.gif

   

space.gif

   

space.gif

  ../images/main/bullet_star_pink.gif put()

The semaphore put() method is used to return keys to a semaphore.

   

space.gif

task put(int keyCount = 1);
   

space.gif

Where

   

space.gif

  • The keyCount specifies the number of keys being returned to the semaphore. The default is 1.
   

space.gif

  ../images/main/bullet_star_pink.gif get()

The semaphore get() method is used to procure a specified number of keys from a semaphore.

   

space.gif

task get(int keyCount = 1);
   

space.gif

Where

   

space.gif

  • The keyCount specifies the required number of keys to obtain from the semaphore. The default is 1.
  • If the specified number of keys is not available, the process blocks until the keys become available.
  • The semaphore waiting queue is first-in first-out (FIFO).
   

space.gif

  ../images/main/bullet_star_pink.gif try_get()

The semaphore try_get() method is used to procure a specified number of keys from a semaphore, but without blocking.

   

space.gif

function int try_get(int keyCount = 1);
   

space.gif

Where

   

space.gif

  • The keyCount specifies the required number of keys to obtain from the semaphore. The default is 1.
  • If the specified number of keys is available, the method returns a positive integer and execution continues.
  • If the specified number of keys is not available, the method returns 0.
   

space.gif

  ../images/main/bullet_star_pink.gif Example : Semaphore
   

space.gif


  1 program semaphore_ex;
  2 
  3   semaphore  semBus = new(1);
  4 
  5   initial begin
  6     fork 
  7       agent("AGENT 0",5);
  8       agent("AGENT 1",20);
  9     join
 10   end
 11 
 12   task automatic agent(string name, integer nwait);
 13     integer i = 0;
 14     for (i = 0 ; i < 4; i ++ ) begin
 15       semBus.get(1);
 16       $display("[%0d] Lock semBus for %s", $time,name);
 17       #(nwait);
 18       $display("[%0d] Release semBus for %s", $time,name);
 19       semBus.put(1);
 20       #(nwait);
 21     end
 22   endtask
 23 
 24 endprogram
You could download file semaphore_ex.sv here
   

space.gif

  ../images/main/bullet_star_pink.gif Simulation : Semaphore
   

space.gif

 [0] Lock semBus for AGENT 0
 [5] Release semBus for AGENT 0
 [5] Lock semBus for AGENT 1
 [25] Release semBus for AGENT 1
 [25] Lock semBus for AGENT 0
 [30] Release semBus for AGENT 0
 [35] Lock semBus for AGENT 0
 [40] Release semBus for AGENT 0
 [45] Lock semBus for AGENT 1
 [65] Release semBus for AGENT 1
 [65] Lock semBus for AGENT 0
 [70] Release semBus for AGENT 0
 [85] Lock semBus for AGENT 1
 [105] Release semBus for AGENT 1
 [125] Lock semBus for AGENT 1
 [145] Release semBus for AGENT 1
   

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