49async def SendReceiveSynchronizer_test(dut):
50 """Test SendReceiveSynchronizer module"""
51
52 global DEFAULT_CONFIGURATION_INITIALIZED_MEMORY_SIZE
53
54
55
56
57 assert LogicArray(dut.io_psOutInterrupt.value) == LogicArray("X")
58 assert LogicArray(dut.io_rdWrAddr.value) == LogicArray("XXXXXXXXXXXXX")
59 assert LogicArray(dut.io_wrEna.value) == LogicArray("X")
60 assert LogicArray(dut.io_wrData.value) == LogicArray("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
61 assert LogicArray(dut.io_requestedActionOfThePacketOutput.value) == LogicArray("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
62 assert LogicArray(dut.io_requestedActionOfThePacketOutputValid.value) == LogicArray("X")
63 assert LogicArray(dut.io_dataValidOutput.value) == LogicArray("X")
64 assert LogicArray(dut.io_receivingData.value) == LogicArray("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
65 assert LogicArray(dut.io_sendWaitForBuffer.value) == LogicArray("X")
66
67 clock = Clock(dut.clock, 10, units="ns")
68
69
70
71
72 cocotb.start_soon(clock.start(start_high=False))
73
74 dut._log.info("Initialize and reset module")
75
76
77
78
79 dut.io_en.value = 0
80 dut.io_beginSendingBuffer.value = 0
81 dut.io_noNewDataSender.value = 0
82 dut.io_dataValidInput.value = 0
83 dut.io_readNextData.value = 0
84 dut.io_noNewDataReceiver.value = 0
85 dut.io_plInSignal.value = 0
86 dut.io_requestedActionOfThePacketInput.value = 0
87 dut.io_requestedActionOfThePacketInput.value = 0
88
89
90
91
92 dut.reset.value = 1
93 for _ in range(10):
94 await Timer(10, units="ns")
95 dut.reset.value = 0
96
97 dut._log.info("Enabling chip")
98
99
100
101
102 dut.io_en.value = 1
103
104 for test_number in range(10):
105
106
111
112 dut._log.info("Enable receiving data on the chip (" + str(test_number) + ")")
113
114
115
116
117
118 dut.io_plInSignal.value = 1
119 await Timer(10, units="ns")
120 dut.io_plInSignal.value = 0
121
122
123
124
125 dut.io_beginSendingBuffer.value = 1
126 await Timer(10, units="ns")
127 dut.io_beginSendingBuffer.value = 0
128
129
130
131
132 for i in range(30):
133
134 match dut.io_rdWrAddr.value:
135
136
137
138
139 case 0x0:
140 dut.io_rdData.value = 0x00001234
141 case 0x8:
142 dut.io_rdData.value = 0x48595045
143 case 0x10:
144 dut.io_rdData.value = 0x4
145 case 0x14:
146 dut.io_rdData.value = 0x14141414
147 case 0x18:
148 dut.io_rdData.value = 0x18181818
149 case 0x1c:
150 dut.io_rdData.value = 0x1c1c1c1c
151 case 0x20:
152 dut.io_rdData.value = 0x20202020
153 case 0x24:
154 dut.io_rdData.value = 0x24242424
155 case 0x28:
156 dut.io_rdData.value = 0x28282828
157 case 0x2c:
158 dut.io_rdData.value = 0x2c2c2c2c
159 case 0x30:
160 dut.io_rdData.value = 0x30303030
161 case 0x34:
162 dut.io_rdData.value = 0x34343434
163 case 0x38:
164 dut.io_rdData.value = 0x38383838
165 case 0x3c:
166 dut.io_rdData.value = 0x3c3c3c3c
167 case 0x40:
168 dut.io_rdData.value = 0x40404040
169 case 0x44:
170 dut.io_rdData.value = 0x44444444
171 case 0x48:
172 dut.io_rdData.value = 0x48484848
173 case 0x4c:
174 dut.io_rdData.value = 0x4c4c4c4c
175 case 0x50:
176 dut.io_rdData.value = 0x50505050
177
178
179
180
181 case 0x1000:
182 dut.io_rdData.value = 0x10001000
183 case 0x1008:
184 dut.io_rdData.value = 0x48595045
185 case 0x100c:
186 dut.io_rdData.value = 0x100c100c
187 case 0x1010:
188 dut.io_rdData.value = 0x4
189 case 0x1014:
190 dut.io_rdData.value = 0x10141014
191 case 0x1018:
192 dut.io_rdData.value = 0x10181018
193 case 0x101c:
194 dut.io_rdData.value = 0x101c101c
195 case 0x1020:
196 dut.io_rdData.value = 0x10201020
197 case 0x1024:
198 dut.io_rdData.value = 0x10241024
199 case 0x1028:
200 dut.io_rdData.value = 0x10281028
201 case 0x102c:
202 dut.io_rdData.value = 0x102c102c
203 case 0x1030:
204 dut.io_rdData.value = 0x10301030
205 case 0x1034:
206 dut.io_rdData.value = 0x10341034
207 case 0x1038:
208 dut.io_rdData.value = 0x10381038
209 case 0x103c:
210 dut.io_rdData.value = 0x103c103c
211 case 0x1040:
212 dut.io_rdData.value = 0x10401040
213 case 0x1044:
214 dut.io_rdData.value = 0x10441044
215 case 0x1048:
216 dut.io_rdData.value = 0x10481048
217 case 0x104c:
218 dut.io_rdData.value = 0x104c104c
219 case 0x1050:
220 dut.io_rdData.value = 0x10501050
221 case _:
222 assert 1 == 2, "invalid address in the address line"
223
224 if dut.io_requestedActionOfThePacketOutputValid.value == 1:
225
226
227
228
229 if test_number % 3 == 0:
230 dut.io_noNewDataReceiver.value = 1
231 await Timer(10, units="ns")
232 dut.io_noNewDataReceiver.value = 0
233 else:
234
235
236
237
238 if dut.io_readNextData.value == 0:
239 dut.io_readNextData.value = 1
240 else:
241 dut.io_readNextData.value = 0
242
243
244
245
246 await Timer(10, units="ns")
247
248
249 if test_number % 3 != 0:
250 dut.io_noNewDataReceiver.value = 1
251 await Timer(10, units="ns")
252 dut.io_noNewDataReceiver.value = 0
253
254
255
256
257 for _ in range(10):
258 await Timer(10, units="ns")
259
260
265
266 dut._log.info("Enable sending data on the chip (" + str(test_number) + ")")
267
268
269
270
271 dut.io_noNewDataSender.value = 0
272 dut.io_beginSendingBuffer.value = 0
273
274
275
276
277
278 dut.io_beginSendingBuffer.value = 1
279 await Timer(10, units="ns")
280 dut.io_beginSendingBuffer.value = 0
281
282
283
284
285 dut.io_plInSignal.value = 1
286 await Timer(10, units="ns")
287 dut.io_plInSignal.value = 0
288
289
290
291
292 dut.io_dataValidInput.value = 0
293 dut.io_sendingData.value = 0
294
295
296
297
298 dut.io_requestedActionOfThePacketInput.value = 0x55859555
299
300
301
302
303 await Timer(10, units="ns")
304
305
306
307
308
309
310 if test_number % 3 != 0 :
311
312
313
314 for i in range(100):
315 if dut.io_sendWaitForBuffer.value == 1:
316 val = random.randint(0, 0xffffffff)
317
318
319
320
321 dut.io_dataValidInput.value = 1
322
323
324
325
326 dut.io_sendingData.value = val
327
328 await Timer(10, units="ns")
329
330
331
332
333 for i in range(100):
334 if dut.io_sendWaitForBuffer.value == 1:
335 dut.io_noNewDataSender.value = 1
336 await Timer(10, units="ns")
337 dut.io_noNewDataSender.value = 0
338 break
339
340 await Timer(10, units="ns")
341
342
343
344
345
346 for _ in range(10):
347 await Timer(10, units="ns")
348
349
350
351
352 await Timer(10, units="ns")