|HOME |ABOUT |ARTICLES |ACK |FEEDBACK |TOC |LINKS |BLOG |JOBS |


Tutorials



MAILBOX



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. Conceptually, mailboxes behave like real mailboxes. When a letter is delivered and put into the mailbox, you can retrieve the letter (and any data stored within). However, if the letter has not been delivered when you check the mailbox, you must choose whether to wait for the letter or retrieve the letter on subsequent trips to the mailbox.Similarly, OpenVera‚~@~Ys mailboxes allow you to transfer and retrieve data in a very controlled manner.

To allocate a mailbox, you must use the alloc() system function.
Syntax : function integer alloc(MAILBOX, integer mailbox_id, integer mailbox_count);
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.
The mailbox_put() system task sends data to the mailbox.
The mailbox_get() system function returns data stored in a mailbox.



EXAMPLE : Mailbox

#include "vera_defines.vrh"

program vshell
{
integer my_mailbox;

my_mailbox = alloc(MAILBOX, 0, 1);
if (my_mailbox)
{
fork
put_packets();
get_packets();
join none
}

delay(1000);
printf("END of Program\n");
}

task put_packets()
{
integer i;

for (i=0; i<10; i++)
{
delay(10);
mailbox_put(my_mailbox,i);
printf("Done putting packet %d @time %d\n",i, get_time(LO) );

}
}

task get_packets()
{
integer ret;
bit [63:0] packet;

while (1)
{
ret = mailbox_get(WAIT, my_mailbox, packet, CHECK);
if (ret > 0)
printf("Got packet %d @time %d\n", packet, get_time(LO) );
}
}

RESULTS

Done putting packet 0 @time 10
Got packet 0 @time 10
Done putting packet 1 @time 20
Got packet 1 @time 20
Done putting packet 2 @time 30
Got packet 2 @time 30
Done putting packet 3 @time 40
Got packet 3 @time 40
Done putting packet 4 @time 50
Got packet 4 @time 50
Done putting packet 5 @time 60
Got packet 5 @time 60
Done putting packet 6 @time 70
Got packet 6 @time 70
Done putting packet 7 @time 80
Got packet 7 @time 80
Done putting packet 8 @time 90
Got packet 8 @time 90
Done putting packet 9 @time 100
Got packet 9 @time 100

Index
Introduction
Data Types
Linked List
Operators Part 1
Operators Part 2
Operators Part 3
Operator Precedence
Control Statements
Procedures And Methods
Interprocess
Fork Join
Shadow Variables
Fork Join Control
Wait Var
Event Sync
Event Trigger
Semaphore
Regions
Mailbox
Timeouts
Oop
Casting
Randomization
Randomization Methods
Constraint Block
Constraint Expression
Variable Ordaring
Aop
Predefined Methods
String Methods
Queue Methods
Dut Communication
Functional Coverage

Report a Bug or Comment on This section - Your input is what keeps Testbench.in improving with time!





<< PREVIOUS PAGE

TOP

NEXT PAGE >>

copyright © 2007-2017 :: all rights reserved www.testbench.in::Disclaimer