|
|
|
|
|
|
|
|
|
|
|
|
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. |
|
|
|
|
|
VERA provides following methods for working with mailbox. |
|
|
|
|
|
- Mailbox allocation
- Put data
- Get data
|
|
|
|
|
|
Mailbox Allocation |
|
|
|
|
|
function integer alloc(MAILBOX, integer mailbox_id, integer
mailbox_count);
|
|
|
|
|
|
Where |
|
|
|
|
|
- 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.
|
|
|
|
|
|
Put Data into Mailbox |
|
|
|
|
|
task mailbox_put(integer mailbox_id, any_scalar_type data)
task mailbox_put(integer mailbox_id, object_type data)
|
|
|
|
|
|
Where |
|
|
|
|
|
- mailbox_id : Specifies which mailbox receives the data.
- data : Can be any general expression that evaluates to any scalar or object type.
|
|
|
|
|
|
Get Data from Mailbox |
|
|
|
|
|
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]]);
|
|
|
|
|
|
Where |
|
|
|
|
|
- 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.
|
|
|
|
|
|
|
|
|
|
|
|
Example : mailbox
|
|
|
|
|
|
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
|
|
|
|
|
|
Simulation : mailbox
|
|
|
|
|
|
[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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Copyright © 1998-2014 |
Deepak Kumar Tala - All rights reserved |
Do you have any Comment? mail me at:deepak@asic-world.com
|
|