1 |
2 |
acastong |
//csr_l2_tb.cpp
|
2 |
|
|
|
3 |
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
4 |
|
|
* Version: MPL 1.1
|
5 |
|
|
*
|
6 |
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
7 |
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
8 |
|
|
* the License. You may obtain a copy of the License at
|
9 |
|
|
* http://www.mozilla.org/MPL/
|
10 |
|
|
*
|
11 |
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
12 |
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
13 |
|
|
* for the specific language governing rights and limitations under the
|
14 |
|
|
* License.
|
15 |
|
|
*
|
16 |
|
|
* The Original Code is HyperTransport Tunnel IP Core.
|
17 |
|
|
*
|
18 |
|
|
* The Initial Developer of the Original Code is
|
19 |
|
|
* Ecole Polytechnique de Montreal.
|
20 |
|
|
* Portions created by the Initial Developer are Copyright (C) 2005
|
21 |
|
|
* the Initial Developer. All Rights Reserved.
|
22 |
|
|
*
|
23 |
|
|
* Contributor(s):
|
24 |
|
|
* Ami Castonguay <acastong@grm.polymtl.ca>
|
25 |
|
|
*
|
26 |
|
|
* Alternatively, the contents of this file may be used under the terms
|
27 |
|
|
* of the Polytechnique HyperTransport Tunnel IP Core Source Code License
|
28 |
|
|
* (the "PHTICSCL License", see the file PHTICSCL.txt), in which case the
|
29 |
|
|
* provisions of PHTICSCL License are applicable instead of those
|
30 |
|
|
* above. If you wish to allow use of your version of this file only
|
31 |
|
|
* under the terms of the PHTICSCL License and not to allow others to use
|
32 |
|
|
* your version of this file under the MPL, indicate your decision by
|
33 |
|
|
* deleting the provisions above and replace them with the notice and
|
34 |
|
|
* other provisions required by the PHTICSCL License. If you do not delete
|
35 |
|
|
* the provisions above, a recipient may use your version of this file
|
36 |
|
|
* under either the MPL or the PHTICSCL License."
|
37 |
|
|
*
|
38 |
|
|
* ***** END LICENSE BLOCK ***** */
|
39 |
|
|
|
40 |
|
|
#include "csr_l2_tb.h"
|
41 |
|
|
#include <cstdlib>
|
42 |
|
|
|
43 |
|
|
using namespace std;
|
44 |
|
|
|
45 |
|
|
csr_l2_tb::csr_l2_tb(sc_module_name name) : sc_module(name){
|
46 |
|
|
SC_THREAD(send_packets_csr);
|
47 |
|
|
sensitive_pos(clk);
|
48 |
|
|
SC_THREAD(verify_csr_response);
|
49 |
|
|
sensitive_pos(clk);
|
50 |
|
|
SC_THREAD(simulate_databuffer);
|
51 |
|
|
sensitive_pos(clk);
|
52 |
|
|
SC_THREAD(flow_control_read_signals);
|
53 |
|
|
sensitive_pos(clk);
|
54 |
|
|
sensitive << csr_available_fc0 << csr_available_fc1;
|
55 |
|
|
|
56 |
|
|
SC_THREAD(grant_access_databuffer);
|
57 |
|
|
sensitive_pos(clk);
|
58 |
|
|
sensitive << csr_request_databuffer0_access_ui << csr_request_databuffer1_access_ui;
|
59 |
|
|
|
60 |
|
|
generate_csr_requests_and_responses();
|
61 |
|
|
srand(4623);
|
62 |
|
|
}
|
63 |
|
|
|
64 |
|
|
void csr_l2_tb::send_packets_csr(){
|
65 |
|
|
//Initialize startup values
|
66 |
|
|
ro0_available_csr = false;
|
67 |
|
|
data_sent0 = 0;
|
68 |
|
|
ro0_packet_csr = to_send0.front().pkt_cplt;
|
69 |
|
|
|
70 |
|
|
ro1_available_csr = false;
|
71 |
|
|
ro1_packet_csr = to_send1.front().pkt_cplt;
|
72 |
|
|
data_sent1 = 0;
|
73 |
|
|
|
74 |
|
|
syn_ControlPacketComplete default_syn_pkt;
|
75 |
|
|
initialize_syn_ControlPacketComplete(default_syn_pkt);
|
76 |
|
|
|
77 |
|
|
//Start with a reset
|
78 |
|
|
resetx = false;
|
79 |
|
|
for(int n = 0; n <5; n++){
|
80 |
|
|
wait();
|
81 |
|
|
}
|
82 |
|
|
resetx = true;
|
83 |
|
|
|
84 |
|
|
while(true){
|
85 |
|
|
wait();
|
86 |
|
|
/**
|
87 |
|
|
At first, send packets from to_send0 and to_send1. When the two
|
88 |
|
|
queues are empty, send packets to both sides from to_send. Having
|
89 |
|
|
to_send0 and to_send1 makes sure that the CSR can truly receive from
|
90 |
|
|
the two sides. Then, having the same packet sent to both sides eases
|
91 |
|
|
testing.
|
92 |
|
|
*/
|
93 |
|
|
if(!(to_send0.empty() && to_send1.empty())){
|
94 |
|
|
ro0_available_csr = ((rand() % 10 < 4)
|
95 |
|
|
|| (ro0_available_csr.read() && !csr_ack_ro0.read())) && !to_send0.empty() ;
|
96 |
|
|
ro1_available_csr = ((rand() % 10 < 4)
|
97 |
|
|
|| (ro1_available_csr.read() && !csr_ack_ro1.read())) && !to_send1.empty() ;
|
98 |
|
|
}
|
99 |
|
|
else{
|
100 |
|
|
ro0_available_csr = ((rand() % 10 < 4) ||
|
101 |
|
|
(ro0_available_csr.read() && (!csr_ack_ro0.read() || !csr_ack_ro1.read()) ))&&
|
102 |
|
|
!to_send.empty();
|
103 |
|
|
ro1_available_csr = ((rand() % 10 < 4) ||
|
104 |
|
|
(ro1_available_csr.read() && (!csr_ack_ro0.read() || !csr_ack_ro1.read()) ))&&
|
105 |
|
|
!to_send.empty();
|
106 |
|
|
}
|
107 |
|
|
|
108 |
|
|
if(!to_send0.empty()){
|
109 |
|
|
ro0_packet_csr = to_send0.front().pkt_cplt;
|
110 |
|
|
}
|
111 |
|
|
else if(!to_send.empty()){
|
112 |
|
|
ro0_packet_csr = to_send.front().pkt_cplt;
|
113 |
|
|
}
|
114 |
|
|
else
|
115 |
|
|
ro0_packet_csr = default_syn_pkt;
|
116 |
|
|
|
117 |
|
|
if(!to_send1.empty()){
|
118 |
|
|
ro1_packet_csr = (syn_ControlPacketComplete)to_send1.front().pkt_cplt;
|
119 |
|
|
}
|
120 |
|
|
else if(!to_send.empty()){
|
121 |
|
|
ro1_packet_csr = (syn_ControlPacketComplete)to_send.front().pkt_cplt;
|
122 |
|
|
}
|
123 |
|
|
else
|
124 |
|
|
ro1_packet_csr = default_syn_pkt;
|
125 |
|
|
|
126 |
|
|
//When sent packet is acked
|
127 |
|
|
if(csr_ack_ro0.read()){
|
128 |
|
|
//Packet left from side 0
|
129 |
|
|
side_pkt_sent = 0;
|
130 |
|
|
//Check that if the previous packet had data associated, that it was all sent
|
131 |
|
|
if(data_size0 != 0)
|
132 |
|
|
cout << "ERROR:Not all data sent side 0"<< endl;
|
133 |
|
|
//Reset the data sent counter
|
134 |
|
|
data_sent0 = 0;
|
135 |
|
|
|
136 |
|
|
/**
|
137 |
|
|
Set the variables necessary to simulate the databuffer to send the data
|
138 |
|
|
associated with the packet sent.
|
139 |
|
|
|
140 |
|
|
Once the data is extracted, pop the packet from it's queue.
|
141 |
|
|
*/
|
142 |
|
|
if(!to_send0.empty()){
|
143 |
|
|
if(to_send0.front().pkt_cplt.packet->hasDataAssociated())
|
144 |
|
|
data_size0 = to_send0.front().pkt_cplt.packet->getDataLengthm1()+1;
|
145 |
|
|
data_address0 = to_send0.front().pkt_cplt.data_address;
|
146 |
|
|
data_vc0 = to_send0.front().pkt_cplt.packet->getVirtualChannel();
|
147 |
|
|
for(int n = 0; n < 16;n++){
|
148 |
|
|
data0[n] = to_send0.front().data[n];
|
149 |
|
|
}
|
150 |
|
|
to_send0.pop_front();
|
151 |
|
|
}
|
152 |
|
|
else if(!to_send.empty()){
|
153 |
|
|
if(to_send.front().pkt_cplt.packet->hasDataAssociated())
|
154 |
|
|
data_size0 = to_send.front().pkt_cplt.packet->getDataLengthm1()+1;
|
155 |
|
|
data_address0 = to_send.front().pkt_cplt.data_address;
|
156 |
|
|
data_vc0 = to_send.front().pkt_cplt.packet->getVirtualChannel();
|
157 |
|
|
for(int n = 0; n < 16;n++){
|
158 |
|
|
data0[n] = to_send.front().data[n];
|
159 |
|
|
}
|
160 |
|
|
to_send.pop_front();
|
161 |
|
|
}
|
162 |
|
|
else cout << "ERROR : Side0 read and no packet to send" << endl;
|
163 |
|
|
}
|
164 |
|
|
|
165 |
|
|
//When sent packet is acked
|
166 |
|
|
if(csr_ack_ro1.read()){
|
167 |
|
|
//Packet left from side 1
|
168 |
|
|
side_pkt_sent = 1;
|
169 |
|
|
//Check that if the previous packet had data associated, that it was all sent
|
170 |
|
|
if(data_size1 != 0)
|
171 |
|
|
cout << "ERROR:Not all data sent side 1" << endl;
|
172 |
|
|
//Reset the data sent counter
|
173 |
|
|
data_sent1 = 0;
|
174 |
|
|
|
175 |
|
|
/**
|
176 |
|
|
Set the variables necessary to simulate the databuffer to send the data
|
177 |
|
|
associated with the packet sent.
|
178 |
|
|
|
179 |
|
|
Once the data is extracted, pop the packet from it's queue.
|
180 |
|
|
*/
|
181 |
|
|
if(!to_send1.empty()){
|
182 |
|
|
if(to_send1.front().pkt_cplt.packet->hasDataAssociated())
|
183 |
|
|
data_size1 = to_send1.front().pkt_cplt.packet->getDataLengthm1()+1;
|
184 |
|
|
data_address1 = to_send1.front().pkt_cplt.data_address;
|
185 |
|
|
data_vc1 = to_send1.front().pkt_cplt.packet->getVirtualChannel();
|
186 |
|
|
for(int n = 0; n < 16;n++){
|
187 |
|
|
data1[n] = to_send1.front().data[n];
|
188 |
|
|
}
|
189 |
|
|
to_send1.pop_front();
|
190 |
|
|
}
|
191 |
|
|
else if(!to_send.empty()){
|
192 |
|
|
if(to_send.front().pkt_cplt.packet->hasDataAssociated())
|
193 |
|
|
data_size1 = to_send.front().pkt_cplt.packet->getDataLengthm1()+1;
|
194 |
|
|
data_address1 = to_send.front().pkt_cplt.data_address;
|
195 |
|
|
data_vc1 = to_send.front().pkt_cplt.packet->getVirtualChannel();
|
196 |
|
|
for(int n = 0; n < 16;n++){
|
197 |
|
|
data1[n] = to_send.front().data[n];
|
198 |
|
|
}
|
199 |
|
|
to_send.pop_front();
|
200 |
|
|
}
|
201 |
|
|
else cout << "ERROR : Side1 read and no packet to send" << endl;
|
202 |
|
|
}
|
203 |
|
|
}
|
204 |
|
|
}
|
205 |
|
|
|
206 |
|
|
void csr_l2_tb::verify_csr_response(){
|
207 |
|
|
//No response dwords received yet
|
208 |
|
|
received0 = 0;
|
209 |
|
|
received1 = 0;
|
210 |
|
|
|
211 |
|
|
while(true){
|
212 |
|
|
wait();
|
213 |
|
|
|
214 |
|
|
//If response available for side 0
|
215 |
|
|
if(csr_available_fc0.read()){
|
216 |
|
|
//Check if it's from wrong side side
|
217 |
|
|
/** This can happen when sending data : in the case csr_ack_ro0 is zero and side_pkt_sent is 1
|
218 |
|
|
Or when receiving a new command packet from side 1*/
|
219 |
|
|
if(!csr_ack_ro0.read() && side_pkt_sent != 0 || csr_ack_ro1.read())
|
220 |
|
|
cout << "ERROR : Response not received on expected side : " << side_pkt_sent << endl;
|
221 |
|
|
//If data is consumed from flow control and we still have expected data from side 0
|
222 |
|
|
else if(!to_receive0.empty() && fc0_ack_csr.read()){
|
223 |
|
|
//Check that it is the right dword
|
224 |
|
|
if(to_receive0.front().dwords[received0] != sc_uint<32>(csr_dword_fc0.read())){
|
225 |
|
|
cout << "ERROR in dword received from CSR (side 0)" << endl;
|
226 |
|
|
cout << " received0: " << received0 << endl;
|
227 |
|
|
cout << " Expected " << sc_uint<32>(to_receive0.front().dwords[received0]).to_string(SC_HEX)
|
228 |
|
|
<< " Received " << csr_dword_fc0.read().to_string(SC_HEX) << endl;
|
229 |
|
|
}
|
230 |
|
|
|
231 |
|
|
//increment the number of dwords received
|
232 |
|
|
received0++;
|
233 |
|
|
//Remove the entry from the queue if the entry is finished
|
234 |
|
|
if(received0 == to_receive0.front().size_with_data){
|
235 |
|
|
received0 = 0;
|
236 |
|
|
to_receive0.pop_front();
|
237 |
|
|
}
|
238 |
|
|
}
|
239 |
|
|
//When all data from side0 has been receive, we then check if there is data that
|
240 |
|
|
//had any side as a destination
|
241 |
|
|
else if(!to_receive.empty() && fc0_ack_csr.read()){
|
242 |
|
|
//Check if it is the correct dword
|
243 |
|
|
if(to_receive.front().dwords[received0] != sc_uint<32>(csr_dword_fc0.read())){
|
244 |
|
|
cout << "ERROR in dword received from CSR (side 0)" << endl;
|
245 |
|
|
cout << " received0: " << received0 << endl;
|
246 |
|
|
cout << " Expected " << sc_uint<32>(to_receive.front().dwords[received0]).to_string(SC_HEX)
|
247 |
|
|
<< " Received " << csr_dword_fc0.read().to_string(SC_HEX) << endl;
|
248 |
|
|
}
|
249 |
|
|
|
250 |
|
|
//increment the number of dwords received
|
251 |
|
|
received0++;
|
252 |
|
|
//Remove the entry from the queue if the entry is finished
|
253 |
|
|
if(received0 == to_receive.front().size_with_data){
|
254 |
|
|
received0 = 0;
|
255 |
|
|
to_receive.pop_front();
|
256 |
|
|
}
|
257 |
|
|
}
|
258 |
|
|
//If no respionse expected and some received, display ERROR
|
259 |
|
|
else if(fc0_ack_csr.read())
|
260 |
|
|
cout << "CSR Response (side 0) not expected!" << endl;
|
261 |
|
|
}
|
262 |
|
|
|
263 |
|
|
//If response available for side 1
|
264 |
|
|
if(csr_available_fc1.read()){
|
265 |
|
|
//Check if it's from wrong side side
|
266 |
|
|
/** This can happen when sending data : in the case csr_ack_ro0 is zero and side_pkt_sent is 1
|
267 |
|
|
Or when receiving a new command packet from side 1*/
|
268 |
|
|
if(!csr_ack_ro1.read() && side_pkt_sent != 1 || csr_ack_ro0.read())
|
269 |
|
|
cout << "ERROR : Response not received on expected side : " << side_pkt_sent << endl;
|
270 |
|
|
//If data is consumed from flow control and we still have expected data from side 0
|
271 |
|
|
else if(!to_receive1.empty() && fc1_ack_csr.read()){
|
272 |
|
|
//Check that it is the right dword
|
273 |
|
|
if(to_receive1.front().dwords[received1] != sc_uint<32>(csr_dword_fc1.read())){
|
274 |
|
|
cout << "ERROR in dword received from CSR (side 1)" << endl;
|
275 |
|
|
cout << " received1: " << received1 << endl;
|
276 |
|
|
cout << " Expected " << sc_uint<32>(to_receive1.front().dwords[received1]).to_string(SC_HEX)
|
277 |
|
|
<< " Received " << csr_dword_fc1.read().to_string(SC_HEX) << endl;
|
278 |
|
|
}
|
279 |
|
|
//increment the number of dwords received
|
280 |
|
|
received1++;
|
281 |
|
|
//Remove the entry from the queue if the entry is finished
|
282 |
|
|
if(received1 == to_receive1.front().size_with_data){
|
283 |
|
|
received0 = 0;
|
284 |
|
|
to_receive1.pop_front();
|
285 |
|
|
}
|
286 |
|
|
}
|
287 |
|
|
//When all data from side0 has been receive, we then check if there is data that
|
288 |
|
|
//had any side as a destination
|
289 |
|
|
else if(!to_receive.empty() && fc1_ack_csr.read()){
|
290 |
|
|
//Check if it is the correct dword
|
291 |
|
|
if(to_receive.front().dwords[received1] != sc_uint<32>(csr_dword_fc1.read()))
|
292 |
|
|
cout << "ERROR in dword received from CSR (side 1)" << endl;
|
293 |
|
|
|
294 |
|
|
//increment the number of dwords received
|
295 |
|
|
received1++;
|
296 |
|
|
//Remove the entry from the queue if the entry is finished
|
297 |
|
|
if(received1 == to_receive.front().size_with_data){
|
298 |
|
|
received1 = 0;
|
299 |
|
|
to_receive.pop_front();
|
300 |
|
|
}
|
301 |
|
|
}
|
302 |
|
|
//If no respionse expected and some received, display ERROR
|
303 |
|
|
else if(fc1_ack_csr.read())
|
304 |
|
|
cout << "CSR Response (side 1) not expected!" << endl;
|
305 |
|
|
}
|
306 |
|
|
}
|
307 |
|
|
|
308 |
|
|
}
|
309 |
|
|
|
310 |
|
|
void csr_l2_tb::simulate_databuffer(){
|
311 |
|
|
data_sent0 = 0;
|
312 |
|
|
data_sent1 = 0;
|
313 |
|
|
data_size0 = 0;
|
314 |
|
|
data_size1 = 0;
|
315 |
|
|
valid_output0 = false;
|
316 |
|
|
valid_output1 = false;
|
317 |
|
|
|
318 |
|
|
bool expect_erase_after_read0 = false;
|
319 |
|
|
bool expect_erase_after_read1 = false;
|
320 |
|
|
|
321 |
|
|
while(true){
|
322 |
|
|
wait();
|
323 |
|
|
|
324 |
|
|
//If what is outputed from databuffer is valid data : false by default
|
325 |
|
|
valid_output0 = false;
|
326 |
|
|
|
327 |
|
|
if(csr_erase_db0.read() != expect_erase_after_read0){
|
328 |
|
|
cout << "ERROR: csr_erase_db0 asserted at wrong time" << endl;
|
329 |
|
|
}
|
330 |
|
|
//By default, don't expect the CSR to erase data packet
|
331 |
|
|
expect_erase_after_read0 = false;
|
332 |
|
|
|
333 |
|
|
//If reading data from side 0
|
334 |
|
|
if(csr_read_db0.read()){
|
335 |
|
|
//Check that there is data
|
336 |
|
|
if(data_size0 == 0)
|
337 |
|
|
cout << "ERROR : CSR reading databuffer while no data to send 0" << endl;
|
338 |
|
|
//If it was not valid output, display error
|
339 |
|
|
else if(!valid_output0.read())
|
340 |
|
|
cout << "ERROR : CSR reading invalid output 0" << endl;
|
341 |
|
|
//If done, reset the data position
|
342 |
|
|
else{
|
343 |
|
|
if(++data_sent0 == data_size0){
|
344 |
|
|
data_size0 = 0;
|
345 |
|
|
data_sent0 = 0;
|
346 |
|
|
expect_erase_after_read0 = true;
|
347 |
|
|
}
|
348 |
|
|
}
|
349 |
|
|
}
|
350 |
|
|
//If there is no data, output 0
|
351 |
|
|
if(data_size0 == 0){
|
352 |
|
|
db0_data_csr = 0;
|
353 |
|
|
}
|
354 |
|
|
//If address is correct, output data and set valid output
|
355 |
|
|
if((csr_address_db0.read() == data_address0 && csr_vctype_db0.read() == data_vc0 ||
|
356 |
|
|
data_sent0 > 0) && data_size0 != 0)
|
357 |
|
|
{
|
358 |
|
|
valid_output0 = true;
|
359 |
|
|
db0_data_csr = data0[data_sent0];
|
360 |
|
|
}
|
361 |
|
|
|
362 |
|
|
//Read from side 1
|
363 |
|
|
valid_output1 = false;
|
364 |
|
|
|
365 |
|
|
if(csr_erase_db1.read() != expect_erase_after_read1){
|
366 |
|
|
cout << "ERROR: csr_erase_db1 asserted at wrong time" << endl;
|
367 |
|
|
}
|
368 |
|
|
expect_erase_after_read1 = false;
|
369 |
|
|
|
370 |
|
|
//If reading data from side 1
|
371 |
|
|
if(csr_read_db1.read()){
|
372 |
|
|
//Check that there is data
|
373 |
|
|
if(data_size1 == 0)
|
374 |
|
|
cout << "ERROR : CSR reading databuffer while no data to send 1" << endl;
|
375 |
|
|
//If it was not valid output, display error
|
376 |
|
|
else if(!valid_output1.read())
|
377 |
|
|
cout << "ERROR : CSR reading invalid output 1" << endl;
|
378 |
|
|
//If done, reset the data position
|
379 |
|
|
else{
|
380 |
|
|
if(++data_sent1 == data_size1){
|
381 |
|
|
data_size1 = 0;
|
382 |
|
|
data_sent1 = 0;
|
383 |
|
|
expect_erase_after_read1 = true;
|
384 |
|
|
}
|
385 |
|
|
}
|
386 |
|
|
}
|
387 |
|
|
|
388 |
|
|
//If there is no data, output 0
|
389 |
|
|
if(data_size1 == 0){
|
390 |
|
|
db1_data_csr = 0;
|
391 |
|
|
}
|
392 |
|
|
//If address is correct, output data and set valid output
|
393 |
|
|
if((csr_address_db1.read() == data_address1 && csr_vctype_db1.read() == data_vc1 ||
|
394 |
|
|
data_sent1 > 0) && data_size1 != 0)
|
395 |
|
|
{
|
396 |
|
|
valid_output1 = true;
|
397 |
|
|
db1_data_csr = data1[data_sent1];
|
398 |
|
|
}
|
399 |
|
|
}
|
400 |
|
|
|
401 |
|
|
}
|
402 |
|
|
|
403 |
|
|
void csr_l2_tb::generate_csr_requests_and_responses(){
|
404 |
|
|
|
405 |
|
|
//A smart packet container
|
406 |
|
|
PacketContainer pkt;
|
407 |
|
|
PacketContainerWithData pkt_wdata;
|
408 |
|
|
ExpectedResponse response;
|
409 |
|
|
|
410 |
|
|
///////////////////////////////////////////////////
|
411 |
|
|
//Generate a read to a static position (RevisionID)
|
412 |
|
|
///////////////////////////////////////////////////
|
413 |
|
|
|
414 |
|
|
pkt_wdata.pkt_cplt.packet.takeControl(
|
415 |
|
|
new ReadPacket(0 /*seqID*/ ,0 /*unitID*/ ,0 /*srcTag*/ ,0 /*maskCount*/,
|
416 |
|
|
(sc_bv<38>)sc_uint<40>(0xFDFE000000005C).range(39,2) /*address*/ ,
|
417 |
|
|
true /*doubleWordDataLength*/ ,false /*passPW*/ ,
|
418 |
|
|
false /*responsePassPW*/ ,true /*memoryCoherent*/ ,
|
419 |
|
|
false /*compat*/ ,false /*isoc*/ ));
|
420 |
|
|
|
421 |
|
|
pkt_wdata.pkt_cplt.error64BitExtension = false;
|
422 |
|
|
pkt_wdata.pkt_cplt.data_address = 0;
|
423 |
|
|
pkt_wdata.pkt_cplt.isPartOfChain = false;
|
424 |
|
|
to_send0.push_back(pkt_wdata);
|
425 |
|
|
|
426 |
|
|
//Generate the expected response for comparison
|
427 |
|
|
pkt.takeControl(
|
428 |
|
|
new ReadResponsePacket(0 /*unitID*/ ,0 /*srcTag*/ ,0 /*rqUID*/ ,
|
429 |
|
|
|
430 |
|
|
false /*passPW*/ ,false /*isoc*/ ));
|
431 |
|
|
|
432 |
|
|
response.size_with_data = 2;
|
433 |
|
|
response.dwords[0] = sc_uint<32>((sc_bv<32>)pkt->getVector().range(31,0));
|
434 |
|
|
response.dwords[1] = sc_uint<32>(0x88406008);
|
435 |
|
|
to_receive0.push_back(response);
|
436 |
|
|
|
437 |
|
|
///////////////////////////////////////////////////
|
438 |
|
|
//Generate a write to the BARS - Posted
|
439 |
|
|
///////////////////////////////////////////////////
|
440 |
|
|
|
441 |
|
|
pkt_wdata.pkt_cplt.packet.takeControl(
|
442 |
|
|
new WritePacket(0 /*seqID*/ ,0 /*unitID*/ ,1 /*maskCount*/,
|
443 |
|
|
(sc_bv<38>)sc_uint<40>(0xFDFE0000000010).range(39,2) /*address*/ ,
|
444 |
|
|
true /*doubleWordDataLength*/ ,false /*passPW*/ ,
|
445 |
|
|
false /*dataError*/ ,false /*chain*/ ,true /*memoryCoherent*/ ,
|
446 |
|
|
false /*compat*/ ,false /*isoc*/ ));
|
447 |
|
|
|
448 |
|
|
pkt_wdata.pkt_cplt.error64BitExtension = false;
|
449 |
|
|
pkt_wdata.pkt_cplt.data_address = rand() % 16;
|
450 |
|
|
pkt_wdata.pkt_cplt.isPartOfChain = false;
|
451 |
|
|
pkt_wdata.data[0] = 0xFFFFFFFF;
|
452 |
|
|
pkt_wdata.data[1] = 0xF0F0F0F0;
|
453 |
|
|
to_send1.push_back(pkt_wdata);
|
454 |
|
|
|
455 |
|
|
///////////////////////////////////////////////////
|
456 |
|
|
//Generate a write to the BARS - Non Posted
|
457 |
|
|
///////////////////////////////////////////////////
|
458 |
|
|
/*WritePacket( const sc_bv<4> &seqID,
|
459 |
|
|
const sc_bv<5> &unitID,
|
460 |
|
|
const sc_bv<5> &srcTag,
|
461 |
|
|
const sc_bv<4> &maskCount,
|
462 |
|
|
const sc_bv<38> &address,
|
463 |
|
|
int doubleWordDataLength,
|
464 |
|
|
bool passPW = false,
|
465 |
|
|
bool memoryCoherent = true,
|
466 |
|
|
bool compat = false,
|
467 |
|
|
bool isoc = false) :*/
|
468 |
|
|
|
469 |
|
|
pkt_wdata.pkt_cplt.packet.takeControl(
|
470 |
|
|
new WritePacket(5 /*seqID*/ ,5 /*unitID*/ ,3 /*srcTag*/,1 /*maskCount*/,
|
471 |
|
|
(sc_bv<38>)sc_uint<40>(0xFDFE0000000018).range(39,2) /*address*/ ,
|
472 |
|
|
true /*doubleWordDataLength*/ ,false /*passPW*/ ,
|
473 |
|
|
true /*memoryCoherent*/ ,
|
474 |
|
|
false /*compat*/ ,false /*isoc*/ ));
|
475 |
|
|
pkt_wdata.pkt_cplt.data_address = rand() % 16;
|
476 |
|
|
to_send1.push_back(pkt_wdata);
|
477 |
|
|
|
478 |
|
|
//Generate the expected response for comparison
|
479 |
|
|
pkt.takeControl(
|
480 |
|
|
new TargetDonePacket(0 /*unitID*/,
|
481 |
|
|
3 /*srcTag*/,
|
482 |
|
|
1 /*rqUID*/,
|
483 |
|
|
false /*bridge*/,
|
484 |
|
|
RE_NORMAL /*error*/,
|
485 |
|
|
|
486 |
|
|
|
487 |
|
|
|
488 |
|
|
|
489 |
|
|
response.size_with_data = 1;
|
490 |
|
|
response.dwords[0] = sc_uint<32>((sc_bv<32>)pkt->getVector().range(31,0));
|
491 |
|
|
to_receive1.push_back(response);
|
492 |
|
|
|
493 |
|
|
|
494 |
|
|
///////////////////////////////////////////////////
|
495 |
|
|
//Read the BARS - Non Posted
|
496 |
|
|
///////////////////////////////////////////////////
|
497 |
|
|
|
498 |
|
|
pkt_wdata.pkt_cplt.packet.takeControl(
|
499 |
|
|
new ReadPacket(0 /*seqID*/ ,0 /*unitID*/ ,7 /*srcTag*/ ,3 /*maskCount*/,
|
500 |
|
|
(sc_bv<38>)sc_uint<40>(0xFDFE0000000010).range(39,2) /*address*/ ,
|
501 |
|
|
true /*doubleWordDataLength*/ ,false /*passPW*/ ,
|
502 |
|
|
false /*responsePassPW*/ ,true /*memoryCoherent*/ ,
|
503 |
|
|
false /*compat*/ ,false /*isoc*/ ));
|
504 |
|
|
|
505 |
|
|
pkt_wdata.pkt_cplt.error64BitExtension = false;
|
506 |
|
|
pkt_wdata.pkt_cplt.data_address = 0;
|
507 |
|
|
pkt_wdata.pkt_cplt.isPartOfChain = false;
|
508 |
|
|
to_send.push_back(pkt_wdata);
|
509 |
|
|
|
510 |
|
|
//Generate the expected response for comparison
|
511 |
|
|
pkt.takeControl(
|
512 |
|
|
new ReadResponsePacket(0 /*unitID*/ ,7 /*srcTag*/ ,0 /*rqUID*/ ,
|
513 |
|
|
3 /*count*/ ,false /*bridge*/ ,RE_NORMAL /*error*/ ,
|
514 |
|
|
false /*passPW*/ ,false /*isoc*/ ));
|
515 |
|
|
|
516 |
|
|
response.size_with_data = 5;
|
517 |
|
|
response.dwords[0] = sc_uint<32>((sc_bv<32>)pkt->getVector().range(31,0));
|
518 |
|
|
response.dwords[1] = sc_uint<32>(0xFFFFFC00);
|
519 |
|
|
response.dwords[2] = sc_uint<32>(0xF0F0F000);
|
520 |
|
|
response.dwords[3] = sc_uint<32>(0xFFFFFC00);
|
521 |
|
|
response.dwords[4] = sc_uint<32>(0xF0F0F000);
|
522 |
|
|
to_receive.push_back(response);
|
523 |
|
|
|
524 |
|
|
///////////////////////////////////////////
|
525 |
|
|
// Test Byte write
|
526 |
|
|
///////////////////////////////////////////
|
527 |
|
|
pkt_wdata.pkt_cplt.packet.takeControl(
|
528 |
|
|
new WritePacket(0 /*seqID*/ ,0 /*unitID*/ ,1 /*maskCount*/,
|
529 |
|
|
(sc_bv<38>)sc_uint<40>(0xFDFE0000000014).range(39,2) /*address*/ ,
|
530 |
|
|
false /*doubleWordDataLength*/ ,false /*passPW*/ ,
|
531 |
|
|
false /*dataError*/ ,false /*chain*/ ,true /*memoryCoherent*/ ,
|
532 |
|
|
false /*compat*/ ,false /*isoc*/ ));
|
533 |
|
|
|
534 |
|
|
pkt_wdata.pkt_cplt.error64BitExtension = false;
|
535 |
|
|
pkt_wdata.pkt_cplt.data_address = rand() % 16;
|
536 |
|
|
pkt_wdata.pkt_cplt.isPartOfChain = false;
|
537 |
|
|
pkt_wdata.data[0] = 0x00C00000;
|
538 |
|
|
pkt_wdata.data[1] = 0xCD0F0FF0;
|
539 |
|
|
to_send.push_back(pkt_wdata);
|
540 |
|
|
|
541 |
|
|
//Read where we wrote
|
542 |
|
|
pkt_wdata.pkt_cplt.packet.takeControl(
|
543 |
|
|
new ReadPacket(0 /*seqID*/ ,0 /*unitID*/ ,7 /*srcTag*/ ,0 /*maskCount*/,
|
544 |
|
|
(sc_bv<38>)sc_uint<40>(0xFDFE0000000014).range(39,2) /*address*/ ,
|
545 |
|
|
true /*doubleWordDataLength*/ ,false /*passPW*/ ,
|
546 |
|
|
false /*responsePassPW*/ ,true /*memoryCoherent*/ ,
|
547 |
|
|
false /*compat*/ ,false /*isoc*/ ));
|
548 |
|
|
|
549 |
|
|
pkt_wdata.pkt_cplt.error64BitExtension = false;
|
550 |
|
|
pkt_wdata.pkt_cplt.data_address = 0;
|
551 |
|
|
pkt_wdata.pkt_cplt.isPartOfChain = false;
|
552 |
|
|
to_send.push_back(pkt_wdata);
|
553 |
|
|
|
554 |
|
|
//Generate the expected response for comparison
|
555 |
|
|
pkt.takeControl(
|
556 |
|
|
new ReadResponsePacket(0 /*unitID*/ ,7 /*srcTag*/ ,0 /*rqUID*/ ,
|
557 |
|
|
|
558 |
|
|
false /*passPW*/ ,false /*isoc*/ ));
|
559 |
|
|
|
560 |
|
|
response.size_with_data = 5;
|
561 |
|
|
response.dwords[0] = sc_uint<32>((sc_bv<32>)pkt->getVector().range(31,0));
|
562 |
|
|
response.dwords[1] = sc_uint<32>(0xCD0FF000);
|
563 |
|
|
to_receive.push_back(response);
|
564 |
|
|
}
|
565 |
|
|
|
566 |
|
|
void csr_l2_tb::flow_control_read_signals(){
|
567 |
|
|
while(true){
|
568 |
|
|
//Randomly read when there is data available
|
569 |
|
|
bool read = (rand() % 10 < 9);
|
570 |
|
|
fc0_ack_csr = read && csr_available_fc0.read();
|
571 |
|
|
fc1_ack_csr = read && csr_available_fc1.read();
|
572 |
|
|
wait();
|
573 |
|
|
}
|
574 |
|
|
|
575 |
|
|
}
|
576 |
|
|
|
577 |
|
|
void csr_l2_tb::grant_access_databuffer(){
|
578 |
|
|
bool delay = false;
|
579 |
|
|
while(true){
|
580 |
|
|
//Randomly grant access, with a minimum delay of one cycle
|
581 |
|
|
bool grant = (rand() % 10 < 2) && delay;
|
582 |
|
|
//Delay the request until next cycke
|
583 |
|
|
delay = csr_request_databuffer0_access_ui.read() || csr_request_databuffer1_access_ui.read();
|
584 |
|
|
//Once access granted, keep it granted until request is done
|
585 |
|
|
if(csr_request_databuffer0_access_ui.read() || csr_request_databuffer1_access_ui.read())
|
586 |
|
|
ui_databuffer_access_granted_csr = ui_databuffer_access_granted_csr.read() || grant;
|
587 |
|
|
else
|
588 |
|
|
ui_databuffer_access_granted_csr = false;
|
589 |
|
|
wait();
|
590 |
|
|
}
|
591 |
|
|
}
|
592 |
|
|
|
593 |
|
|
|