18
18
from cocotb .triggers import ClockCycles , Combine , Event , RisingEdge , Timer , with_timeout
19
19
from cocotb_helpers import reset_n
20
20
21
+ from cocotbext .axi .constants import AxiBurstType
22
+
21
23
22
24
async def timeout_task (timeout ):
23
25
await Timer (timeout , "us" )
@@ -69,6 +71,8 @@ async def initialize(dut, timeout=50):
69
71
data_len = random .randint (10 , 100 )
70
72
test_data = [random .randint (0 , 2 ** 32 - 1 ) for _ in range (data_len )]
71
73
74
+ tb .log .info (f"Generated { data_len } dwords to transfer." )
75
+
72
76
return tb , data_len , test_data
73
77
74
78
@@ -78,12 +82,12 @@ async def test_collision_with_write(dut):
78
82
79
83
fifo_addr = tb .reg_map .I3C_EC .SECFWRECOVERYIF .INDIRECT_FIFO_DATA .base_addr
80
84
81
- tb .log .info (f"Generated { data_len } dwords to transfer." )
82
-
83
85
async def writer ():
84
86
# Write sequence should just write data
85
87
for d in test_data :
86
88
await tb .write_csr (fifo_addr , int2bytes (d ))
89
+ # Wait for read to finish to avoid multiple writes per read
90
+ await tb .axi_m .wait_read ()
87
91
88
92
async def reader (return_data ):
89
93
# Wait until there is data in FIFO
@@ -104,7 +108,7 @@ async def reader(return_data):
104
108
105
109
await Combine (w , r )
106
110
107
- assert received_data == test_data , "Recieved data does not match sent data!"
111
+ assert received_data == test_data , "Received data does not match sent data!"
108
112
109
113
tb .log .info ("Test finished!" )
110
114
@@ -115,16 +119,16 @@ async def test_collision_with_read(dut):
115
119
116
120
fifo_addr = tb .reg_map .I3C_EC .SECFWRECOVERYIF .INDIRECT_FIFO_DATA .base_addr
117
121
118
- tb .log .info (f"Generated { data_len } dwords to transfer." )
119
-
120
122
async def writer ():
121
123
# Write sequence should write data on each read data
122
124
for i , d in enumerate (test_data ):
123
125
# Awaiting read request causes writing simultaneously with read data channel activity
124
126
if i > 2 :
125
127
await RisingEdge (dut .s_cpuif_req )
126
128
assert not dut .s_cpuif_req_is_wr .value
127
- await tb .write_csr (fifo_addr , int2bytes (d ))
129
+ # Wait additional cycle to line up write with FIFO read delay
130
+ await RisingEdge (tb .clk )
131
+ await tb .write_csr (fifo_addr , int2dword (d ))
128
132
129
133
async def reader (return_data ):
130
134
# Wait until there is data in FIFO
@@ -134,6 +138,8 @@ async def reader(return_data):
134
138
135
139
# Read sequence should just read data
136
140
for _ in range (data_len ):
141
+ # Wait for write to finish to avoid multiple reads per write
142
+ await tb .axi_m .wait_write ()
137
143
return_data .append (dword2int (await tb .read_csr (fifo_addr )))
138
144
await RisingEdge (tb .clk )
139
145
@@ -143,26 +149,32 @@ async def reader(return_data):
143
149
144
150
await Combine (w , r )
145
151
146
- assert received_data == test_data , "Recieved data does not match sent data!"
152
+ assert received_data == test_data , "Received data does not match sent data!"
147
153
148
154
tb .log .info ("Test finished!" )
149
155
150
156
151
- @cocotb .test (skip = True )
152
- async def test_write_burst (dut ):
153
- tb = await initialize (dut )
157
+ @cocotb .test ()
158
+ async def test_write_read_burst (dut ):
159
+ tb , data_len , test_data = await initialize (dut )
154
160
161
+ fifo_addr = tb .reg_map .I3C_EC .SECFWRECOVERYIF .INDIRECT_FIFO_DATA .base_addr
155
162
156
- @cocotb .test (skip = True )
157
- async def test_read_burst (dut ):
158
- tb = await initialize (dut )
163
+ await with_timeout (tb .axi_m .write_dwords (fifo_addr , test_data , burst = AxiBurstType .FIXED ), 1 , "us" )
164
+ received_data = await with_timeout (tb .axi_m .read_dwords (fifo_addr , count = data_len , burst = AxiBurstType .FIXED ), 1 , "us" )
165
+
166
+ assert received_data == test_data , "Received data does not match sent data!"
159
167
160
168
161
169
@cocotb .test (skip = True )
162
170
async def test_read_burst_collision_with_write (dut ):
163
- tb = await initialize (dut )
171
+ tb , data_len , test_data = await initialize (dut )
172
+
173
+ fifo_addr = tb .reg_map .I3C_EC .SECFWRECOVERYIF .INDIRECT_FIFO_DATA .base_addr
164
174
165
175
166
176
@cocotb .test (skip = True )
167
177
async def test_write_burst_collision_with_read (dut ):
168
- tb = await initialize (dut )
178
+ tb , data_len , test_data = await initialize (dut )
179
+
180
+ fifo_addr = tb .reg_map .I3C_EC .SECFWRECOVERYIF .INDIRECT_FIFO_DATA .base_addr
0 commit comments