mspan_mon.v
6.41 KB
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
module mspan_mon(clock);
input clock;
//
// Encode 32 bit input
// Assumes input has only one bit set
// If low order bit is set, call that state 1 (not zero)
// this will let us index the initial 0 state (XXX could I use -1?)
function [4:0] ms_mon_encode;
input [32:0] i;
reg [4:0] z;
begin
if (i[ 0] == 1'b1)
z = 5'd1;
else if (i[ 1] == 1'b1)
z = 5'd2;
else if (i[ 2] == 1'b1)
z = 5'd3;
else if (i[ 3] == 1'b1)
z = 5'd4;
else if (i[ 4] == 1'b1)
z = 5'd5;
else if (i[ 5] == 1'b1)
z = 5'd6;
else if (i[ 6] == 1'b1)
z = 5'd7;
else if (i[ 7] == 1'b1)
z = 5'd8;
else if (i[ 8] == 1'b1)
z = 5'd9;
else if (i[ 9] == 1'b1)
z = 5'd10;
else if (i[10] == 1'b1)
z = 5'd11;
else if (i[11] == 1'b1)
z = 5'd12;
else if (i[12] == 1'b1)
z = 5'd13;
else if (i[13] == 1'b1)
z = 5'd14;
else if (i[14] == 1'b1)
z = 5'd15;
else if (i[15] == 1'b1)
z = 5'd16;
else if (i[16] == 1'b1)
z = 5'd17;
else if (i[17] == 1'b1)
z = 5'd18;
else if (i[18] == 1'b1)
z = 5'd19;
else if (i[19] == 1'b1)
z = 5'd20;
else if (i[20] == 1'b1)
z = 5'd21;
else if (i[21] == 1'b1)
z = 5'd22;
else if (i[22] == 1'b1)
z = 5'd23;
else if (i[23] == 1'b1)
z = 5'd24;
else if (i[24] == 1'b1)
z = 5'd25;
else if (i[25] == 1'b1)
z = 5'd26;
else if (i[26] == 1'b1)
z = 5'd27;
else if (i[27] == 1'b1)
z = 5'd28;
else if (i[28] == 1'b1)
z = 5'd29;
else if (i[29] == 1'b1)
z = 5'd30;
else if (i[30] == 1'b1)
z = 5'd31;
else
z = 5'd0;
ms_mon_encode = z;
end
endfunction
reg monitor_states;
reg monitor_gclk;
reg [31:0] gclock_max;
reg [31:0] gclock_cnt;
// ms_sc.state 4 possible states
reg [3:0] last_ms_sc_state;
reg [3:0] ms_sc_transitions[0:4];
// ms_si.state 4 possible states
reg [3:0] last_ms_si_state;
reg [3:0] ms_si_transitions[0:4];
// ms_sm.state 4 possible states
reg [21:0] last_ms_sm_state;
reg [21:0] ms_sm_transitions[0:22];
task ms_state_results;
begin : vcs_sucks_1
integer i;
if (monitor_states) begin
$display("MSPAN State Transitions");
// ms_sc_transitions:
$display("ms_sc_transitions");
for (i = 0; i<= 4; i = i + 1)
$display("%d - 0x%h", i, mspan_mon.ms_sc_transitions[i]);
// ms_si_transitions:
$display("ms_si_transitions");
for (i = 0; i<= 4; i = i + 1)
$display("%d - 0x%h", i, mspan_mon.ms_si_transitions[i]);
// ms_sm_transitions:
$display("ms_sm_transitions");
for (i = 0; i<= 22; i = i + 1)
$display("%d - 0x%h", i, mspan_mon.ms_sm_transitions[i]);
// ms_rp nirvana register
$display("ms_rp nirvana 0x%h", reality.rcp_0.rdp_0.ms.rp.nirvana);
// Pointer difference
$display("Z ptr: 0x%h - 0x%h = 0x%h", reality.rcp_0.rdp_0.ms.rbzwptr, reality.rcp_0.rdp_0.ms.rbzrptr, reality.rcp_0.rdp_0.ms.rbzwptr - reality.rcp_0.rdp_0.ms.rbzrptr);
if ((reality.rcp_0.rdp_0.ms.rbzwptr - reality.rcp_0.rdp_0.ms.rbzrptr) & 3'h7)
$display("ERROR Z ptr");
$display("C ptr: 0x%h - 0x%h = 0x%h", reality.rcp_0.rdp_0.ms.rbcwptr, reality.rcp_0.rdp_0.ms.rbcrptr, reality.rcp_0.rdp_0.ms.rbcwptr - reality.rcp_0.rdp_0.ms.rbcrptr);
if ((reality.rcp_0.rdp_0.ms.rbcwptr - reality.rcp_0.rdp_0.ms.rbcrptr) & 3'h7)
$display("ERROR C ptr");
// ms_sc arc registers
$display("ms_sc idle_arcs 0x%h", reality.rcp_0.rdp_0.ms.sc.idle_arcs);
$display("ms_sc spanlet_arcs 0x%h", reality.rcp_0.rdp_0.ms.sc.spanlet_arcs);
// ms_si arc registers
$display("ms_si firstwr_arcs 0x%h", reality.rcp_0.rdp_0.ms.si.firstwr_arcs);
$display("ms_si wrz_arcs 0x%h", reality.rcp_0.rdp_0.ms.si.wrz_arcs);
$display("ms_si rdc_arcs 0x%h", reality.rcp_0.rdp_0.ms.si.rdc_arcs);
// ms_sm arc registers
$display("ms_sm rdctxt_arcs 0x%h", reality.rcp_0.rdp_0.ms.sm.rdctxt_arcs);
$display("ms_sm rdcdata_arcs 0x%h", reality.rcp_0.rdp_0.ms.sm.rdcdata_arcs);
$display("ms_sm rdzdata_arcs 0x%h", reality.rcp_0.rdp_0.ms.sm.rdzdata_arcs);
$display("ms_sm wrctxt_arcs 0x%h", reality.rcp_0.rdp_0.ms.sm.wrctxt_arcs);
$display("ms_sm wrcdata_arcs 0x%h", reality.rcp_0.rdp_0.ms.sm.wrcdata_arcs);
$display("ms_sm wrzdata_arcs 0x%h", reality.rcp_0.rdp_0.ms.sm.wrzdata_arcs);
$display("MSPAN State Transitions END");
end
end
endtask
reg [4:0] state_number;
initial begin : vcs_sucks_2
integer i;
monitor_states = $test$plusargs("mspan_mon");
last_ms_sc_state = 0;
for (i = 0; i<= 4; i = i + 1)
ms_sc_transitions[i] = 0;
last_ms_si_state = 0;
for (i = 0; i<= 4; i = i + 1)
ms_si_transitions[i] = 0;
last_ms_sm_state = 0;
for (i = 0; i<= 22; i = i + 1)
ms_sm_transitions[i] = 0;
if ($getnum$plusarg("gclock_mon=", gclock_max) == 1)
begin
$display("Simulation will end if gclock stops for %d clocks", gclock_max);
monitor_gclk = 1;
gclock_cnt = 0;
end
else
begin
monitor_gclk = 0;
end
end
//
// Monitor the 3 state machines
//
always @(posedge clock) begin
if (monitor_states) begin
if (last_ms_sc_state != reality.rcp_0.rdp_0.ms.sc.state) begin
state_number = ms_mon_encode(last_ms_sc_state);
ms_sc_transitions[state_number] = (ms_sc_transitions[state_number] |
reality.rcp_0.rdp_0.ms.sc.state);
last_ms_sc_state = reality.rcp_0.rdp_0.ms.sc.state;
end
if (last_ms_si_state != reality.rcp_0.rdp_0.ms.si.statec) begin
state_number = ms_mon_encode(last_ms_si_state);
ms_si_transitions[state_number] = (ms_si_transitions[state_number] |
reality.rcp_0.rdp_0.ms.si.statec);
last_ms_si_state = reality.rcp_0.rdp_0.ms.si.statec;
end
if (last_ms_sm_state != reality.rcp_0.rdp_0.ms.sm.state) begin
state_number = ms_mon_encode(last_ms_sm_state);
ms_sm_transitions[state_number] = (ms_sm_transitions[state_number] |
reality.rcp_0.rdp_0.ms.sm.state);
last_ms_sm_state = reality.rcp_0.rdp_0.ms.sm.state;
end
end
end
//
// detect gclock stalls. If mspan has a rdram DMA REQ don't increment the counter
//
always @(negedge clock) begin
if (monitor_gclk) begin
if (reality.rcp_0.rdp_0.start_gclk == 0)
begin
if (reality.rcp_0.rdp_0.ms.rdramreq == 0)
gclock_cnt = gclock_cnt + 1;
end
else
begin
gclock_cnt = 0;
end
if (gclock_cnt > gclock_max)
begin
$display("ERROR: gclock stopped for %d clocks. End Simulation", gclock_max);
ms_state_results;
$finish;
end
end
end
endmodule // ms_mon_state()