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 mailbox

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.

   

space.gif

VERA provides following methods for working with mailbox.

   

space.gif

  • Mailbox allocation
  • Put data
  • Get data
   

space.gif

Mailbox Allocation

   

space.gif

function integer alloc(MAILBOX, integer mailbox_id, integer
mailbox_count);
   

space.gif

Where

   

space.gif

  • mailbox_id : Is the ID number of the particular mailbox being created. It must be an integer value. You should generally use 0. When you use 0, Vera automatically generates a mailbox ID.
  • mailbox_count : Specifies how many mailboxes you want to create. It must be an integer value.
   

space.gif

Put Data into Mailbox

   

space.gif

task mailbox_put(integer mailbox_id, any_scalar_type data)
task mailbox_put(integer mailbox_id, object_type data)
   

space.gif

Where

   

space.gif

  • mailbox_id : Specifies which mailbox receives the data.
  • data : Can be any general expression that evaluates to any scalar or object type.
   

space.gif

Get Data from Mailbox

   

space.gif

function integer mailbox_get(NO_WAIT | WAIT | COPY_NO_WAIT |
COPY_WAIT, integer mailbox_id [, any_scalar_type dest_var [,
CHECK]]);
function integer mailbox_get(NO_WAIT | WAIT |COPY_NO_WAIT |
COPY_WAIT, integer mailbox_id [, object_type dest_var
[,CHECK]]);
   

space.gif

Where

   

space.gif

  • NO_WAIT : Dequeues mailbox data if it is available. Otherwise, it returns an empty status (0).
  • WAIT : Suspends the calling thread until data is available in the mailbox, and then dequeues the data.
  • COPY_NO_WAIT : Copies mailbox data without dequeuing it if it is available. Otherwise, it returns an empty status (0).
  • COPY_WAIT : Suspends the calling thread until data is available in the mailbox, and then copies the data without dequeuing it.
  • mailbox_id : specifies which mailbox data is being retrieved from.
  • dest_var : Is the destination variable of the mailbox data.
  • CHECK: CHECK specifies whether type checking occurs between the mailbox data and the destination variable. CHECK is optional.
   

space.gif

   

space.gif

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

space.gif


  1 program mailbox {
  2   integer checker_data;
  3   checker_data  = alloc(MAILBOX,0,1);
  4 
  5   fork
  6     { input_monitor();}
  7     { checker();}
  8   join any
  9 
 10   delay(1000);
 11 
 12 }
 13 
 14 task input_monitor() {
 15   integer i = 0;
 16   // This can be any valid data type
 17   bit [7:0] data = 0; 
 18   for(i = 0; i < 4; i ++) {
 19     delay(3);
 20     data = random();
 21     printf("[%0d] Putting data : %x into mailbox\n", get_time(LO),data);
 22     mailbox_put(checker_data,data);    
 23   }
 24 }
 25 
 26 task checker() {
 27   integer i = 0;
 28   // This can be any valid data type
 29   bit [7:0] data = 0; 
 30   while (1) {
 31     delay(1);
 32     if (mailbox_get(NO_WAIT,checker_data, data) > 0) {
 33       printf("[%0d] Got data : %x from mailbox\n", get_time(LO),data);
 34     } else {
 35       delay(7);
 36     }
 37   }
 38 }
You could download file mailbox.vr here
   

space.gif

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

space.gif

 [3] Putting data : 36 into mailbox
 [6] Putting data : 3c into mailbox
 [9] Putting data : 7d into mailbox
 [9] Got data : 36 from mailbox
 [10] Got data : 3c from mailbox
 [11] Got data : 7d from mailbox
 [12] Putting data : e2 into mailbox
 [12] Got data : e2 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