1 |
2 |
acastong |
//link_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 "link_l2_tb.h"
|
40 |
|
|
#include <cstdlib>
|
41 |
|
|
#include <iostream>
|
42 |
|
|
|
43 |
|
|
#include "../link_frame_rx_l3_tb/link_rx_transmitter.h"
|
44 |
|
|
#include "../link_frame_tx_l3_tb/link_tx_validator.h"
|
45 |
|
|
#include "../../core/require.h"
|
46 |
|
|
|
47 |
|
|
/**
|
48 |
|
|
Note : this is far from being a full testbench. The goal of this
|
49 |
|
|
is to verify the basic fonctionnality. Extensive testing of all
|
50 |
|
|
possibilities is not yet a priority...
|
51 |
|
|
|
52 |
|
|
The goals of this testbench are to check :
|
53 |
|
|
|
54 |
|
|
-basic sequence without error (verify the correctness of sent CRC's)
|
55 |
|
|
-basic with error on rx side (verify the correctness of sent CRC's)
|
56 |
|
|
-ldtstop sequence
|
57 |
|
|
-sync error
|
58 |
|
|
|
59 |
|
|
-basic with error in CRC and retry mode enabled (should be ignored)
|
60 |
|
|
-basic with error in CTL transition and retry mode
|
61 |
|
|
*/
|
62 |
|
|
|
63 |
|
|
|
64 |
|
|
link_l2_tb::link_l2_tb(sc_module_name name) : sc_module(name){
|
65 |
|
|
SC_THREAD(manage_rx_transmission);
|
66 |
|
|
sensitive_pos(clk);
|
67 |
|
|
|
68 |
|
|
SC_THREAD(validate_rx_reception);
|
69 |
|
|
sensitive_pos(clk);
|
70 |
|
|
|
71 |
|
|
SC_THREAD(stimulus);
|
72 |
|
|
sensitive_pos(clk);
|
73 |
|
|
|
74 |
|
|
transmitter = new link_rx_transmitter("link_rx_transmitter");
|
75 |
|
|
transmitter->clk(clk);
|
76 |
|
|
transmitter->phy_ctl_lk(phy_ctl_lk);
|
77 |
|
|
for(int n = 0; n < CAD_IN_WIDTH; n++){
|
78 |
|
|
transmitter->phy_cad_lk[n](phy_cad_lk[n]);
|
79 |
|
|
}
|
80 |
|
|
transmitter->phy_available_lk(phy_available_lk);
|
81 |
|
|
|
82 |
|
|
#ifndef INTERNAL_SHIFTER_ALIGNMENT
|
83 |
|
|
transmitter->lk_deser_stall_phy(lk_deser_stall_phy);
|
84 |
|
|
transmitter->lk_deser_stall_cycles_phy(lk_deser_stall_cycles_phy);
|
85 |
|
|
#endif
|
86 |
|
|
|
87 |
|
|
validator = new link_tx_validator("link_tx_validator");
|
88 |
|
|
validator->clk(clk);
|
89 |
|
|
|
90 |
|
|
validator->lk_ctl_phy(lk_ctl_phy);
|
91 |
|
|
for(int n = 0; n < CAD_IN_WIDTH; n++){
|
92 |
|
|
validator->lk_cad_phy[n](lk_cad_phy[n]);
|
93 |
|
|
}
|
94 |
|
|
validator->tx_consume_data(lk_consume_fc);
|
95 |
|
|
|
96 |
|
|
validator->phy_consume_lk(phy_consume_lk);
|
97 |
|
|
validator->cad_to_frame(fc_dword_lk);
|
98 |
|
|
validator->lctl_to_frame(fc_lctl_lk);
|
99 |
|
|
validator->hctl_to_frame(fc_hctl_lk);
|
100 |
|
|
|
101 |
|
|
//A random seed value
|
102 |
|
|
srand(23524);
|
103 |
|
|
reset_rx_connection = false;
|
104 |
|
|
check_rx_dword_reception = true;
|
105 |
|
|
rx_number = 0;
|
106 |
|
|
expecting_rx_crc_error = 0;
|
107 |
|
|
|
108 |
|
|
rx_crc = 0xFFFFFFFF;
|
109 |
|
|
tx_crc = 0xFFFFFFFF;
|
110 |
|
|
}
|
111 |
|
|
|
112 |
|
|
link_l2_tb::~link_l2_tb(){
|
113 |
|
|
delete transmitter;
|
114 |
|
|
delete validator;
|
115 |
|
|
}
|
116 |
|
|
|
117 |
|
|
void link_l2_tb::stimulus(){
|
118 |
|
|
init();
|
119 |
|
|
|
120 |
|
|
link_tx_validator::LinkTransmission_TX tx_crc_transmission;
|
121 |
|
|
tx_crc_transmission.lctl = true;
|
122 |
|
|
tx_crc_transmission.hctl = true;
|
123 |
|
|
|
124 |
|
|
LinkTransmission rx_crc_transmission;
|
125 |
|
|
rx_crc_transmission.error = false;
|
126 |
|
|
rx_crc_transmission.lctl = true;
|
127 |
|
|
rx_crc_transmission.hctl = true;
|
128 |
|
|
|
129 |
|
|
//////////////////////////////////////
|
130 |
|
|
// First test, valid and nonvalid CRC
|
131 |
|
|
//////////////////////////////////////
|
132 |
|
|
|
133 |
|
|
init_fill_queues(272,false);
|
134 |
|
|
tx_crc_transmission.dword = ~last_tx_crc;
|
135 |
|
|
validator->expected_transmission.push(tx_crc_transmission);
|
136 |
|
|
//cout << "Expected TX CRC : " << tx_crc_transmission.dword.to_string(SC_HEX) << endl;
|
137 |
|
|
|
138 |
|
|
//rx_crc_transmission.dword = ~last_rx_crc;
|
139 |
|
|
//Generate error!
|
140 |
|
|
rx_crc_transmission.dword = 0x01234567;
|
141 |
|
|
transmit_rx_queue.push(rx_crc_transmission);
|
142 |
|
|
expecting_rx_crc_error++;
|
143 |
|
|
|
144 |
|
|
fill_rx_qeues(16, true);
|
145 |
|
|
fill_tx_qeues(16, true);
|
146 |
|
|
|
147 |
|
|
link_tx_validator::LinkTransmission_TX nop_transmit;
|
148 |
|
|
nop_transmit.dword = 0;
|
149 |
|
|
nop_transmit.lctl = true;
|
150 |
|
|
nop_transmit.hctl = true;
|
151 |
|
|
|
152 |
|
|
validator->expect_tx_consume_data = 600;
|
153 |
|
|
|
154 |
|
|
while(!(expected_rx_queue.empty() && validator->expected_transmission.empty())){
|
155 |
|
|
if(validator->to_transmit.size() < 2){
|
156 |
|
|
validator->to_transmit.push(nop_transmit);
|
157 |
|
|
validator->checking_errors = false;
|
158 |
|
|
}
|
159 |
|
|
|
160 |
|
|
if(lk_crc_error_csr.read()){
|
161 |
|
|
if(!expecting_rx_crc_error)
|
162 |
|
|
cout << "CRC mismatch on reception" << endl;
|
163 |
|
|
else
|
164 |
|
|
expecting_rx_crc_error--;
|
165 |
|
|
}
|
166 |
|
|
wait();
|
167 |
|
|
}
|
168 |
|
|
|
169 |
|
|
cout << "Done basic sequence without CTL error " << endl;
|
170 |
|
|
resetx = false;
|
171 |
|
|
|
172 |
|
|
if(expecting_rx_crc_error){
|
173 |
|
|
cout << "Some CRC transmission errors were not detected!" << endl;
|
174 |
|
|
}
|
175 |
|
|
|
176 |
|
|
//////////////////////////////////////
|
177 |
|
|
// Test : LDTSTOP sequence
|
178 |
|
|
//////////////////////////////////////
|
179 |
|
|
cout << endl << "Start LDTSTOP test" << endl;
|
180 |
|
|
empty_tx_queues(true);
|
181 |
|
|
empty_rx_queues(true);
|
182 |
|
|
init();
|
183 |
|
|
cout << "LDTSTOP init done" << endl;
|
184 |
|
|
init_fill_queues(272,true);
|
185 |
|
|
validator->expect_tx_consume_data = 600;
|
186 |
|
|
|
187 |
|
|
//Send part of the data
|
188 |
|
|
while(validator->expected_transmission.size() > 114){
|
189 |
|
|
if(lk_crc_error_csr.read()){
|
190 |
|
|
if(!expecting_rx_crc_error)
|
191 |
|
|
cout << "CRC mismatch on reception" << endl;
|
192 |
|
|
else
|
193 |
|
|
expecting_rx_crc_error--;
|
194 |
|
|
}
|
195 |
|
|
wait();
|
196 |
|
|
}
|
197 |
|
|
|
198 |
|
|
cout << "starting LDTSTOP sequence" << endl;
|
199 |
|
|
|
200 |
|
|
//Start ldtstop sequence
|
201 |
|
|
ldtstopx = false;
|
202 |
|
|
cd_initiate_nonretry_disconnect_lk = true;
|
203 |
|
|
|
204 |
|
|
while(validator->expected_transmission.size() > 0){
|
205 |
|
|
if(lk_crc_error_csr.read()){
|
206 |
|
|
if(!expecting_rx_crc_error)
|
207 |
|
|
cout << "CRC mismatch on reception" << endl;
|
208 |
|
|
else
|
209 |
|
|
expecting_rx_crc_error--;
|
210 |
|
|
}
|
211 |
|
|
wait();
|
212 |
|
|
}
|
213 |
|
|
|
214 |
|
|
cout << "Sending disconnect nops" << endl;
|
215 |
|
|
|
216 |
|
|
//Disconnect NOPs!
|
217 |
|
|
link_tx_validator::LinkTransmission_TX t_tx;
|
218 |
|
|
t_tx.dword = sc_uint<32>(0x00000020); t_tx.hctl = true; t_tx.lctl = true;
|
219 |
|
|
for(int n = 0; n < 20; n++)
|
220 |
|
|
validator->expected_transmission.push(t_tx);
|
221 |
|
|
|
222 |
|
|
while(validator->expected_transmission.size() > 10){
|
223 |
|
|
if(lk_crc_error_csr.read()){
|
224 |
|
|
if(!expecting_rx_crc_error)
|
225 |
|
|
cout << "CRC mismatch on reception" << endl;
|
226 |
|
|
else
|
227 |
|
|
expecting_rx_crc_error--;
|
228 |
|
|
}
|
229 |
|
|
wait();
|
230 |
|
|
}
|
231 |
|
|
|
232 |
|
|
cout << "Done LDTSTOP sequence test" << endl;
|
233 |
|
|
|
234 |
|
|
//////////////////////////////////////
|
235 |
|
|
// Test : SYNC sequence
|
236 |
|
|
//////////////////////////////////////
|
237 |
|
|
cout << endl << "Start SYNC test" << endl;
|
238 |
|
|
empty_tx_queues(true);
|
239 |
|
|
empty_rx_queues(true);
|
240 |
|
|
init();
|
241 |
|
|
init_fill_queues(400,true);
|
242 |
|
|
validator->expect_tx_consume_data = 600;
|
243 |
|
|
|
244 |
|
|
cout << "Start sending data" << endl;
|
245 |
|
|
//Send part of the data
|
246 |
|
|
while(validator->expected_transmission.size() > 1 || !phy_consume_lk.read()){
|
247 |
|
|
if(lk_crc_error_csr.read()){
|
248 |
|
|
if(!expecting_rx_crc_error)
|
249 |
|
|
cout << "CRC mismatch on reception" << endl;
|
250 |
|
|
else
|
251 |
|
|
expecting_rx_crc_error--;
|
252 |
|
|
}
|
253 |
|
|
wait();
|
254 |
|
|
}
|
255 |
|
|
|
256 |
|
|
cout << "starting SYNC sequence" << endl;
|
257 |
|
|
|
258 |
|
|
//Start sync sequence
|
259 |
|
|
csr_sync = true;
|
260 |
|
|
|
261 |
|
|
//Empty all expected packets
|
262 |
|
|
for(int n = expected_rx_queue.size(); n != 0 ;n--)
|
263 |
|
|
expected_rx_queue.pop();
|
264 |
|
|
|
265 |
|
|
//Expect disconnect NOPs!
|
266 |
|
|
t_tx.dword = sc_uint<32>(0xFFFFFFFF); t_tx.hctl = true; t_tx.lctl = true;
|
267 |
|
|
for(int n = 0; n < 150; n++)
|
268 |
|
|
validator->expected_transmission.push(t_tx);
|
269 |
|
|
|
270 |
|
|
while(validator->expected_transmission.size() > 10){
|
271 |
|
|
if(lk_crc_error_csr.read()){
|
272 |
|
|
cout << "CRC mismatch on reception" << endl;
|
273 |
|
|
}
|
274 |
|
|
wait();
|
275 |
|
|
}
|
276 |
|
|
|
277 |
|
|
csr_sync = false;
|
278 |
|
|
cout << "Done SYNC sequence test" << endl;
|
279 |
|
|
|
280 |
|
|
//////////////////////////////////////
|
281 |
|
|
// Test : CRC Error in retry mode (should be ignored)
|
282 |
|
|
//////////////////////////////////////
|
283 |
|
|
cout << endl << "Start Retry CRC error test" << endl;
|
284 |
|
|
empty_tx_queues(true);
|
285 |
|
|
empty_rx_queues(true);
|
286 |
|
|
init();
|
287 |
|
|
init_fill_queues(272,false);
|
288 |
|
|
validator->checking_errors = false;
|
289 |
|
|
|
290 |
|
|
//rx_crc_transmission.dword = ~last_rx_crc;
|
291 |
|
|
//Generate error!
|
292 |
|
|
transmit_rx_queue.push(rx_crc_transmission);
|
293 |
|
|
|
294 |
|
|
fill_rx_qeues(16, true);
|
295 |
|
|
fill_tx_qeues(16, true);
|
296 |
|
|
|
297 |
|
|
validator->expect_tx_consume_data = 600;
|
298 |
|
|
|
299 |
|
|
csr_retry = true;
|
300 |
|
|
|
301 |
|
|
while(!(expected_rx_queue.empty() && validator->expected_transmission.empty())){
|
302 |
|
|
if(validator->to_transmit.size() < 2){
|
303 |
|
|
validator->to_transmit.push(nop_transmit);
|
304 |
|
|
}
|
305 |
|
|
|
306 |
|
|
if(lk_crc_error_csr.read())
|
307 |
|
|
cout << "ERROR : CRC mismatch signaled in retry mode" << endl;
|
308 |
|
|
if(lk_initiate_retry_disconnect.read())
|
309 |
|
|
cout << "Error, retry sequence started incorrectly!" << endl;
|
310 |
|
|
wait();
|
311 |
|
|
}
|
312 |
|
|
|
313 |
|
|
cout << "Done retry sequence with periodic CRC error " << endl;
|
314 |
|
|
resetx = false;
|
315 |
|
|
csr_retry = false;
|
316 |
|
|
//validator->checking_errors = true;
|
317 |
|
|
|
318 |
|
|
|
319 |
|
|
//////////////////////////////////////
|
320 |
|
|
// Test : CTL transition error in retry mode
|
321 |
|
|
//////////////////////////////////////
|
322 |
|
|
cout << endl << "Start Retry CTL error test" << endl;
|
323 |
|
|
empty_tx_queues(true);
|
324 |
|
|
empty_rx_queues(true);
|
325 |
|
|
init();
|
326 |
|
|
init_fill_queues(50,false);
|
327 |
|
|
csr_retry = true;
|
328 |
|
|
validator->checking_errors = false;
|
329 |
|
|
|
330 |
|
|
LinkTransmission rx_ctl_error_t;
|
331 |
|
|
rx_ctl_error_t.error = true;
|
332 |
|
|
rx_ctl_error_t.lctl = true;
|
333 |
|
|
rx_ctl_error_t.hctl = true;
|
334 |
|
|
rx_ctl_error_t.dword = 0x01234567;
|
335 |
|
|
|
336 |
|
|
transmit_rx_queue.push(rx_ctl_error_t);
|
337 |
|
|
|
338 |
|
|
fill_rx_qeues(16, true);
|
339 |
|
|
fill_tx_qeues(16, true);
|
340 |
|
|
|
341 |
|
|
validator->expect_tx_consume_data = 600;
|
342 |
|
|
|
343 |
|
|
csr_retry = true;
|
344 |
|
|
|
345 |
|
|
while(!expected_rx_queue.empty() && !lk_initiate_retry_disconnect.read())
|
346 |
|
|
wait();
|
347 |
|
|
|
348 |
|
|
if(!lk_initiate_retry_disconnect.read())
|
349 |
|
|
cout << "Error, retry sequence not started correctly!" << endl;
|
350 |
|
|
|
351 |
|
|
csr_retry = false;
|
352 |
|
|
cout << "Done retry sequence CTL error " << endl;
|
353 |
|
|
|
354 |
|
|
//////////////////////////////////////
|
355 |
|
|
// Test : initiate an external retry sequence
|
356 |
|
|
//////////////////////////////////////
|
357 |
|
|
|
358 |
|
|
/*cout << "Start initiate Retry test" << endl;
|
359 |
|
|
empty_tx_queues(true);
|
360 |
|
|
empty_rx_queues(true);
|
361 |
|
|
init();
|
362 |
|
|
init_fill_queues(50,false);
|
363 |
|
|
csr_retry = true;
|
364 |
|
|
|
365 |
|
|
while(validator->expected_transmission.size() > 10)
|
366 |
|
|
wait();*/
|
367 |
|
|
|
368 |
|
|
resetx = false;
|
369 |
|
|
validator->checking_errors = false;
|
370 |
|
|
validator->reset();
|
371 |
|
|
|
372 |
|
|
//Inifinite loop
|
373 |
|
|
while(true) wait();
|
374 |
|
|
}
|
375 |
|
|
|
376 |
|
|
void link_l2_tb::init(){
|
377 |
|
|
cout << "TB: Init" << endl;
|
378 |
|
|
|
379 |
|
|
/**
|
380 |
|
|
Start reset and initialist internal variables and signals sent
|
381 |
|
|
to the link
|
382 |
|
|
*/
|
383 |
|
|
resetx = false;
|
384 |
|
|
pwrok = false;
|
385 |
|
|
ldtstopx = false;
|
386 |
|
|
|
387 |
|
|
csr_rx_link_width_lk = "000";
|
388 |
|
|
csr_tx_link_width_lk = "000";
|
389 |
|
|
csr_sync = false;
|
390 |
|
|
csr_end_of_chain = false;
|
391 |
|
|
|
392 |
|
|
csr_crc_force_error_lk = false;
|
393 |
|
|
csr_transmitter_off_lk = false;
|
394 |
|
|
csr_extented_ctl_lk = false;
|
395 |
|
|
csr_extended_ctl_timeout_lk = false;
|
396 |
|
|
csr_ldtstop_tristate_enable_lk = false;
|
397 |
|
|
|
398 |
|
|
#ifdef RETRY_MODE_ENABLED
|
399 |
|
|
cd_initiate_retry_disconnect = false;
|
400 |
|
|
fc_disconnect_lk = false;
|
401 |
|
|
csr_retry = false;
|
402 |
|
|
#endif
|
403 |
|
|
cd_initiate_nonretry_disconnect_lk = false;
|
404 |
|
|
|
405 |
|
|
//Reset validator to initial state
|
406 |
|
|
validator->reset();
|
407 |
|
|
//Wait some cycles for reset to have effect
|
408 |
|
|
for(int n = 0; n < 5; n++) wait();
|
409 |
|
|
validator->reset();//Not sure this call is necessary...
|
410 |
|
|
|
411 |
|
|
//Stop cold reset and make sure no in ldtstop sequence
|
412 |
|
|
pwrok = true;
|
413 |
|
|
ldtstopx = true;
|
414 |
|
|
transmitter->send_initial_value(5);
|
415 |
|
|
|
416 |
|
|
for(int n = 0; n < 5; n++) wait();
|
417 |
|
|
|
418 |
|
|
//stop reset
|
419 |
|
|
resetx = true;
|
420 |
|
|
//Reset the rx connection (it will reconnect automatically)
|
421 |
|
|
reset_rx_connection = true;
|
422 |
|
|
}
|
423 |
|
|
|
424 |
|
|
void link_l2_tb::init_fill_queues(const unsigned quantity,bool insertLastCrc){
|
425 |
|
|
//First, push a maximum of 128 in
|
426 |
|
|
int q_max128 = quantity > 128 ? 128 : quantity;
|
427 |
|
|
fill_rx_qeues(q_max128, true);
|
428 |
|
|
fill_tx_qeues(q_max128, true);
|
429 |
|
|
|
430 |
|
|
//Check how many are to add
|
431 |
|
|
int quantity_remaining = quantity - q_max128;
|
432 |
|
|
|
433 |
|
|
//if none, we're done
|
434 |
|
|
if(!quantity_remaining) return;
|
435 |
|
|
|
436 |
|
|
//128 is the first window
|
437 |
|
|
last_rx_crc = rx_crc;
|
438 |
|
|
last_tx_crc = tx_crc;
|
439 |
|
|
rx_crc = 0xFFFFFFFF;
|
440 |
|
|
tx_crc = 0xFFFFFFFF;
|
441 |
|
|
|
442 |
|
|
//Transmission object that will hold tx CRC
|
443 |
|
|
link_tx_validator::LinkTransmission_TX tx_crc_transmission;
|
444 |
|
|
tx_crc_transmission.lctl = true;
|
445 |
|
|
tx_crc_transmission.hctl = true;
|
446 |
|
|
|
447 |
|
|
//Transmission object that will hold rx CRC
|
448 |
|
|
LinkTransmission rx_crc_transmission;
|
449 |
|
|
rx_crc_transmission.error = false;
|
450 |
|
|
rx_crc_transmission.lctl = true;
|
451 |
|
|
rx_crc_transmission.hctl = true;
|
452 |
|
|
while(true){
|
453 |
|
|
//Send a max of 16 dwords
|
454 |
|
|
int q_max16 = quantity_remaining > 16 ? 16 : quantity_remaining;
|
455 |
|
|
//substract the number sent to the quantity remaining
|
456 |
|
|
quantity_remaining -= q_max16;
|
457 |
|
|
|
458 |
|
|
//Fill the queues
|
459 |
|
|
fill_rx_qeues(q_max16, true);
|
460 |
|
|
fill_tx_qeues(q_max16, true);
|
461 |
|
|
|
462 |
|
|
//Break if done
|
463 |
|
|
//If less than 16 were pushed in, we reached our quantity
|
464 |
|
|
//If 16 were pushed and none left, we're done if we don't want
|
465 |
|
|
//to add the last CRC
|
466 |
|
|
if(!quantity_remaining && !insertLastCrc || q_max16 != 16) break;
|
467 |
|
|
|
468 |
|
|
//Insert the CRC
|
469 |
|
|
tx_crc_transmission.dword = ~last_tx_crc;
|
470 |
|
|
rx_crc_transmission.dword = ~last_rx_crc;
|
471 |
|
|
validator->expected_transmission.push(tx_crc_transmission);
|
472 |
|
|
transmit_rx_queue.push(rx_crc_transmission);
|
473 |
|
|
//cout << "TX CRC inserted : " << tx_crc_transmission.dword.to_string(SC_HEX)
|
474 |
|
|
// << " Size now : " << validator->expected_transmission.size() << endl;
|
475 |
|
|
|
476 |
|
|
if(!quantity_remaining) break;
|
477 |
|
|
|
478 |
|
|
//Insert the next 112 dwords of the window
|
479 |
|
|
int q_max112 = quantity_remaining > 112 ? 112 : quantity_remaining;
|
480 |
|
|
quantity_remaining -= q_max112;
|
481 |
|
|
|
482 |
|
|
fill_rx_qeues(q_max112, true);
|
483 |
|
|
fill_tx_qeues(q_max112, true);
|
484 |
|
|
|
485 |
|
|
|
486 |
|
|
last_rx_crc = rx_crc;
|
487 |
|
|
last_tx_crc = tx_crc;
|
488 |
|
|
rx_crc = 0xFFFFFFFF;
|
489 |
|
|
tx_crc = 0xFFFFFFFF;
|
490 |
|
|
|
491 |
|
|
if(!quantity_remaining) break;
|
492 |
|
|
}
|
493 |
|
|
}
|
494 |
|
|
|
495 |
|
|
|
496 |
|
|
void link_l2_tb::fill_tx_qeues(const unsigned quantity, bool updateCRC){
|
497 |
|
|
LinkTransmission t;
|
498 |
|
|
link_tx_validator::LinkTransmission_TX t_tx;
|
499 |
|
|
|
500 |
|
|
//Add the requested number of transmissions
|
501 |
|
|
for(unsigned n = 0; n < quantity; n++){
|
502 |
|
|
//Generate a transmission
|
503 |
|
|
generate_random_transmission(t);
|
504 |
|
|
//Simply copy it into a TX transmission
|
505 |
|
|
t_tx.dword = t.dword; t_tx.hctl = t.hctl; t_tx.lctl = t.lctl;
|
506 |
|
|
|
507 |
|
|
//Put it in the expected and to_transmit queues
|
508 |
|
|
validator->expected_transmission.push(t_tx);
|
509 |
|
|
validator->to_transmit.push(t_tx);
|
510 |
|
|
if(updateCRC) {
|
511 |
|
|
update_crc(tx_crc,t.dword,t.lctl,t.hctl);
|
512 |
|
|
//cout << "CRC after " << n << " : " << tx_crc << "Hex " << sc_uint<32>(tx_crc).to_string(SC_HEX) << endl;
|
513 |
|
|
}
|
514 |
|
|
}
|
515 |
|
|
}
|
516 |
|
|
|
517 |
|
|
void link_l2_tb::empty_tx_queues(bool reset_crc){
|
518 |
|
|
for(int n = validator->expected_transmission.size(); n > 0; n--)
|
519 |
|
|
validator->expected_transmission.pop();
|
520 |
|
|
for(int n = validator->to_transmit.size(); n > 0; n--)
|
521 |
|
|
validator->to_transmit.pop();
|
522 |
|
|
if(reset_crc){
|
523 |
|
|
last_tx_crc = 0;
|
524 |
|
|
tx_crc = 0xFFFFFFFF;
|
525 |
|
|
}
|
526 |
|
|
}
|
527 |
|
|
|
528 |
|
|
void link_l2_tb::fill_rx_qeues(const unsigned quantity, bool updateCRC){
|
529 |
|
|
LinkTransmission t;
|
530 |
|
|
t.error = false;
|
531 |
|
|
for(int n = quantity; n != 0; n--){
|
532 |
|
|
generate_random_transmission(t);
|
533 |
|
|
transmit_rx_queue.push(t);
|
534 |
|
|
expected_rx_queue.push(t);
|
535 |
|
|
if(updateCRC)
|
536 |
|
|
update_crc(rx_crc,t.dword,t.lctl,t.hctl);
|
537 |
|
|
}
|
538 |
|
|
}
|
539 |
|
|
|
540 |
|
|
void link_l2_tb::empty_rx_queues(bool reset_crc){
|
541 |
|
|
for(int n = transmit_rx_queue.size();n>0;n--)
|
542 |
|
|
transmit_rx_queue.pop();
|
543 |
|
|
for(int n = expected_rx_queue.size();n>0;n--)
|
544 |
|
|
expected_rx_queue.pop();
|
545 |
|
|
if(reset_crc){
|
546 |
|
|
last_rx_crc = 0;
|
547 |
|
|
rx_crc = 0xFFFFFFFF;
|
548 |
|
|
}
|
549 |
|
|
}
|
550 |
|
|
|
551 |
|
|
void link_l2_tb::generate_random_transmission(LinkTransmission & t){
|
552 |
|
|
//15 bit used for rand because some implementations of rand
|
553 |
|
|
//have a max of 32K
|
554 |
|
|
sc_uint<15> r = rand();
|
555 |
|
|
t.dword.range(31,24) = r.range(7,0);
|
556 |
|
|
r = rand();
|
557 |
|
|
t.dword.range(23,16) = r.range(7,0);
|
558 |
|
|
r = rand();
|
559 |
|
|
t.dword.range(15,8) = r.range(7,0);
|
560 |
|
|
r = rand();
|
561 |
|
|
t.dword.range(7,0) = r.range(7,0);
|
562 |
|
|
|
563 |
|
|
t.lctl = (rand() << 1) / (RAND_MAX);
|
564 |
|
|
t.hctl = (rand() << 1) / (RAND_MAX);
|
565 |
|
|
}
|
566 |
|
|
|
567 |
|
|
void link_l2_tb::update_crc(int & crc,const sc_bv<32> &dword, bool lctl, bool hctl){
|
568 |
|
|
//There is a total of 36 bits to throw in CRC. Since it's higher
|
569 |
|
|
//than 32 bits, do it in two passes of 18 bits
|
570 |
|
|
unsigned dword_int = (unsigned)sc_uint<32>(dword);
|
571 |
|
|
|
572 |
|
|
//Put data in integers
|
573 |
|
|
int data[2] = {
|
574 |
|
|
(dword_int & 0xFF) | ((dword_int & 0xFF00) << 1),
|
575 |
|
|
((dword_int & 0xFF0000) >> 16) | ((dword_int & 0xFF000000) >> 15)
|
576 |
|
|
};
|
577 |
|
|
|
578 |
|
|
//Add the lctl values to the CRC
|
579 |
|
|
if(lctl) data[0] |= 0x20100;
|
580 |
|
|
if(hctl) data[1] |= 0x20100;
|
581 |
|
|
|
582 |
|
|
sc_uint<18> d0 = data[0];
|
583 |
|
|
sc_uint<18> d1 = data[1];
|
584 |
|
|
|
585 |
|
|
sc_bv<36> complete_data;
|
586 |
|
|
complete_data.range(17,0) = data[0];
|
587 |
|
|
complete_data.range(35,18) = data[1];
|
588 |
|
|
|
589 |
|
|
//cout << "TB CRC DATA " << complete_data.to_string(SC_HEX) << endl;
|
590 |
|
|
|
591 |
|
|
//Do the two passes
|
592 |
|
|
for(int n = 0; n < 2; n++){
|
593 |
|
|
//- taken exactly from the HT spec (10.1.1)
|
594 |
|
|
for(int i = 0; i < 18; i++){
|
595 |
|
|
int tmp = crc >> 31; /* store highest bit */
|
596 |
|
|
crc = (crc << 1) | ((data[n] >> i) & 1); /* shift message in */
|
597 |
|
|
crc = (tmp) ? crc ^ poly : crc; /* substract poly if greater */
|
598 |
|
|
}
|
599 |
|
|
}
|
600 |
|
|
}
|
601 |
|
|
|
602 |
|
|
|
603 |
|
|
void link_l2_tb::manage_rx_transmission(){
|
604 |
|
|
while(true){
|
605 |
|
|
if(reset_rx_connection){
|
606 |
|
|
transmitter->send_initial_value(5);
|
607 |
|
|
transmitter->send_init_sequence(0,0);
|
608 |
|
|
reset_rx_connection = false;
|
609 |
|
|
}
|
610 |
|
|
if(!transmit_rx_queue.empty()){
|
611 |
|
|
transmitter->send_dword_link(
|
612 |
|
|
transmit_rx_queue.front().dword,
|
613 |
|
|
transmit_rx_queue.front().lctl,
|
614 |
|
|
transmit_rx_queue.front().hctl,
|
615 |
|
|
transmit_rx_queue.front().error);
|
616 |
|
|
transmit_rx_queue.pop();
|
617 |
|
|
}
|
618 |
|
|
else
|
619 |
|
|
wait();
|
620 |
|
|
}
|
621 |
|
|
}
|
622 |
|
|
|
623 |
|
|
|
624 |
|
|
void link_l2_tb::validate_rx_reception(){
|
625 |
|
|
while(true){
|
626 |
|
|
wait();
|
627 |
|
|
//Test reception of data
|
628 |
|
|
if(lk_available_cd.read() && check_rx_dword_reception){
|
629 |
|
|
verify(!(expected_rx_queue.empty()),
|
630 |
|
|
"RX : Unexpected data reception");
|
631 |
|
|
if(!expected_rx_queue.empty()){
|
632 |
|
|
LinkTransmission t = expected_rx_queue.front();
|
633 |
|
|
|
634 |
|
|
/*cout << "RX Data in front : L=" << t.lctl << " H=" <<
|
635 |
|
|
t.hctl << " D=" << t.dword.to_string(SC_HEX) << " Number: " << rx_number++ << endl;
|
636 |
|
|
cout << "RX Data received : L=" << lk_lctl_cd.read() << " H=" <<
|
637 |
|
|
lk_hctl_cd.read() << " D=" << lk_dword_cd.read().to_string(SC_HEX) << endl;*/
|
638 |
|
|
|
639 |
|
|
expected_rx_queue.pop();
|
640 |
|
|
|
641 |
|
|
verify((t.dword == lk_dword_cd.read() &&
|
642 |
|
|
t.lctl == lk_lctl_cd.read() &&
|
643 |
|
|
t.hctl == lk_hctl_cd.read()),
|
644 |
|
|
"RX Invalid data received");
|
645 |
|
|
}
|
646 |
|
|
}
|
647 |
|
|
}
|
648 |
|
|
|
649 |
|
|
}
|