12
12
from interface import I3CTopTestInterface
13
13
14
14
import cocotb
15
- from cocotb .triggers import ClockCycles , Combine , Event , Timer
15
+ from cocotb .triggers import ClockCycles , Combine , Event , RisingEdge , Timer
16
16
17
17
STATIC_ADDR = 0x5A
18
18
VIRT_STATIC_ADDR = 0x5B
@@ -959,10 +959,12 @@ async def test_payload_available(dut):
959
959
chunks are written to INDIRECT_FIFO_DATA CSR.
960
960
"""
961
961
962
- payload_size = 16 # Bytes
963
-
964
962
# 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
966
968
967
969
# set regular device dynamic address
968
970
await i3c_controller .i3c_ccc_write (
@@ -981,42 +983,60 @@ async def test_payload_available(dut):
981
983
), "Upon initialization payload_available should be deasserted"
982
984
983
985
# 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 )]
985
987
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 ]
987
989
)
990
+ assert not bool (
991
+ payload_available .value
992
+ ), "After writing data without filling whole FIFO, payload_available should be deasserted"
988
993
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
+ )
991
997
992
998
# Check if payload_available is asserted
993
999
assert bool (
994
1000
payload_available .value
995
1001
), "After reception of a complete write packet targeting INDIRECT_FIFO_DATA payload_available should be asserted"
996
1002
997
- # Wait
998
- await Timer (100 , "ns" )
999
-
1000
1003
# Read data from the indirect FIFO from the AXI side. payload_available should
1001
1004
# get deasserted only when the FIFO gets empty.
1002
- for i in range (payload_size // 4 ):
1003
-
1005
+ for _ in range (fifo_size // 4 ):
1004
1006
# Check the signal
1005
1007
assert bool (
1006
1008
payload_available .value
1007
1009
), "FIFO payload_available should not be deasserted until the indirect FIFO is not empty"
1008
1010
1009
1011
# Read & wait
1010
1012
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 )
1012
1014
1013
1015
# Check the signal
1014
1016
assert not bool (
1015
1017
payload_available .value
1016
1018
), "After emptying indirect FIFO payload_available should be deasserted"
1017
1019
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"
1020
1040
1021
1041
1022
1042
@cocotb .test ()
@@ -1046,9 +1066,6 @@ async def test_image_activated(dut):
1046
1066
VIRT_DYNAMIC_ADDR , I3cRecoveryInterface .Command .RECOVERY_CTRL , [0x0 , 0x0 , 0xF ]
1047
1067
)
1048
1068
1049
- # Wait
1050
- await Timer (1 , "us" )
1051
-
1052
1069
# Check if image_activated is asserted
1053
1070
assert bool (
1054
1071
image_activated .value
@@ -1058,18 +1075,13 @@ async def test_image_activated(dut):
1058
1075
await tb .write_csr (
1059
1076
tb .reg_map .I3C_EC .SECFWRECOVERYIF .RECOVERY_CTRL .base_addr , int2dword (0xFF << 16 ), 4
1060
1077
)
1061
-
1062
- # Wait
1063
- await Timer (100 , "ns" )
1078
+ await RisingEdge (tb .clk )
1064
1079
1065
1080
# Check if image_activated is deasserted
1066
1081
assert not bool (
1067
1082
image_activated .value
1068
1083
), "Upon writing 0xFF to RECOVERY_CTRL byte 2 image_activated should be deasserted"
1069
1084
1070
- # Wait
1071
- await Timer (1 , "us" )
1072
-
1073
1085
1074
1086
@cocotb .test ()
1075
1087
async def test_indirect_fifo_reset_access (dut ):
0 commit comments