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 Mailboxes

A mailbox is a mechanism to exchange messages between processes. Data can be sent to a mailbox by one process and retrieved by another. Mailbox can be used a FIFO if required. Data can be any valid systemVerilog data types, including class data types.

   

space.gif

SystemVerilog provides following methods for working with mailbox.

   

space.gif

  • Mailbox allocation : new()
  • Put data : put()
  • Try to place a message in a mailbox without blocking: try_put()
  • Get data : get() or peek()
  • Try to retrieve a message from a mailbox without blocking: try_get() or try_peek()
  • Retrieve the number of messages in the mailbox: num()
   

space.gif

Nonparameterized mailboxes are typeless, that is, a single mailbox can send and receive different types of data. Thus, in addition to the data being sent (i.e., the message queue), a mailbox implementation must maintain the message data type placed by put(). This is required in order to enable the run-time type checking.

   

space.gif

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

Mailboxes are created with the new() method.

   

space.gif

function new(int bound = 0);
   

space.gif

  • The new() function returns the mailbox handle or, if the mailbox cannot be created, null.
  • If the bound argument is 0, then the mailbox is unbounded (the default) and a put() operation shall never block.
   

space.gif

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

The number of messages in a mailbox can be obtained via the num() method.

   

space.gif

function int num();
   

space.gif

  • The num() method returns the number of messages currently in the mailbox.
  • The returned value should be used with care because it is valid only until the next get() or put() is executed on the mailbox.
   

space.gif

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

The put() method places a message in a mailbox.

   

space.gif

task put( singular message);
   

space.gif

  • The message is any singular expression, including object handles.
  • The put() method stores a message in the mailbox in strict FIFO order.
  • If the mailbox was created with a bounded queue, the process shall be suspended until there is enough space in the queue.
   

space.gif

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

The try_put() method attempts to place a message in a mailbox.

   

space.gif

function int try_put( singular message);
   

space.gif

  • The try_put() method stores a message in the mailbox in strict FIFO order.
  • If the mailbox is full, the method returns 0.
   

space.gif

   

space.gif

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

The get() method retrieves a message from a mailbox.

   

space.gif

task get( ref singular message );
   

space.gif

  • The get() method removes one message from queue.
  • If the mailbox is empty, then the current process blocks until a message is placed in the mailbox.
  • If the type of the message variable is not equivalent to the type of the message in the mailbox, a run-time error is generated.
   

space.gif

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

The try_get() method attempts to retrieves a message from a mailbox without blocking.

   

space.gif

function int try_get( ref singular message );
   

space.gif

  • The try_get() method tries to retrieve one message from the mailbox.
  • If the mailbox is empty, then the method returns 0.
   

space.gif

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

The peek() method copies a message from a mailbox without removing the message from the queue.

   

space.gif

task peek( ref singular message );
   

space.gif

  • The peek() method copies one message from the mailbox without removing the message from the mailbox queue.
  • If the mailbox is empty, then the current process blocks until a message is placed in the mailbox.
   

space.gif

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

The try_peek() method attempts to copy a message from a mailbox without blocking.

   

space.gif

function int try_peek( ref singular message );
   

space.gif

  • The try_peek() method tries to copy one message from the mailbox without removing the message from the mailbox queue.
  • If the mailbox is empty, then the method returns 0.
   

space.gif

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

space.gif


  1 program mailbox_ex;
  2   mailbox checker_data  = new();
  3 
  4   initial begin
  5     fork
  6       input_monitor();
  7       checker();
  8     join_any
  9      #1000 ;
 10   end
 11 
 12   task input_monitor();
 13     begin
 14       integer i = 0;
 15       // This can be any valid data type
 16       bit [7:0] data = 0; 
 17       for(i = 0; i < 4; i ++) begin
 18         #(3);
 19         data = $random();
 20         $display("[%0d] Putting data : %x into mailbox", $time,data);
 21         checker_data.put(data);    
 22       end
 23     end
 24   endtask
 25   
 26   task checker();
 27     begin
 28       integer i = 0;
 29       // This can be any valid data type
 30       bit [7:0] data = 0; 
 31       while (1) begin
 32         #(1);
 33         if (checker_data.num() > 0) begin
 34           checker_data.get(data);
 35           $display("[%0d] Got data : %x from mailbox", $time,data);
 36         end else begin
 37           #(7);
 38         end
 39       end
 40     end
 41   endtask
 42 
 43 endprogram
You could download file mailbox_ex.sv here
   

space.gif

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

space.gif

 [3] Putting data : 24 into mailbox
 [6] Putting data : 81 into mailbox
 [9] Putting data : 09 into mailbox
 [9] Got data : 24 from mailbox
 [10] Got data : 81 from mailbox
 [11] Got data : 09 from mailbox
 [12] Putting data : 63 into mailbox
 [12] Got data : 63 from mailbox
   

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