1 |
2 |
acastong |
//main.cpp for decoder_l2 testbench
|
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 "../../rtl/systemc/core_synth/synth_datatypes.h"
|
40 |
|
|
#include "../../rtl/systemc/core_synth/constants.h"
|
41 |
|
|
|
42 |
|
|
#include "decoder_l2_tb.h"
|
43 |
|
|
#include "../../rtl/systemc/decoder_l2/decoder_l2.h"
|
44 |
|
|
#include "../../rtl/systemc/decoder_l2/cd_counter_l3.h"
|
45 |
|
|
#include "../../rtl/systemc/decoder_l2/cd_packet_crc_l3.h"
|
46 |
|
|
|
47 |
|
|
#include <iostream>
|
48 |
|
|
#include <string>
|
49 |
|
|
#include <sstream>
|
50 |
|
|
#include <iomanip>
|
51 |
|
|
#include <time.h>
|
52 |
|
|
|
53 |
|
|
using namespace std;
|
54 |
|
|
|
55 |
|
|
int sc_main( int argc, char* argv[] ){
|
56 |
|
|
|
57 |
|
|
//The Design Under Test
|
58 |
|
|
decoder_l2* dut = new decoder_l2("decoder_l2");
|
59 |
|
|
//The TestBench
|
60 |
|
|
decoder_l2_tb* tb = new decoder_l2_tb("decoder_l2_tb");
|
61 |
|
|
|
62 |
|
|
|
63 |
|
|
//Signals used to link the design to the testbench
|
64 |
|
|
sc_clock clk("clk", 1); // system clk
|
65 |
|
|
|
66 |
|
|
///Warm Reset to initialize module
|
67 |
|
|
sc_signal < bool > resetx;
|
68 |
|
|
|
69 |
|
|
//*******************************
|
70 |
|
|
// Signals for Control Buffer
|
71 |
|
|
//*******************************
|
72 |
|
|
|
73 |
|
|
/**Packet to be transmitted to control buffer module*/
|
74 |
|
|
sc_signal< syn_ControlPacketComplete > cd_packet_ro;
|
75 |
|
|
/**Enables control buffer module to read cd_packet_ro port*/
|
76 |
|
|
sc_signal< bool > cd_available_ro;
|
77 |
|
|
/**If we're currently receiving data. This is used by the ro to know
|
78 |
|
|
if we have finished receiving the data of a packet, so it can know if
|
79 |
|
|
it can send it.*/
|
80 |
|
|
sc_signal<bool> cd_data_pending_ro;
|
81 |
|
|
/**Where we are storing data. This is used by the ro to know
|
82 |
|
|
if we have finished receiving the data of a packet, so it can know if
|
83 |
|
|
it can send it.*/
|
84 |
|
|
sc_signal<sc_uint<BUFFERS_ADDRESS_WIDTH> > cd_data_pending_addr_ro;
|
85 |
|
|
|
86 |
|
|
//*******************************
|
87 |
|
|
// Signals for Data Buffer
|
88 |
|
|
//*******************************
|
89 |
|
|
|
90 |
|
|
///ddress of data in data buffer module
|
91 |
|
|
sc_signal< sc_uint<BUFFERS_ADDRESS_WIDTH> > db_address_cd;
|
92 |
|
|
///Get an address form data buffer module
|
93 |
|
|
sc_signal< bool > cd_getaddr_db;
|
94 |
|
|
///Size of data packet to be written
|
95 |
|
|
sc_signal< sc_uint<4> > cd_datalen_db;
|
96 |
|
|
///Virtual channel where data will be written
|
97 |
|
|
sc_signal< VirtualChannel > cd_vctype_db;
|
98 |
|
|
///Data to be written in data buffer module
|
99 |
|
|
sc_signal< sc_bv<32> > cd_data_db;
|
100 |
|
|
///Enables data buffer to read cd_data_db port
|
101 |
|
|
sc_signal< bool > cd_write_db;
|
102 |
|
|
|
103 |
|
|
#ifdef RETRY_MODE_ENABLED
|
104 |
|
|
///Erase signal for packet stomping
|
105 |
|
|
sc_signal< bool > cd_drop_db;
|
106 |
|
|
#endif
|
107 |
|
|
|
108 |
|
|
|
109 |
|
|
//*************************************
|
110 |
|
|
// Signals to CSR
|
111 |
|
|
//*************************************
|
112 |
|
|
|
113 |
|
|
///A protocol error has been detected
|
114 |
|
|
sc_signal< bool > cd_protocol_error_csr;
|
115 |
|
|
///A sync packet has been received
|
116 |
|
|
sc_signal< bool > cd_sync_detected_csr;
|
117 |
|
|
#ifdef RETRY_MODE_ENABLED
|
118 |
|
|
///If retry mode is active
|
119 |
|
|
sc_signal< bool > csr_retry;
|
120 |
|
|
#endif
|
121 |
|
|
|
122 |
|
|
//*******************************
|
123 |
|
|
// Signals from link
|
124 |
|
|
//*******************************
|
125 |
|
|
|
126 |
|
|
///Bit vector input from the FIFO
|
127 |
|
|
sc_signal< sc_bv<32> > lk_dword_cd;
|
128 |
|
|
///Control bit
|
129 |
|
|
sc_signal< bool > lk_hctl_cd;
|
130 |
|
|
///Control bit
|
131 |
|
|
sc_signal< bool > lk_lctl_cd;
|
132 |
|
|
///FIFO is ready to be read from
|
133 |
|
|
sc_signal< bool > lk_available_cd;
|
134 |
|
|
|
135 |
|
|
#ifdef RETRY_MODE_ENABLED
|
136 |
|
|
///If a retry sequence is initiated by link
|
137 |
|
|
sc_signal< bool > lk_initiate_retry_disconnect;
|
138 |
|
|
#endif
|
139 |
|
|
//*******************************
|
140 |
|
|
// Signals for Forwarding module
|
141 |
|
|
//*******************************
|
142 |
|
|
|
143 |
|
|
#ifdef RETRY_MODE_ENABLED
|
144 |
|
|
///History count
|
145 |
|
|
sc_signal< sc_uint<8> > cd_rx_next_pkt_to_ack_fc;
|
146 |
|
|
///rxPacketToAck (retry mode)
|
147 |
|
|
sc_signal< sc_uint<8> > cd_nop_ack_value_fc;
|
148 |
|
|
#endif
|
149 |
|
|
|
150 |
|
|
///Info registered from NOP word
|
151 |
|
|
sc_signal< sc_bv<12> > cd_nopinfo_fc;
|
152 |
|
|
///Signal that new nop info are available
|
153 |
|
|
sc_signal< bool > cd_nop_received_fc;
|
154 |
|
|
|
155 |
|
|
#ifdef RETRY_MODE_ENABLED
|
156 |
|
|
///Start the sequence for a retry disconnect
|
157 |
|
|
sc_signal< bool > cd_initiate_retry_disconnect;
|
158 |
|
|
///A stomped packet has been received
|
159 |
|
|
sc_signal<bool> cd_received_stomped_csr;
|
160 |
|
|
///Let the reordering know we received a non flow control stomped packet
|
161 |
|
|
/** When this situation happens, packet available bit does not become
|
162 |
|
|
asserted but the correct packet is sent, which can be used to know
|
163 |
|
|
from which VC to free a flow control credit.
|
164 |
|
|
*/
|
165 |
|
|
sc_signal<bool> cd_received_non_flow_stomped_ro;
|
166 |
|
|
#endif
|
167 |
|
|
///The link can start a sequence for a ldtstop disconnect
|
168 |
|
|
sc_signal< bool > cd_initiate_nonretry_disconnect_lk;
|
169 |
|
|
|
170 |
|
|
////////////////////////////////////////////////////////////////
|
171 |
|
|
////////////////////////////////////////////////////////////////
|
172 |
|
|
// DUT connections
|
173 |
|
|
////////////////////////////////////////////////////////////////
|
174 |
|
|
////////////////////////////////////////////////////////////////
|
175 |
|
|
|
176 |
|
|
//Signals used to link the design to the testbench
|
177 |
|
|
dut->clk(clk);
|
178 |
|
|
dut->resetx(resetx);
|
179 |
|
|
dut->cd_packet_ro(cd_packet_ro);
|
180 |
|
|
dut->cd_available_ro(cd_available_ro);
|
181 |
|
|
dut->cd_data_pending_ro(cd_data_pending_ro);
|
182 |
|
|
dut->cd_data_pending_addr_ro(cd_data_pending_addr_ro);
|
183 |
|
|
|
184 |
|
|
dut->db_address_cd(db_address_cd);
|
185 |
|
|
dut->cd_getaddr_db(cd_getaddr_db);
|
186 |
|
|
dut->cd_datalen_db(cd_datalen_db);
|
187 |
|
|
dut->cd_vctype_db(cd_vctype_db);
|
188 |
|
|
dut->cd_data_db(cd_data_db);
|
189 |
|
|
dut->cd_write_db(cd_write_db);
|
190 |
|
|
|
191 |
|
|
#ifdef RETRY_MODE_ENABLED
|
192 |
|
|
dut->cd_drop_db(cd_drop_db);
|
193 |
|
|
#endif
|
194 |
|
|
|
195 |
|
|
|
196 |
|
|
dut->cd_protocol_error_csr(cd_protocol_error_csr);
|
197 |
|
|
dut->cd_sync_detected_csr(cd_sync_detected_csr);
|
198 |
|
|
#ifdef RETRY_MODE_ENABLED
|
199 |
|
|
dut->csr_retry(csr_retry);
|
200 |
|
|
#endif
|
201 |
|
|
|
202 |
|
|
dut->lk_dword_cd(lk_dword_cd);
|
203 |
|
|
dut->lk_hctl_cd(lk_hctl_cd);
|
204 |
|
|
dut->lk_lctl_cd(lk_lctl_cd);
|
205 |
|
|
dut->lk_available_cd(lk_available_cd);
|
206 |
|
|
|
207 |
|
|
#ifdef RETRY_MODE_ENABLED
|
208 |
|
|
dut->lk_initiate_retry_disconnect(lk_initiate_retry_disconnect);
|
209 |
|
|
#endif
|
210 |
|
|
|
211 |
|
|
#ifdef RETRY_MODE_ENABLED
|
212 |
|
|
dut->cd_rx_next_pkt_to_ack_fc(cd_rx_next_pkt_to_ack_fc);
|
213 |
|
|
dut->cd_nop_ack_value_fc(cd_nop_ack_value_fc);
|
214 |
|
|
#endif
|
215 |
|
|
|
216 |
|
|
dut->cd_nopinfo_fc(cd_nopinfo_fc);
|
217 |
|
|
dut->cd_nop_received_fc(cd_nop_received_fc);
|
218 |
|
|
|
219 |
|
|
#ifdef RETRY_MODE_ENABLED
|
220 |
|
|
dut->cd_initiate_retry_disconnect(cd_initiate_retry_disconnect);
|
221 |
|
|
dut->cd_received_stomped_csr(cd_received_stomped_csr);
|
222 |
|
|
dut->cd_received_non_flow_stomped_ro(cd_received_non_flow_stomped_ro);
|
223 |
|
|
#endif
|
224 |
|
|
dut->cd_initiate_nonretry_disconnect_lk(cd_initiate_nonretry_disconnect_lk);
|
225 |
|
|
|
226 |
|
|
|
227 |
|
|
////////////////////////////////////////////////////////////////
|
228 |
|
|
////////////////////////////////////////////////////////////////
|
229 |
|
|
// TB connections
|
230 |
|
|
////////////////////////////////////////////////////////////////
|
231 |
|
|
////////////////////////////////////////////////////////////////
|
232 |
|
|
|
233 |
|
|
tb->clk(clk);
|
234 |
|
|
tb->resetx(resetx);
|
235 |
|
|
tb->cd_packet_ro(cd_packet_ro);
|
236 |
|
|
tb->cd_available_ro(cd_available_ro);
|
237 |
|
|
tb->cd_data_pending_ro(cd_data_pending_ro);
|
238 |
|
|
tb->cd_data_pending_addr_ro(cd_data_pending_addr_ro);
|
239 |
|
|
|
240 |
|
|
tb->db_address_cd(db_address_cd);
|
241 |
|
|
tb->cd_getaddr_db(cd_getaddr_db);
|
242 |
|
|
tb->cd_datalen_db(cd_datalen_db);
|
243 |
|
|
tb->cd_vctype_db(cd_vctype_db);
|
244 |
|
|
tb->cd_data_db(cd_data_db);
|
245 |
|
|
tb->cd_write_db(cd_write_db);
|
246 |
|
|
|
247 |
|
|
#ifdef RETRY_MODE_ENABLED
|
248 |
|
|
tb->cd_drop_db(cd_drop_db);
|
249 |
|
|
#endif
|
250 |
|
|
|
251 |
|
|
|
252 |
|
|
tb->cd_protocol_error_csr(cd_protocol_error_csr);
|
253 |
|
|
tb->cd_sync_detected_csr(cd_sync_detected_csr);
|
254 |
|
|
#ifdef RETRY_MODE_ENABLED
|
255 |
|
|
tb->csr_retry(csr_retry);
|
256 |
|
|
#endif
|
257 |
|
|
|
258 |
|
|
tb->lk_dword_cd(lk_dword_cd);
|
259 |
|
|
tb->lk_hctl_cd(lk_hctl_cd);
|
260 |
|
|
tb->lk_lctl_cd(lk_lctl_cd);
|
261 |
|
|
tb->lk_available_cd(lk_available_cd);
|
262 |
|
|
|
263 |
|
|
#ifdef RETRY_MODE_ENABLED
|
264 |
|
|
tb->lk_initiate_retry_disconnect(lk_initiate_retry_disconnect);
|
265 |
|
|
#endif
|
266 |
|
|
|
267 |
|
|
#ifdef RETRY_MODE_ENABLED
|
268 |
|
|
tb->cd_rx_next_pkt_to_ack_fc(cd_rx_next_pkt_to_ack_fc);
|
269 |
|
|
tb->cd_nop_ack_value_fc(cd_nop_ack_value_fc);
|
270 |
|
|
#endif
|
271 |
|
|
|
272 |
|
|
tb->cd_nopinfo_fc(cd_nopinfo_fc);
|
273 |
|
|
tb->cd_nop_received_fc(cd_nop_received_fc);
|
274 |
|
|
|
275 |
|
|
#ifdef RETRY_MODE_ENABLED
|
276 |
|
|
tb->cd_initiate_retry_disconnect(cd_initiate_retry_disconnect);
|
277 |
|
|
tb->cd_received_stomped_csr(cd_received_stomped_csr);
|
278 |
|
|
tb->cd_received_non_flow_stomped_ro(cd_received_non_flow_stomped_ro);
|
279 |
|
|
#endif
|
280 |
|
|
tb->cd_initiate_nonretry_disconnect_lk(cd_initiate_nonretry_disconnect_lk);
|
281 |
|
|
|
282 |
|
|
////////////////////////////////////////////////////////////////
|
283 |
|
|
////////////////////////////////////////////////////////////////
|
284 |
|
|
// Trace signals
|
285 |
|
|
////////////////////////////////////////////////////////////////
|
286 |
|
|
////////////////////////////////////////////////////////////////
|
287 |
|
|
|
288 |
|
|
sc_trace_file *tf = sc_create_vcd_trace_file("sim_decoder_l2");
|
289 |
|
|
|
290 |
|
|
sc_trace(tf,clk,"clk");
|
291 |
|
|
sc_trace(tf,resetx,"resetx");
|
292 |
|
|
sc_trace(tf,cd_packet_ro,"cd_packet_ro");
|
293 |
|
|
sc_trace(tf,cd_available_ro,"cd_available_ro");
|
294 |
|
|
sc_trace(tf,cd_data_pending_ro,"cd_data_pending_ro");
|
295 |
|
|
sc_trace(tf,cd_data_pending_addr_ro,"cd_data_pending_addr_ro");
|
296 |
|
|
|
297 |
|
|
sc_trace(tf,db_address_cd,"db_address_cd");
|
298 |
|
|
sc_trace(tf,cd_getaddr_db,"cd_getaddr_db");
|
299 |
|
|
sc_trace(tf,cd_datalen_db,"cd_datalen_db");
|
300 |
|
|
sc_trace(tf,cd_vctype_db,"cd_vctype_db");
|
301 |
|
|
sc_trace(tf,cd_data_db,"cd_data_db");
|
302 |
|
|
sc_trace(tf,cd_write_db,"cd_write_db");
|
303 |
|
|
|
304 |
|
|
#ifdef RETRY_MODE_ENABLED
|
305 |
|
|
sc_trace(tf,cd_drop_db,"cd_drop_db");
|
306 |
|
|
#endif
|
307 |
|
|
|
308 |
|
|
|
309 |
|
|
sc_trace(tf,cd_protocol_error_csr,"cd_protocol_error_csr");
|
310 |
|
|
sc_trace(tf,cd_sync_detected_csr,"cd_sync_detected_csr");
|
311 |
|
|
#ifdef RETRY_MODE_ENABLED
|
312 |
|
|
sc_trace(tf,csr_retry,"csr_retry");
|
313 |
|
|
#endif
|
314 |
|
|
|
315 |
|
|
sc_trace(tf,lk_dword_cd,"lk_dword_cd");
|
316 |
|
|
sc_trace(tf,lk_hctl_cd,"lk_hctl_cd");
|
317 |
|
|
sc_trace(tf,lk_lctl_cd,"lk_lctl_cd");
|
318 |
|
|
sc_trace(tf,lk_available_cd,"lk_available_cd");
|
319 |
|
|
|
320 |
|
|
#ifdef RETRY_MODE_ENABLED
|
321 |
|
|
sc_trace(tf,lk_initiate_retry_disconnect,"lk_initiate_retry_disconnect");
|
322 |
|
|
#endif
|
323 |
|
|
|
324 |
|
|
#ifdef RETRY_MODE_ENABLED
|
325 |
|
|
sc_trace(tf,cd_rx_next_pkt_to_ack_fc,"cd_rx_next_pkt_to_ack_fc");
|
326 |
|
|
sc_trace(tf,cd_nop_ack_value_fc,"cd_nop_ack_value_fc");
|
327 |
|
|
#endif
|
328 |
|
|
|
329 |
|
|
sc_trace(tf,cd_nopinfo_fc,"cd_nopinfo_fc");
|
330 |
|
|
sc_trace(tf,cd_nop_received_fc,"cd_nop_received_fc");
|
331 |
|
|
|
332 |
|
|
#ifdef RETRY_MODE_ENABLED
|
333 |
|
|
sc_trace(tf,cd_initiate_retry_disconnect,"cd_initiate_retry_disconnect");
|
334 |
|
|
sc_trace(tf,cd_received_stomped_csr,"cd_received_stomped_csr");
|
335 |
|
|
#endif
|
336 |
|
|
sc_trace(tf,cd_initiate_nonretry_disconnect_lk,"cd_initiate_nonretry_disconnect_lk");
|
337 |
|
|
|
338 |
|
|
|
339 |
|
|
sc_trace(tf,dut->CNT->setCnt,"CNT.setCnt");
|
340 |
|
|
sc_trace(tf,dut->CNT->decrCnt,"CNT.decrCnt");
|
341 |
|
|
sc_trace(tf,dut->CNT->data,"CNT.data");
|
342 |
|
|
sc_trace(tf,dut->CNT->end_of_count,"CNT.end_of_count");
|
343 |
|
|
|
344 |
|
|
sc_trace(tf,dut->packet_crc_unit->crc1_enable,"CRC.crc1_enable");
|
345 |
|
|
sc_trace(tf,dut->packet_crc_unit->crc2_enable,"CRC.crc2_enable");
|
346 |
|
|
sc_trace(tf,dut->packet_crc_unit->crc1_reset,"CRC.crc1_reset");
|
347 |
|
|
sc_trace(tf,dut->packet_crc_unit->crc2_reset,"CRC.crc2_reset");
|
348 |
|
|
|
349 |
|
|
sc_trace(tf,dut->packet_crc_unit->crc1_good,"CRC.crc1_good");
|
350 |
|
|
sc_trace(tf,dut->packet_crc_unit->crc2_good,"CRC.crc2_good");
|
351 |
|
|
sc_trace(tf,dut->packet_crc_unit->crc1_stomped,"CRC.crc1_stomped");
|
352 |
|
|
sc_trace(tf,dut->packet_crc_unit->crc2_stomped,"CRC.crc2_stomped");
|
353 |
|
|
|
354 |
|
|
|
355 |
|
|
//------------------------------------------
|
356 |
|
|
// Start simulation
|
357 |
|
|
//------------------------------------------
|
358 |
|
|
cout << "Start of Decoder simulation" << endl;
|
359 |
|
|
|
360 |
|
|
sc_start(200);
|
361 |
|
|
|
362 |
|
|
sc_close_vcd_trace_file(tf);
|
363 |
|
|
cout << "End of simulation" << endl;
|
364 |
|
|
|
365 |
|
|
delete dut;
|
366 |
|
|
delete tb;
|
367 |
|
|
return 0;
|
368 |
|
|
}
|
369 |
|
|
|