forked from hemanth-VP/SystemVerilog_Course
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bound.sv
89 lines (58 loc) · 1.55 KB
/
bound.sv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//--------------------------------------------------------------------------------------------
//Bounded mailbox:
//
//A bounded mailbox is with the size defined. Mailbox becomes full when on storing a
//bounded number of messages.
//
//--------------------------------------------------------------------------------------------
class A;
int a;
int i;
mailbox m;
function new(mailbox m1);
this.m = m1;
endfunction
task tra_data();
for(i =0;i<3;i++)begin:BEGIN_MAIN
if(m.num()==2)begin:BEGIN_1
$display("mailbox is full");
end:BEGIN_1
else
begin:BEGIN_2
a++;
m.put(a);
$display("[%0t] 1. Transmitter: value of a = %0d",$time,a);
end:BEGIN_2
end:BEGIN_MAIN
endtask
endclass:A
// Receiver
class B;
int a;
int i;
mailbox m;
function new(mailbox m2);
this.m = m2;
endfunction
task rec_data();
begin:BEGIN_MAIN
m.get(a);
$display("[%0t] 2. Receiver: value of a = %0d",$time,a);
end:BEGIN_MAIN
endtask
endclass:B
module tb();
A a1;
B b1;
mailbox mb = new(2);
initial begin:BEGIN_MAIN
a1 = new(mb);
b1 = new(mb);
repeat(3)
begin:BEGIN_1
a1.tra_data();
$display("...............................................");
b1.rec_data();
end:BEGIN_1
end:BEGIN_MAIN
endmodule:tb