Skip to content

Commit 65a6517

Browse files
Adjust test to updated payload_available behavior
1 parent 6785ad1 commit 65a6517

File tree

1 file changed

+37
-25
lines changed

1 file changed

+37
-25
lines changed

verification/cocotb/top/lib_i3c_top/test_recovery.py

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from interface import I3CTopTestInterface
1313

1414
import cocotb
15-
from cocotb.triggers import ClockCycles, Combine, Event, Timer
15+
from cocotb.triggers import ClockCycles, Combine, Event, RisingEdge, Timer
1616

1717
STATIC_ADDR = 0x5A
1818
VIRT_STATIC_ADDR = 0x5B
@@ -959,10 +959,12 @@ async def test_payload_available(dut):
959959
chunks are written to INDIRECT_FIFO_DATA CSR.
960960
"""
961961

962-
payload_size = 16 # Bytes
963-
964962
# Initialize
965-
i3c_controller, i3c_target, tb, recovery = await initialize(dut, timeout=50)
963+
i3c_controller, i3c_target, tb, recovery = await initialize(dut, timeout=200)
964+
965+
fifo_size = dword2int(
966+
await tb.read_csr(tb.reg_map.I3C_EC.SECFWRECOVERYIF.INDIRECT_FIFO_STATUS_3.base_addr, 4)
967+
) * 4 # Multiply by 4 to get bytes from dwords
966968

967969
# set regular device dynamic address
968970
await i3c_controller.i3c_ccc_write(
@@ -981,42 +983,60 @@ async def test_payload_available(dut):
981983
), "Upon initialization payload_available should be deasserted"
982984

983985
# Generate random data payload. Write the payload to INDIRECT_FIFO_DATA
984-
payload_data = [random.randint(0, 0xFF) for i in range(payload_size)]
986+
payload_data = [random.randint(0, 0xFF) for i in range(fifo_size)]
985987
await recovery.command_write(
986-
VIRT_DYNAMIC_ADDR, I3cRecoveryInterface.Command.INDIRECT_FIFO_DATA, payload_data
988+
VIRT_DYNAMIC_ADDR, I3cRecoveryInterface.Command.INDIRECT_FIFO_DATA, payload_data[:-1]
987989
)
990+
assert not bool(
991+
payload_available.value
992+
), "After writing data without filling whole FIFO, payload_available should be deasserted"
988993

989-
# Wait
990-
await Timer(1, "us")
994+
await recovery.command_write(
995+
VIRT_DYNAMIC_ADDR, I3cRecoveryInterface.Command.INDIRECT_FIFO_DATA, [payload_data[-1]]
996+
)
991997

992998
# Check if payload_available is asserted
993999
assert bool(
9941000
payload_available.value
9951001
), "After reception of a complete write packet targeting INDIRECT_FIFO_DATA payload_available should be asserted"
9961002

997-
# Wait
998-
await Timer(100, "ns")
999-
10001003
# Read data from the indirect FIFO from the AXI side. payload_available should
10011004
# get deasserted only when the FIFO gets empty.
1002-
for i in range(payload_size // 4):
1003-
1005+
for _ in range(fifo_size // 4):
10041006
# Check the signal
10051007
assert bool(
10061008
payload_available.value
10071009
), "FIFO payload_available should not be deasserted until the indirect FIFO is not empty"
10081010

10091011
# Read & wait
10101012
await tb.read_csr(tb.reg_map.I3C_EC.SECFWRECOVERYIF.INDIRECT_FIFO_DATA.base_addr, 4)
1011-
await Timer(100, "ns")
1013+
await RisingEdge(tb.clk)
10121014

10131015
# Check the signal
10141016
assert not bool(
10151017
payload_available.value
10161018
), "After emptying indirect FIFO payload_available should be deasserted"
10171019

1018-
# Wait
1019-
await Timer(1, "us")
1020+
# Write one random byte to Indirect FIFO so it's not empty
1021+
await recovery.command_write(
1022+
VIRT_DYNAMIC_ADDR, I3cRecoveryInterface.Command.INDIRECT_FIFO_DATA, [random.randint(0, 255)]
1023+
)
1024+
1025+
# Activate an image to indicate transfer is done
1026+
await recovery.command_write(
1027+
VIRT_DYNAMIC_ADDR, I3cRecoveryInterface.Command.RECOVERY_CTRL, [0x0, 0x0, 0xF]
1028+
)
1029+
1030+
assert bool(
1031+
payload_available.value
1032+
), "After activating image, payload_available should be asserted"
1033+
1034+
await tb.read_csr(tb.reg_map.I3C_EC.SECFWRECOVERYIF.INDIRECT_FIFO_DATA.base_addr, 4)
1035+
await RisingEdge(tb.clk)
1036+
1037+
assert not bool(
1038+
payload_available.value
1039+
), "After reading FIFO, payload_available should be deasserted"
10201040

10211041

10221042
@cocotb.test()
@@ -1046,9 +1066,6 @@ async def test_image_activated(dut):
10461066
VIRT_DYNAMIC_ADDR, I3cRecoveryInterface.Command.RECOVERY_CTRL, [0x0, 0x0, 0xF]
10471067
)
10481068

1049-
# Wait
1050-
await Timer(1, "us")
1051-
10521069
# Check if image_activated is asserted
10531070
assert bool(
10541071
image_activated.value
@@ -1058,18 +1075,13 @@ async def test_image_activated(dut):
10581075
await tb.write_csr(
10591076
tb.reg_map.I3C_EC.SECFWRECOVERYIF.RECOVERY_CTRL.base_addr, int2dword(0xFF << 16), 4
10601077
)
1061-
1062-
# Wait
1063-
await Timer(100, "ns")
1078+
await RisingEdge(tb.clk)
10641079

10651080
# Check if image_activated is deasserted
10661081
assert not bool(
10671082
image_activated.value
10681083
), "Upon writing 0xFF to RECOVERY_CTRL byte 2 image_activated should be deasserted"
10691084

1070-
# Wait
1071-
await Timer(1, "us")
1072-
10731085

10741086
@cocotb.test()
10751087
async def test_indirect_fifo_reset_access(dut):

0 commit comments

Comments
 (0)