forked from hemanth-VP/SystemVerilog_Course
-
Notifications
You must be signed in to change notification settings - Fork 0
/
peek.sv
89 lines (63 loc) · 1.75 KB
/
peek.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
//--------------------------------------------------------------------------------------------
//peek_method:
//
//Copies data from the mailbox without removing it from a mailbox
//
//--------------------------------------------------------------------------------------------
//Transmitter
class A;
int a;
int i;
mailbox m;
function new(mailbox m1);
this.m = m1;
endfunction
task tra_data();
for(i=0;i<1;i++)begin:BEGIN_MAIN
a++;
m.put(a);
$display("[%0t] 1. Transmitter: value of a = %0d",$time,a);
end:BEGIN_MAIN
$display("put successful");
$display("Messages in mailbox = %0d",m.num());
endtask
endclass:A
//Receiver
class B;
int a;
int i;
mailbox m;
function new(mailbox m2);
this.m = m2;
endfunction
task rec_data();
for(i =0;i<2;i++)begin:BEGIN_MAIN
m.peek(a);
//begin
$display("[%0t] Peeking value of a = %0d",$time,a);
$display("Peek successful");
//end
//else
//$display("po ra");
end:BEGIN_MAIN
m.get(a);
$display("[%0t] 2. Receiver: value of a = %0d",$time,a);
$display("get successful");
$display("Messages in mailbox = %0d",m.num());
endtask
endclass:B
module tb();
A a1;
B b1;
mailbox main = new(2);
initial begin:BEGIN_MAIN
a1 = new(main);
b1 = new(main);
a1.tra_data();
$display("...............................................");
b1.rec_data();
$display("...............................................");
b1.rec_data();
$display("End of program");
end:BEGIN_MAIN
endmodule:tb