1 |
2 |
acastong |
//decoder_l2_tb.cpp
|
2 |
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
3 |
|
|
* Version: MPL 1.1
|
4 |
|
|
*
|
5 |
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
6 |
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
7 |
|
|
* the License. You may obtain a copy of the License at
|
8 |
|
|
* http://www.mozilla.org/MPL/
|
9 |
|
|
*
|
10 |
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
11 |
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
12 |
|
|
* for the specific language governing rights and limitations under the
|
13 |
|
|
* License.
|
14 |
|
|
*
|
15 |
|
|
* The Original Code is HyperTransport Tunnel IP Core.
|
16 |
|
|
*
|
17 |
|
|
* The Initial Developer of the Original Code is
|
18 |
|
|
* Ecole Polytechnique de Montreal.
|
19 |
|
|
* Portions created by the Initial Developer are Copyright (C) 2005
|
20 |
|
|
* the Initial Developer. All Rights Reserved.
|
21 |
|
|
*
|
22 |
|
|
* Contributor(s):
|
23 |
|
|
* Ami Castonguay <acastong@grm.polymtl.ca>
|
24 |
|
|
*
|
25 |
|
|
* Alternatively, the contents of this file may be used under the terms
|
26 |
|
|
* of the Polytechnique HyperTransport Tunnel IP Core Source Code License
|
27 |
|
|
* (the "PHTICSCL License", see the file PHTICSCL.txt), in which case the
|
28 |
|
|
* provisions of PHTICSCL License are applicable instead of those
|
29 |
|
|
* above. If you wish to allow use of your version of this file only
|
30 |
|
|
* under the terms of the PHTICSCL License and not to allow others to use
|
31 |
|
|
* your version of this file under the MPL, indicate your decision by
|
32 |
|
|
* deleting the provisions above and replace them with the notice and
|
33 |
|
|
* other provisions required by the PHTICSCL License. If you do not delete
|
34 |
|
|
* the provisions above, a recipient may use your version of this file
|
35 |
|
|
* under either the MPL or the PHTICSCL License."
|
36 |
|
|
*
|
37 |
|
|
* ***** END LICENSE BLOCK ***** */
|
38 |
|
|
|
39 |
|
|
#include "decoder_l2_tb.h"
|
40 |
|
|
#include <iostream>
|
41 |
|
|
#include <string>
|
42 |
|
|
#include <sstream>
|
43 |
|
|
|
44 |
|
|
using namespace std;
|
45 |
|
|
|
46 |
|
|
decoder_l2_tb::decoder_l2_tb(sc_module_name name) : sc_module(name){
|
47 |
|
|
SC_THREAD(stimulate_input);
|
48 |
|
|
sensitive_pos(clk);
|
49 |
|
|
SC_THREAD(nop_info_validation);
|
50 |
|
|
sensitive_pos(clk);
|
51 |
|
|
SC_THREAD(databuffer_validation);
|
52 |
|
|
sensitive_pos(clk);
|
53 |
|
|
SC_THREAD(disconnect_retry_validation);
|
54 |
|
|
sensitive_pos(clk);
|
55 |
|
|
SC_THREAD(reordering_validation);
|
56 |
|
|
sensitive_pos(clk);
|
57 |
|
|
|
58 |
|
|
//Seed random generator with any number
|
59 |
|
|
srand(4052);
|
60 |
|
|
error = false;
|
61 |
|
|
crc1 = 0xFFFFFFFF;
|
62 |
|
|
crc2 = 0xFFFFFFFF;
|
63 |
|
|
}
|
64 |
|
|
|
65 |
|
|
void decoder_l2_tb::stimulate_input(){
|
66 |
|
|
resetx = false;
|
67 |
|
|
for(int n = 0; n < 3; n++){
|
68 |
|
|
wait();
|
69 |
|
|
}
|
70 |
|
|
resetx = true;
|
71 |
|
|
|
72 |
|
|
//Non-retry tests, normal operation
|
73 |
|
|
send_nop();
|
74 |
|
|
if(error) return;
|
75 |
|
|
send_tgtdone();
|
76 |
|
|
if(error) return;
|
77 |
|
|
send_read();
|
78 |
|
|
if(error) return;
|
79 |
|
|
send_write();
|
80 |
|
|
if(error) return;
|
81 |
|
|
send_ext();
|
82 |
|
|
if(error) return;
|
83 |
|
|
send_ext_fc();
|
84 |
|
|
if(error) return;
|
85 |
|
|
send_ext_fc64();
|
86 |
|
|
if(error) return;
|
87 |
|
|
send_tgtdone_in_data();
|
88 |
|
|
if(error) return;
|
89 |
|
|
send_discon_nop();
|
90 |
|
|
|
91 |
|
|
//initiated retry mode
|
92 |
|
|
resetx = false;
|
93 |
|
|
csr_retry = true;
|
94 |
|
|
for(int n =0; n < 3; n++)
|
95 |
|
|
wait();
|
96 |
|
|
resetx = true;
|
97 |
|
|
|
98 |
|
|
//Retry mode, normal operation
|
99 |
|
|
send_nop();
|
100 |
|
|
if(error) return;
|
101 |
|
|
send_tgtdone();
|
102 |
|
|
if(error) return;
|
103 |
|
|
send_read();
|
104 |
|
|
if(error) return;
|
105 |
|
|
send_write();
|
106 |
|
|
if(error) return;
|
107 |
|
|
send_ext();
|
108 |
|
|
if(error) return;
|
109 |
|
|
send_ext_fc();
|
110 |
|
|
if(error) return;
|
111 |
|
|
send_ext_fc64();
|
112 |
|
|
if(error) return;
|
113 |
|
|
send_tgtdone_in_data();
|
114 |
|
|
if(error) return;
|
115 |
|
|
send_fc_in_data();
|
116 |
|
|
if(error) return;
|
117 |
|
|
send_fc64_in_data();
|
118 |
|
|
if(error) return;
|
119 |
|
|
send_nop_in_data();
|
120 |
|
|
if(error) return;
|
121 |
|
|
send_discon_nop();
|
122 |
|
|
if(error) return;
|
123 |
|
|
cout << endl << endl << "*** TEST SUCCESSFUL! ***" << endl << endl;
|
124 |
|
|
|
125 |
|
|
expect_cd_initiate_retry_disconnect = 99999;
|
126 |
|
|
//Retry mode, create errors & stomped packets
|
127 |
|
|
//not done yet
|
128 |
|
|
}
|
129 |
|
|
|
130 |
|
|
void decoder_l2_tb::send_dword(sc_bv<32> dword,bool lctl, bool hctl){
|
131 |
|
|
bool send;
|
132 |
|
|
do{
|
133 |
|
|
//Don't always make the dword available
|
134 |
|
|
send = rand() %10 < 8;
|
135 |
|
|
if(send){
|
136 |
|
|
lk_available_cd = true;
|
137 |
|
|
lk_dword_cd = dword;
|
138 |
|
|
lk_hctl_cd = hctl;
|
139 |
|
|
lk_lctl_cd = lctl;
|
140 |
|
|
}
|
141 |
|
|
wait();
|
142 |
|
|
lk_available_cd = false;
|
143 |
|
|
}while(!send);
|
144 |
|
|
}
|
145 |
|
|
|
146 |
|
|
void decoder_l2_tb::send_nop(){
|
147 |
|
|
//Nop is mostly zeroes
|
148 |
|
|
sc_bv<32> dword = 0;
|
149 |
|
|
|
150 |
|
|
//Create a random nop entry
|
151 |
|
|
NopEntry entry;
|
152 |
|
|
entry.cd_nopinfo_fc = sc_uint<12>(rand());
|
153 |
|
|
entry.cd_nop_ack_value_fc = rand();
|
154 |
|
|
|
155 |
|
|
//Fill the nop bits with the values from entry
|
156 |
|
|
dword.range(19,8) = entry.cd_nopinfo_fc;
|
157 |
|
|
dword.range(31,24) = entry.cd_nop_ack_value_fc;
|
158 |
|
|
|
159 |
|
|
//Send then generated nop
|
160 |
|
|
nop_queue.push_back(entry);
|
161 |
|
|
send_dword(dword,true,true);
|
162 |
|
|
if(csr_retry.read()){
|
163 |
|
|
calculate_crc1(dword,true,true);
|
164 |
|
|
send_dword(~crc1,true,false);
|
165 |
|
|
crc1 = 0xFFFFFFFF;
|
166 |
|
|
}
|
167 |
|
|
}
|
168 |
|
|
|
169 |
|
|
void decoder_l2_tb::send_tgtdone(){
|
170 |
|
|
//Generate a target done packet
|
171 |
|
|
sc_bv<32> dword;
|
172 |
|
|
getRandomVector(dword);
|
173 |
|
|
sc_bv<6> command = "110011";
|
174 |
|
|
dword.range(5,0) = command;
|
175 |
|
|
|
176 |
|
|
//Send the packet
|
177 |
|
|
send_dword(dword,true,true);
|
178 |
|
|
if(csr_retry.read()){
|
179 |
|
|
calculate_crc1(dword,true,true);
|
180 |
|
|
send_dword(~crc1,true,false);
|
181 |
|
|
crc1 = 0xFFFFFFFF;
|
182 |
|
|
}
|
183 |
|
|
//Add to expected entry
|
184 |
|
|
addReorderingEntry(dword,false);
|
185 |
|
|
}
|
186 |
|
|
|
187 |
|
|
void decoder_l2_tb::send_read(){
|
188 |
|
|
//Generate first dword of read packet
|
189 |
|
|
sc_bv<32> dword;
|
190 |
|
|
sc_bv<32> dword2;
|
191 |
|
|
getRandomVector(dword);
|
192 |
|
|
sc_bv<2> command = "01";
|
193 |
|
|
dword.range(5,4) = command;
|
194 |
|
|
|
195 |
|
|
//Send it
|
196 |
|
|
send_dword(dword,true,true);
|
197 |
|
|
if(csr_retry.read()){
|
198 |
|
|
calculate_crc1(dword,true,true);
|
199 |
|
|
}
|
200 |
|
|
|
201 |
|
|
//Repeat for second dword
|
202 |
|
|
getRandomVector(dword2);
|
203 |
|
|
send_dword(dword2,true,true);
|
204 |
|
|
if(csr_retry.read()){
|
205 |
|
|
calculate_crc1(dword2,true,true);
|
206 |
|
|
send_dword(~crc1,true,false);
|
207 |
|
|
crc1 = 0xFFFFFFFF;
|
208 |
|
|
}
|
209 |
|
|
|
210 |
|
|
//Add to expected entry
|
211 |
|
|
sc_bv<64> qword;
|
212 |
|
|
qword.range(31,0) = dword;
|
213 |
|
|
qword.range(63,32) = dword2;
|
214 |
|
|
addReorderingEntry(qword,false);
|
215 |
|
|
|
216 |
|
|
}
|
217 |
|
|
|
218 |
|
|
void decoder_l2_tb::send_write(){
|
219 |
|
|
//Random amount of data following it
|
220 |
|
|
int data_length = rand() % 16;
|
221 |
|
|
|
222 |
|
|
///Create and store the data
|
223 |
|
|
DataBufferEntry entry = generate_data_packet(data_length,VC_POSTED);
|
224 |
|
|
databuffer_queue.push_back(entry);
|
225 |
|
|
|
226 |
|
|
//Send the write command packet (randomly generated)
|
227 |
|
|
send_write_header(data_length);
|
228 |
|
|
//Then send the data that follows it
|
229 |
|
|
send_data_packet(entry,0,data_length);
|
230 |
|
|
|
231 |
|
|
//Then send CRC if in retry mode
|
232 |
|
|
if(csr_retry.read()){
|
233 |
|
|
send_dword(~crc2,false,true);
|
234 |
|
|
crc2 = 0xFFFFFFFF;
|
235 |
|
|
}
|
236 |
|
|
}
|
237 |
|
|
|
238 |
|
|
|
239 |
|
|
void decoder_l2_tb::send_write_header(int datalength_m1){
|
240 |
|
|
sc_bv<32> dword;
|
241 |
|
|
sc_bv<64> qword = 0;
|
242 |
|
|
|
243 |
|
|
|
244 |
|
|
getRandomVector(dword);
|
245 |
|
|
sc_bv<3> command = "101";
|
246 |
|
|
dword.range(5,3) = command;
|
247 |
|
|
dword.range(25,22) = sc_uint<4>(datalength_m1);
|
248 |
|
|
qword.range(31,0) = dword;
|
249 |
|
|
send_dword(dword,true,true);
|
250 |
|
|
if(csr_retry.read()){
|
251 |
|
|
calculate_crc2(dword,true,true);
|
252 |
|
|
}
|
253 |
|
|
getRandomVector(dword);
|
254 |
|
|
qword.range(63,32) = dword;
|
255 |
|
|
addReorderingEntry(qword,false);
|
256 |
|
|
|
257 |
|
|
send_dword(dword,true,true);
|
258 |
|
|
if(csr_retry.read()){
|
259 |
|
|
calculate_crc2(dword,true,true);
|
260 |
|
|
}
|
261 |
|
|
}
|
262 |
|
|
|
263 |
|
|
decoder_l2_tb::DataBufferEntry decoder_l2_tb::generate_data_packet(int datalength_m1,
|
264 |
|
|
VirtualChannel vc){
|
265 |
|
|
DataBufferEntry entry;
|
266 |
|
|
entry.size = datalength_m1;
|
267 |
|
|
entry.vc = vc;
|
268 |
|
|
entry.address_requested = false;
|
269 |
|
|
entry.badcrc = false;
|
270 |
|
|
|
271 |
|
|
for(int n = 0; n <= datalength_m1; n++){
|
272 |
|
|
entry.data[n] = rand() & 0xFFF |
|
273 |
|
|
rand() & 0xFFF << 12 |
|
274 |
|
|
rand() & 0xFF << 24;
|
275 |
|
|
}
|
276 |
|
|
|
277 |
|
|
return entry;
|
278 |
|
|
}
|
279 |
|
|
|
280 |
|
|
void decoder_l2_tb::send_data_packet(DataBufferEntry &entry,
|
281 |
|
|
int offset,
|
282 |
|
|
int last){
|
283 |
|
|
for(int n = offset; n <= last; n++){
|
284 |
|
|
send_dword(sc_uint<32>(entry.data[n]),false,false);
|
285 |
|
|
if(csr_retry.read()){
|
286 |
|
|
calculate_crc2(sc_uint<32>(entry.data[n]),false,false);
|
287 |
|
|
}
|
288 |
|
|
}
|
289 |
|
|
}
|
290 |
|
|
|
291 |
|
|
void decoder_l2_tb::send_ext(){
|
292 |
|
|
//Send the 64 bit extension
|
293 |
|
|
sc_bv<32> dword;
|
294 |
|
|
getRandomVector(dword);
|
295 |
|
|
sc_bv<6> command = "111110";
|
296 |
|
|
dword.range(5,0) = command;
|
297 |
|
|
send_dword(dword,true,true);
|
298 |
|
|
if(csr_retry.read()){
|
299 |
|
|
calculate_crc1(dword,true,true);
|
300 |
|
|
}
|
301 |
|
|
|
302 |
|
|
//Send a standard read packet
|
303 |
|
|
send_read();
|
304 |
|
|
|
305 |
|
|
/** The send_read() function pushed an expected request
|
306 |
|
|
in the queue. Modify it so that a 64b error is
|
307 |
|
|
expected */
|
308 |
|
|
reordering_queue.back().pkt.error64BitExtension = true;
|
309 |
|
|
|
310 |
|
|
}
|
311 |
|
|
|
312 |
|
|
void decoder_l2_tb::send_ext_fc(){
|
313 |
|
|
sc_bv<32> dword;
|
314 |
|
|
getRandomVector(dword);
|
315 |
|
|
sc_bv<7> command = "0110111";
|
316 |
|
|
dword.range(6,0) = command;
|
317 |
|
|
send_dword(dword,true,true);
|
318 |
|
|
if(csr_retry.read()){
|
319 |
|
|
calculate_crc1(dword,true,true);
|
320 |
|
|
send_dword(~crc1,true,false);
|
321 |
|
|
crc1 = 0xFFFFFFFF;
|
322 |
|
|
}
|
323 |
|
|
}
|
324 |
|
|
|
325 |
|
|
void decoder_l2_tb::send_ext_fc64(){
|
326 |
|
|
sc_bv<32> dword;
|
327 |
|
|
getRandomVector(dword);
|
328 |
|
|
sc_bv<7> command = "1110111";
|
329 |
|
|
dword.range(6,0) = command;
|
330 |
|
|
send_dword(dword,true,true);
|
331 |
|
|
if(csr_retry.read()){
|
332 |
|
|
calculate_crc1(dword,true,true);
|
333 |
|
|
}
|
334 |
|
|
getRandomVector(dword);
|
335 |
|
|
send_dword(dword,true,true);
|
336 |
|
|
if(csr_retry.read()){
|
337 |
|
|
calculate_crc1(dword,true,true);
|
338 |
|
|
send_dword(~crc1,true,false);
|
339 |
|
|
crc1 = 0xFFFFFFFF;
|
340 |
|
|
}
|
341 |
|
|
}
|
342 |
|
|
|
343 |
|
|
void decoder_l2_tb::send_tgtdone_in_data(){
|
344 |
|
|
int data_length = rand() % 12 + 4;
|
345 |
|
|
DataBufferEntry entry = generate_data_packet(data_length,VC_POSTED);
|
346 |
|
|
databuffer_queue.push_back(entry);
|
347 |
|
|
send_write_header(data_length);
|
348 |
|
|
|
349 |
|
|
send_data_packet(entry,0,1);
|
350 |
|
|
send_tgtdone();
|
351 |
|
|
|
352 |
|
|
//Swap packets in retry mode
|
353 |
|
|
if(csr_retry.read()){
|
354 |
|
|
ReorderingEntry tmp = reordering_queue.back();
|
355 |
|
|
reordering_queue.back() = *(reordering_queue.end()-2);
|
356 |
|
|
*(reordering_queue.end()-2) = tmp;
|
357 |
|
|
}
|
358 |
|
|
|
359 |
|
|
send_data_packet(entry,2,data_length);
|
360 |
|
|
|
361 |
|
|
if(csr_retry.read()){
|
362 |
|
|
send_dword(~crc2,false,true);
|
363 |
|
|
crc2 = 0xFFFFFFFF;
|
364 |
|
|
}
|
365 |
|
|
}
|
366 |
|
|
|
367 |
|
|
void decoder_l2_tb::send_fc_in_data(){
|
368 |
|
|
int data_length = rand() % 12 + 4;
|
369 |
|
|
DataBufferEntry entry = generate_data_packet(data_length,VC_POSTED);
|
370 |
|
|
databuffer_queue.push_back(entry);
|
371 |
|
|
send_write_header(data_length);
|
372 |
|
|
|
373 |
|
|
send_data_packet(entry,0,1);
|
374 |
|
|
send_ext_fc();
|
375 |
|
|
send_data_packet(entry,2,data_length);
|
376 |
|
|
|
377 |
|
|
if(csr_retry.read()){
|
378 |
|
|
send_dword(~crc2,false,true);
|
379 |
|
|
crc2 = 0xFFFFFFFF;
|
380 |
|
|
}
|
381 |
|
|
}
|
382 |
|
|
|
383 |
|
|
void decoder_l2_tb::send_fc64_in_data(){
|
384 |
|
|
int data_length = rand() % 12 + 4;
|
385 |
|
|
DataBufferEntry entry = generate_data_packet(data_length,VC_POSTED);
|
386 |
|
|
databuffer_queue.push_back(entry);
|
387 |
|
|
send_write_header(data_length);
|
388 |
|
|
|
389 |
|
|
send_data_packet(entry,0,1);
|
390 |
|
|
send_ext_fc64();
|
391 |
|
|
send_data_packet(entry,2,data_length);
|
392 |
|
|
|
393 |
|
|
if(csr_retry.read()){
|
394 |
|
|
send_dword(~crc2,false,true);
|
395 |
|
|
crc2 = 0xFFFFFFFF;
|
396 |
|
|
}
|
397 |
|
|
}
|
398 |
|
|
|
399 |
|
|
void decoder_l2_tb::send_nop_in_data(){
|
400 |
|
|
int data_length = rand() % 12 + 4;
|
401 |
|
|
DataBufferEntry entry = generate_data_packet(data_length,VC_POSTED);
|
402 |
|
|
databuffer_queue.push_back(entry);
|
403 |
|
|
send_write_header(data_length);
|
404 |
|
|
|
405 |
|
|
send_data_packet(entry,0,1);
|
406 |
|
|
send_nop();
|
407 |
|
|
send_data_packet(entry,2,data_length);
|
408 |
|
|
|
409 |
|
|
if(csr_retry.read()){
|
410 |
|
|
send_dword(~crc2,false,true);
|
411 |
|
|
crc2 = 0xFFFFFFFF;
|
412 |
|
|
}
|
413 |
|
|
}
|
414 |
|
|
|
415 |
|
|
void decoder_l2_tb::send_discon_nop(){
|
416 |
|
|
sc_bv<32> dword = 0;
|
417 |
|
|
dword[6] = true;
|
418 |
|
|
|
419 |
|
|
NopEntry entry;
|
420 |
|
|
entry.cd_nopinfo_fc = sc_uint<12>(rand());
|
421 |
|
|
entry.cd_nop_ack_value_fc = rand();
|
422 |
|
|
dword.range(19,8) = entry.cd_nopinfo_fc;
|
423 |
|
|
dword.range(31,24) = entry.cd_nop_ack_value_fc;
|
424 |
|
|
|
425 |
|
|
/** After a disconnect nop, the decoder is expected to initiate\
|
426 |
|
|
a disconnect sequence
|
427 |
|
|
*/
|
428 |
|
|
if(csr_retry.read())
|
429 |
|
|
expect_cd_initiate_retry_disconnect = 4;
|
430 |
|
|
else
|
431 |
|
|
expect_cd_initiate_nonretry_disconnect_lk = 4;
|
432 |
|
|
send_dword(dword,true,true);
|
433 |
|
|
if(csr_retry.read()){
|
434 |
|
|
calculate_crc1(dword,true,true);
|
435 |
|
|
send_dword(~crc1,true,false);
|
436 |
|
|
crc1 = 0xFFFFFFFF;
|
437 |
|
|
}
|
438 |
|
|
}
|
439 |
|
|
|
440 |
|
|
void decoder_l2_tb::nop_info_validation(){
|
441 |
|
|
while(!error){
|
442 |
|
|
//Start by checking the standard nop information
|
443 |
|
|
|
444 |
|
|
//Check that entries in the queue are not simply being accumulated without
|
445 |
|
|
//ever being used
|
446 |
|
|
if(nop_queue.size() > 4){
|
447 |
|
|
displayError("ERROR: Nop data not sent"); continue;
|
448 |
|
|
}
|
449 |
|
|
|
450 |
|
|
//When the command decoder says that nop is received, check the validity of the information
|
451 |
|
|
if(cd_nop_received_fc.read()){
|
452 |
|
|
if(nop_queue.empty()){
|
453 |
|
|
displayError("ERROR: Nop data was not sent"); continue;
|
454 |
|
|
}
|
455 |
|
|
if(cd_nopinfo_fc.read() != nop_queue.front().cd_nopinfo_fc ||
|
456 |
|
|
cd_nop_ack_value_fc.read() != nop_queue.front().cd_nop_ack_value_fc)
|
457 |
|
|
{
|
458 |
|
|
displayError("ERROR: Invalid nop data content"); continue;
|
459 |
|
|
}
|
460 |
|
|
nop_queue.pop_front();
|
461 |
|
|
}
|
462 |
|
|
|
463 |
|
|
//Check the next packet to ack value
|
464 |
|
|
if(cd_rx_next_pkt_to_ack_fc.size() > 4){
|
465 |
|
|
displayError("ERROR: next_pkt_to_ack value not udpated correctly"); continue;
|
466 |
|
|
}
|
467 |
|
|
if(!ack_value.empty()){
|
468 |
|
|
if(ack_value.front() == cd_nop_ack_value_fc.read()){
|
469 |
|
|
ack_value.pop_front();
|
470 |
|
|
}
|
471 |
|
|
else if(ack_value.front() != (cd_nop_ack_value_fc.read() + 1)){
|
472 |
|
|
displayError("ERROR: Invalid next_pkt_to_ack value"); continue;
|
473 |
|
|
}
|
474 |
|
|
}
|
475 |
|
|
|
476 |
|
|
wait();
|
477 |
|
|
}
|
478 |
|
|
}
|
479 |
|
|
|
480 |
|
|
void decoder_l2_tb::databuffer_validation(){
|
481 |
|
|
//Some default values
|
482 |
|
|
last_databuffer_address = 0;
|
483 |
|
|
db_address_cd = rand();
|
484 |
|
|
int pos_in_entry = 0;
|
485 |
|
|
delayed_start_writing_data = false;
|
486 |
|
|
delayed_start_writing_data2 = false;
|
487 |
|
|
delayed_start_writing_data3 = false;
|
488 |
|
|
writing_data = false;
|
489 |
|
|
|
490 |
|
|
while(!error){
|
491 |
|
|
//Store cd_getaddr_db with different degrees of delay. It will be used to verify
|
492 |
|
|
//the data pending signal later on
|
493 |
|
|
delayed_start_writing_data = cd_getaddr_db.read();
|
494 |
|
|
delayed_start_writing_data2 = delayed_start_writing_data;
|
495 |
|
|
delayed_start_writing_data3 = delayed_start_writing_data2;
|
496 |
|
|
|
497 |
|
|
//Check that entries in the queue are not simply being accumulated without
|
498 |
|
|
//ever being used
|
499 |
|
|
if(databuffer_queue.size() > 2){
|
500 |
|
|
displayError("ERROR: Data not sent to databuffer"); continue;
|
501 |
|
|
}
|
502 |
|
|
|
503 |
|
|
//When the command decoder starts writing a data packet to the databuffer
|
504 |
|
|
if(cd_getaddr_db.read()){
|
505 |
|
|
/** Check that this is a correct behavior
|
506 |
|
|
*/
|
507 |
|
|
if(writing_data.read()){
|
508 |
|
|
displayError("ERROR: Last data entry not finished"); continue;
|
509 |
|
|
}
|
510 |
|
|
if(databuffer_queue.empty()){
|
511 |
|
|
displayError("ERROR: Data entry requested"); continue;
|
512 |
|
|
}
|
513 |
|
|
if(databuffer_queue.front().address_requested){
|
514 |
|
|
displayError("ERROR: Data address already requested"); continue;
|
515 |
|
|
}
|
516 |
|
|
if(databuffer_queue.front().vc != cd_vctype_db.read()){
|
517 |
|
|
displayError("ERROR: Wrong VC requested in databuffer"); continue;
|
518 |
|
|
}
|
519 |
|
|
if(databuffer_queue.front().size != cd_datalen_db.read()){
|
520 |
|
|
displayError("ERROR: Wrong data length requested"); continue;
|
521 |
|
|
}
|
522 |
|
|
//modify the entry in the queue so that we know that an address has been requested
|
523 |
|
|
databuffer_queue.front().address_requested = true;
|
524 |
|
|
last_databuffer_address = db_address_cd.read();
|
525 |
|
|
db_address_cd = rand();
|
526 |
|
|
writing_data = true;
|
527 |
|
|
pos_in_entry = 0;
|
528 |
|
|
}
|
529 |
|
|
|
530 |
|
|
//When command decoder writing to databuffer, check that correct data is written
|
531 |
|
|
if(cd_write_db.read()){
|
532 |
|
|
if(!writing_data.read()){
|
533 |
|
|
displayError("ERROR: Unexpected data write"); continue;
|
534 |
|
|
}
|
535 |
|
|
if(sc_uint<32>(databuffer_queue.front().data[pos_in_entry++]) !=
|
536 |
|
|
cd_data_db.read())
|
537 |
|
|
{
|
538 |
|
|
displayError("ERROR: Wrong data received"); continue;
|
539 |
|
|
}
|
540 |
|
|
if(pos_in_entry > databuffer_queue.front().size){
|
541 |
|
|
databuffer_queue.pop_front();
|
542 |
|
|
writing_data = false;
|
543 |
|
|
}
|
544 |
|
|
}
|
545 |
|
|
|
546 |
|
|
wait();
|
547 |
|
|
}
|
548 |
|
|
}
|
549 |
|
|
|
550 |
|
|
void decoder_l2_tb::disconnect_retry_validation(){
|
551 |
|
|
expect_cd_initiate_retry_disconnect = 0;
|
552 |
|
|
expect_cd_received_stomped_csr = 0;
|
553 |
|
|
expect_cd_initiate_nonretry_disconnect_lk = 0;
|
554 |
|
|
|
555 |
|
|
while(!error){
|
556 |
|
|
//Check if cd_initiate_retry_disconnect is expected to be asserted
|
557 |
|
|
if(expect_cd_initiate_retry_disconnect > 0){
|
558 |
|
|
//Reduce the count of cycles left before it must be asserted
|
559 |
|
|
expect_cd_initiate_retry_disconnect--;
|
560 |
|
|
|
561 |
|
|
//Remove the expected flag if it becomes asserted
|
562 |
|
|
if(cd_initiate_retry_disconnect.read()){
|
563 |
|
|
expect_cd_initiate_retry_disconnect = 0;
|
564 |
|
|
}
|
565 |
|
|
//If the count goes down to 0, give an error (timeout)
|
566 |
|
|
else if(!expect_cd_initiate_retry_disconnect){
|
567 |
|
|
displayError("ERROR: cd_initiate_retry_disconnect not asserted"); continue;
|
568 |
|
|
}
|
569 |
|
|
}
|
570 |
|
|
//If it is unexpectedly asserted, display error
|
571 |
|
|
else if(cd_initiate_retry_disconnect.read()){
|
572 |
|
|
displayError("ERROR: cd_initiate_retry_disconnect asserted"); continue;
|
573 |
|
|
}
|
574 |
|
|
|
575 |
|
|
//Check if cd_received_stomped_csr is expected to be asserted
|
576 |
|
|
if(expect_cd_received_stomped_csr > 0){
|
577 |
|
|
//Reduce the count of cycles left before it must be asserted
|
578 |
|
|
expect_cd_received_stomped_csr--;
|
579 |
|
|
|
580 |
|
|
//Remove the expected flag if it becomes asserted
|
581 |
|
|
if(cd_received_stomped_csr.read()){
|
582 |
|
|
expect_cd_received_stomped_csr = 0;
|
583 |
|
|
}
|
584 |
|
|
//If the count goes down to 0, give an error (timeout)
|
585 |
|
|
else if(!expect_cd_received_stomped_csr){
|
586 |
|
|
displayError("ERROR: cd_received_stomped_csr not asserted"); continue;
|
587 |
|
|
}
|
588 |
|
|
}
|
589 |
|
|
//If it is unexpectedly asserted, display error
|
590 |
|
|
else if(cd_received_stomped_csr.read()){
|
591 |
|
|
displayError("ERROR: cd_received_stomped_csr asserted"); continue;
|
592 |
|
|
}
|
593 |
|
|
|
594 |
|
|
//Check if cd_initiate_nonretry_disconnect_lk is expected to be asserted
|
595 |
|
|
if(expect_cd_initiate_nonretry_disconnect_lk > 0){
|
596 |
|
|
//Reduce the count of cycles left before it must be asserted
|
597 |
|
|
expect_cd_initiate_nonretry_disconnect_lk--;
|
598 |
|
|
|
599 |
|
|
//Remove the expected flag if it becomes asserted
|
600 |
|
|
if(cd_initiate_nonretry_disconnect_lk.read()){
|
601 |
|
|
expect_cd_initiate_nonretry_disconnect_lk = 0;
|
602 |
|
|
}
|
603 |
|
|
//If the count goes down to 0, give an error (timeout)
|
604 |
|
|
else if(!expect_cd_initiate_nonretry_disconnect_lk){
|
605 |
|
|
displayError("ERROR: cd_initiate_nonretry_disconnect_lk not asserted"); continue;
|
606 |
|
|
}
|
607 |
|
|
}
|
608 |
|
|
//If it is unexpectedly asserted, display error
|
609 |
|
|
else if(cd_initiate_nonretry_disconnect_lk.read()){
|
610 |
|
|
displayError("ERROR: cd_initiate_nonretry_disconnect_lk asserted"); continue;
|
611 |
|
|
}
|
612 |
|
|
|
613 |
|
|
wait();
|
614 |
|
|
}
|
615 |
|
|
|
616 |
|
|
}
|
617 |
|
|
|
618 |
|
|
void decoder_l2_tb::reordering_validation(){
|
619 |
|
|
//There is no data pending at the beggining
|
620 |
|
|
sc_uint<BUFFERS_ADDRESS_WIDTH> pending_data_address;
|
621 |
|
|
bool data_pending = false;
|
622 |
|
|
|
623 |
|
|
while(!error){
|
624 |
|
|
//Check that entries in the queue are not simply being accumulated without
|
625 |
|
|
//ever being used
|
626 |
|
|
if(reordering_queue.size() > 4){
|
627 |
|
|
displayError("ERROR: Packets not sent to reordering"); continue;
|
628 |
|
|
}
|
629 |
|
|
|
630 |
|
|
//If packet is sent to reordering
|
631 |
|
|
if(cd_available_ro.read()){
|
632 |
|
|
//Check that there is a packet in the queue to avoid reading from an empty
|
633 |
|
|
//queue if the decoder is not working correctly
|
634 |
|
|
if(reordering_queue.empty()){
|
635 |
|
|
ostringstream o;
|
636 |
|
|
o << "ERROR: Unexpected command packet received: " <<
|
637 |
|
|
cd_packet_ro.read().packet.to_string(SC_HEX);
|
638 |
|
|
displayError(o.str().c_str()); continue;
|
639 |
|
|
}
|
640 |
|
|
|
641 |
|
|
//Check that the packet matches the entry in the front of the queue
|
642 |
|
|
if(reordering_queue.front().pkt.packet != cd_packet_ro.read().packet ||
|
643 |
|
|
reordering_queue.front().pkt.error64BitExtension != cd_packet_ro.read().error64BitExtension)
|
644 |
|
|
{
|
645 |
|
|
displayError("ERROR: Invalid command packet received"); continue;
|
646 |
|
|
}
|
647 |
|
|
|
648 |
|
|
//Check that the address of the data is correct (if apliccable)
|
649 |
|
|
if(reordering_queue.front().has_data &&
|
650 |
|
|
cd_packet_ro.read().data_address != last_databuffer_address)
|
651 |
|
|
{
|
652 |
|
|
displayError("ERROR: Invalid data address in packet sent to command buffers"); continue;
|
653 |
|
|
}
|
654 |
|
|
|
655 |
|
|
//Store what should be the pending data address for this packet
|
656 |
|
|
pending_data_address = last_databuffer_address;
|
657 |
|
|
//Remove it from the queue
|
658 |
|
|
reordering_queue.pop_front();
|
659 |
|
|
}
|
660 |
|
|
|
661 |
|
|
if(cd_data_pending_ro.read() != data_pending)
|
662 |
|
|
{
|
663 |
|
|
displayError("ERROR: cd_data_pending_ro has wrong value"); continue;
|
664 |
|
|
}
|
665 |
|
|
|
666 |
|
|
/**
|
667 |
|
|
Calculate if the decoder should advertise data pending.
|
668 |
|
|
Rules :
|
669 |
|
|
-No data pending when retry mode is active (csr_retry)
|
670 |
|
|
-It starts after a delay of getting address from
|
671 |
|
|
databuffer (delayed_start_writing_data2)
|
672 |
|
|
-It stays pending (data_pending) until a next command
|
673 |
|
|
packet is received (CTL available from link)
|
674 |
|
|
*/
|
675 |
|
|
data_pending = (data_pending &&
|
676 |
|
|
!(lk_lctl_cd.read() && lk_available_cd.read() && !writing_data.read())
|
677 |
|
|
|| (delayed_start_writing_data2.read())) && !csr_retry.read();
|
678 |
|
|
|
679 |
|
|
if(cd_data_pending_ro.read() &&
|
680 |
|
|
pending_data_address != cd_data_pending_addr_ro.read())
|
681 |
|
|
{
|
682 |
|
|
displayError("ERROR: invalid pending data address value"); continue;
|
683 |
|
|
}
|
684 |
|
|
wait();
|
685 |
|
|
}
|
686 |
|
|
}
|
687 |
|
|
|
688 |
|
|
void decoder_l2_tb::displayError(const char * error_message){
|
689 |
|
|
cout << error_message << endl;
|
690 |
|
|
error = true;
|
691 |
|
|
resetx = false;
|
692 |
|
|
}
|
693 |
|
|
|
694 |
|
|
void decoder_l2_tb::getRandomVector(sc_bv<32> &vector){
|
695 |
|
|
vector.range(14,0) = sc_uint<15>(rand());
|
696 |
|
|
vector.range(29,15) = sc_uint<15>(rand());
|
697 |
|
|
vector.range(31,30) = sc_uint<2>(rand());
|
698 |
|
|
}
|
699 |
|
|
|
700 |
|
|
void decoder_l2_tb::getRandomVector(sc_bv<64> &vector){
|
701 |
|
|
for(int n = 0; n < 4; n++)
|
702 |
|
|
vector.range(15*(n+1) - 1,15*n) = sc_uint<15>(rand());
|
703 |
|
|
vector.range(63,60) = sc_uint<4>(rand());
|
704 |
|
|
}
|
705 |
|
|
|
706 |
|
|
void decoder_l2_tb::addReorderingEntry(sc_bv<32> &vector,bool hasData){
|
707 |
|
|
sc_bv<64> qword = 0;
|
708 |
|
|
qword.range(31,0) = vector;
|
709 |
|
|
addReorderingEntry(qword,hasData);
|
710 |
|
|
}
|
711 |
|
|
|
712 |
|
|
void decoder_l2_tb::addReorderingEntry(sc_bv<64> &vector,bool hasData){
|
713 |
|
|
ReorderingEntry entry;
|
714 |
|
|
entry.pkt.error64BitExtension = false;
|
715 |
|
|
entry.pkt.packet = vector;
|
716 |
|
|
entry.has_data = hasData;
|
717 |
|
|
reordering_queue.push_back(entry);
|
718 |
|
|
}
|
719 |
|
|
|
720 |
|
|
void decoder_l2_tb::calculate_crc1(sc_bv<32> dword,bool lctl, bool hctl){
|
721 |
|
|
sc_bv<34> data;
|
722 |
|
|
data[33] = hctl;
|
723 |
|
|
data.range(32,17) = dword.range(31,16);
|
724 |
|
|
data[16] = lctl;
|
725 |
|
|
data.range(15,0) = dword.range(15,0);
|
726 |
|
|
calculate_crc(crc1,data);
|
727 |
|
|
}
|
728 |
|
|
|
729 |
|
|
void decoder_l2_tb::calculate_crc2(sc_bv<32> dword,bool lctl, bool hctl){
|
730 |
|
|
sc_bv<34> data;
|
731 |
|
|
data[33] = hctl;
|
732 |
|
|
data.range(32,17) = dword.range(31,16);
|
733 |
|
|
data[16] = lctl;
|
734 |
|
|
data.range(15,0) = dword.range(15,0);
|
735 |
|
|
calculate_crc(crc2,data);
|
736 |
|
|
}
|
737 |
|
|
|
738 |
|
|
void decoder_l2_tb::calculate_crc(unsigned &crc,sc_bv<34> &data){
|
739 |
|
|
static unsigned poly = 0x04C11DB7;
|
740 |
|
|
|
741 |
|
|
for(int i = 0; i < 34; i++){
|
742 |
|
|
/* xor highest bit w/ message: */
|
743 |
|
|
unsigned tmp = ((crc >> 31) & 1) ^ ( ((sc_bit)data[i]) ? 1 : 0);
|
744 |
|
|
|
745 |
|
|
/* substract poly if greater: */
|
746 |
|
|
crc = (tmp) ? (crc << 1) ^ poly : ((crc << 1) | tmp);
|
747 |
|
|
}
|
748 |
|
|
}
|