forked from luuvish/amba3-vip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpkg_amba3_apb_monitor.svh
174 lines (144 loc) · 4.95 KB
/
pkg_amba3_apb_monitor.svh
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*==============================================================================
The MIT License (MIT)
Copyright (c) 2014 Luuvish Hwang
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
================================================================================
File : pkg_amba3_apb_monitor.svh
Author(s) : luuvish (github.com/luuvish/amba3-vip)
Modifier : luuvish ([email protected])
Descriptions : package for amba 3 apb 1.0 monitor
==============================================================================*/
class amba3_apb_monitor_t #(
parameter integer ADDR_BITS = 32,
DATA_BITS = 32
);
typedef virtual amba3_apb_if #(ADDR_BITS, DATA_BITS).monitor apb_t;
typedef struct {
logic psel;
logic penable;
logic pwrite;
logic [ADDR_BITS - 1:0] paddr;
logic [DATA_BITS - 1:0] pwdata;
logic [DATA_BITS - 1:0] prdata;
logic pready;
} hold_t;
protected apb_t apb;
protected integer file;
protected hold_t hold;
function new (input apb_t apb, string filename = "");
this.apb = apb;
this.file = -1;
if (filename != "") begin
this.file = $fopen(filename, "w");
end
this.hold = '{default: '0};
endfunction
virtual task start ();
clear();
fork
forever begin
listen();
end
join_none
endtask
virtual task listen ();
fork : loop
begin
apb.monitor_reset();
disable loop;
end
forever report_write();
forever report_read();
forever check_hold();
join_any
disable fork;
endtask
virtual task clear ();
apb.monitor_clear();
endtask
virtual protected task report_write ();
wait (apb.monitor_cb.psel == 1'b1 && apb.monitor_cb.penable == 1'b1 &&
apb.monitor_cb.pwrite == 1'b1 && apb.monitor_cb.pready == 1'b1);
report($sformatf("apb write %x %x",
apb.monitor_cb.paddr,
apb.monitor_cb.pwdata
));
@(apb.monitor_cb);
endtask
virtual protected task report_read ();
wait (apb.monitor_cb.psel == 1'b1 && apb.monitor_cb.penable == 1'b1 &&
apb.monitor_cb.pwrite == 1'b0 && apb.monitor_cb.pready == 1'b1);
report($sformatf("apb read %x %x",
apb.monitor_cb.paddr,
apb.monitor_cb.prdata
));
@(apb.monitor_cb);
endtask
virtual protected task check_hold ();
hold_t now = '{
psel : apb.monitor_cb.psel,
penable: apb.monitor_cb.penable,
pwrite : apb.monitor_cb.pwrite,
paddr : apb.monitor_cb.paddr,
pwdata : apb.monitor_cb.pwdata,
prdata : apb.monitor_cb.prdata,
pready : apb.monitor_cb.pready
};
if (hold.psel == 1'b1 && now.psel == 1'b0) begin
report($sformatf("apb check psel %x is changed before pready",
now.psel
));
end
if (hold.psel == 1'b0) begin
if (now.penable == 1'b1)
report($sformatf("apb check penable %x is set first stage",
now.penable
));
end
else begin
if (hold.penable == 1'b1 && now.penable == 1'b0)
report($sformatf("apb check penable %x is changed before pready",
now.penable
));
end
if (hold.psel == 1'b1) begin
if (hold.paddr != now.paddr)
report($sformatf("apb check paddr %x is changed before pready",
now.paddr
));
if (hold.pwrite != now.pwrite)
report($sformatf("apb check pwrite %0d is changed before pready",
now.pwrite
));
if (now.pwrite == 1'b1 && hold.pwdata != now.pwdata)
report($sformatf("apb check pwdata %x is changed before pready",
now.pwdata
));
end
if (now.psel == 1'b1 && now.penable == 1'b1 && now.pready == 1'b1)
hold = '{default: '0};
else
hold = now;
@(apb.monitor_cb);
endtask
virtual task report (input string text);
string log = $sformatf("@%0dns %s", $time, text);
if (file == -1)
$display(log);
else
$fdisplay(file, log);
endtask
endclass