Skip to content

Commit ac6add6

Browse files
robertszczepanskikgugala
authored andcommitted
Add test for DEVICE_ID register
1 parent 2e8c0b0 commit ac6add6

File tree

1 file changed

+75
-47
lines changed

1 file changed

+75
-47
lines changed

verification/cocotb/top/lib_i3c_top/test_recovery.py

Lines changed: 75 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@
1919
DYNAMIC_ADDR = 0x52
2020
VIRT_DYNAMIC_ADDR = 0x53
2121

22+
ocp_magic_string_as_bytes = [
23+
0x4F, # 'O'
24+
0x43, # 'C'
25+
0x50, # 'P'
26+
0x20, # ' '
27+
0x52, # 'R'
28+
0x45, # 'E'
29+
0x43, # 'C'
30+
0x56, # 'V'
31+
]
32+
2233

2334
async def timeout_task(timeout):
2435
await Timer(timeout, "us")
@@ -517,16 +528,7 @@ async def test_read(dut):
517528
def make_word(bs):
518529
return (bs[3] << 24) | (bs[2] << 16) | (bs[1] << 8) | bs[0]
519530

520-
prot_cap = [
521-
# First 8 bytes is Recovery magic string "OCP RECV"
522-
0x4F, # 'O'
523-
0x43, # 'C'
524-
0x50, # 'P'
525-
0x20, # ' '
526-
0x52, # 'R'
527-
0x45, # 'E'
528-
0x43, # 'C'
529-
0x56, # 'V'
531+
prot_cap = ocp_magic_string_as_bytes + [
530532
0x09,
531533
0x0A,
532534
0x0B,
@@ -615,18 +617,7 @@ async def test_read_short(dut):
615617
def make_word(bs):
616618
return (bs[3] << 24) | (bs[2] << 16) | (bs[1] << 8) | bs[0]
617619

618-
prot_cap = [
619-
# First 8 bytes is Recovery magic string "OCP RECV"
620-
0x4F, # 'O'
621-
0x43, # 'C'
622-
0x50, # 'P'
623-
0x20, # ' '
624-
0x52, # 'R'
625-
0x45, # 'E'
626-
0x43, # 'C'
627-
0x56, # 'V'
628-
]
629-
prot_cap += [random.randint(0, 255) for i in range(8)]
620+
prot_cap = ocp_magic_string_as_bytes + [random.randint(0, 255) for i in range(8)]
630621

631622
await tb.write_csr(
632623
tb.reg_map.I3C_EC.SECFWRECOVERYIF.PROT_CAP_2.base_addr,
@@ -677,7 +668,7 @@ async def test_read_long(dut):
677668
"""
678669

679670
# Initialize
680-
i3c_controller, i3c_target, tb, recovery = await initialize(dut)
671+
i3c_controller, i3c_target, tb, recovery = await initialize(dut, timeout=100)
681672

682673
# set regular device dynamic address
683674
await i3c_controller.i3c_ccc_write(
@@ -692,18 +683,7 @@ async def test_read_long(dut):
692683
def make_word(bs):
693684
return (bs[3] << 24) | (bs[2] << 16) | (bs[1] << 8) | bs[0]
694685

695-
prot_cap = [
696-
# First 8 bytes is Recovery magic string "OCP RECV"
697-
0x4F, # 'O'
698-
0x43, # 'C'
699-
0x50, # 'P'
700-
0x20, # ' '
701-
0x52, # 'R'
702-
0x45, # 'E'
703-
0x43, # 'C'
704-
0x56, # 'V'
705-
]
706-
prot_cap += [random.randint(0, 255) for i in range(8)]
686+
prot_cap = ocp_magic_string_as_bytes + [random.randint(0, 255) for i in range(8)]
707687

708688
await tb.write_csr(
709689
tb.reg_map.I3C_EC.SECFWRECOVERYIF.PROT_CAP_2.base_addr,
@@ -742,6 +722,65 @@ def make_word(bs):
742722
assert recovery_data == prot_cap[:15]
743723
assert pec_ok
744724

725+
# Test DEVICE_ID register
726+
device_id = [random.randint(0, 255) for _ in range(24)]
727+
await tb.write_csr(
728+
tb.reg_map.I3C_EC.SECFWRECOVERYIF.DEVICE_ID_0.base_addr,
729+
int2dword(make_word(device_id[0:4])),
730+
4,
731+
)
732+
await tb.write_csr(
733+
tb.reg_map.I3C_EC.SECFWRECOVERYIF.DEVICE_ID_1.base_addr,
734+
int2dword(make_word(device_id[4:8])),
735+
4,
736+
)
737+
await tb.write_csr(
738+
tb.reg_map.I3C_EC.SECFWRECOVERYIF.DEVICE_ID_2.base_addr,
739+
int2dword(make_word(device_id[8:12])),
740+
4,
741+
)
742+
await tb.write_csr(
743+
tb.reg_map.I3C_EC.SECFWRECOVERYIF.DEVICE_ID_3.base_addr,
744+
int2dword(make_word(device_id[12:16])),
745+
4,
746+
)
747+
await tb.write_csr(
748+
tb.reg_map.I3C_EC.SECFWRECOVERYIF.DEVICE_ID_4.base_addr,
749+
int2dword(make_word(device_id[16:20])),
750+
4,
751+
)
752+
await tb.write_csr(
753+
tb.reg_map.I3C_EC.SECFWRECOVERYIF.DEVICE_ID_5.base_addr,
754+
int2dword(make_word(device_id[20:24])),
755+
4,
756+
)
757+
758+
# Wait
759+
await Timer(1, "us")
760+
761+
# Issue the recovery mode DEVICE_ID read command
762+
data = [I3cRecoveryInterface.Command.DEVICE_ID]
763+
data.append(recovery.pec_calc.checksum(bytes([VIRT_DYNAMIC_ADDR << 1] + data)))
764+
await i3c_controller.i3c_write(VIRT_DYNAMIC_ADDR, data, stop=False)
765+
766+
# Read the DEVICE_ID register using private read of fixed length which is
767+
# shorter than the register content + length + PEC
768+
data = await i3c_controller.i3c_read(VIRT_DYNAMIC_ADDR, 20)
769+
770+
# Wait
771+
await Timer(1, "us")
772+
773+
# Read PROT_CAP again, this time using the correct length
774+
recovery_data, pec_ok = await recovery.command_read(
775+
VIRT_DYNAMIC_ADDR, I3cRecoveryInterface.Command.DEVICE_ID
776+
)
777+
778+
# PROT_CAP read always returns 15 bytes
779+
assert recovery_data is not None
780+
assert len(recovery_data) == 24
781+
assert recovery_data == device_id[:24]
782+
assert pec_ok
783+
745784
# Wait
746785
await Timer(1, "us")
747786

@@ -811,18 +850,7 @@ def make_word(bs):
811850
# ..........
812851

813852
# Write some data to PROT_CAP CSR
814-
prot_cap = [
815-
# First 8 bytes is Recovery magic string "OCP RECV"
816-
0x4F, # 'O'
817-
0x43, # 'C'
818-
0x50, # 'P'
819-
0x20, # ' '
820-
0x52, # 'R'
821-
0x45, # 'E'
822-
0x43, # 'C'
823-
0x56, # 'V'
824-
]
825-
prot_cap += [random.randint(0, 255) for i in range(8)]
853+
prot_cap = ocp_magic_string_as_bytes + [random.randint(0, 255) for i in range(8)]
826854

827855
await tb.write_csr(
828856
tb.reg_map.I3C_EC.SECFWRECOVERYIF.PROT_CAP_2.base_addr,

0 commit comments

Comments
 (0)