19
19
DYNAMIC_ADDR = 0x52
20
20
VIRT_DYNAMIC_ADDR = 0x53
21
21
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
+
22
33
23
34
async def timeout_task (timeout ):
24
35
await Timer (timeout , "us" )
@@ -517,16 +528,7 @@ async def test_read(dut):
517
528
def make_word (bs ):
518
529
return (bs [3 ] << 24 ) | (bs [2 ] << 16 ) | (bs [1 ] << 8 ) | bs [0 ]
519
530
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 + [
530
532
0x09 ,
531
533
0x0A ,
532
534
0x0B ,
@@ -615,18 +617,7 @@ async def test_read_short(dut):
615
617
def make_word (bs ):
616
618
return (bs [3 ] << 24 ) | (bs [2 ] << 16 ) | (bs [1 ] << 8 ) | bs [0 ]
617
619
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 )]
630
621
631
622
await tb .write_csr (
632
623
tb .reg_map .I3C_EC .SECFWRECOVERYIF .PROT_CAP_2 .base_addr ,
@@ -677,7 +668,7 @@ async def test_read_long(dut):
677
668
"""
678
669
679
670
# Initialize
680
- i3c_controller , i3c_target , tb , recovery = await initialize (dut )
671
+ i3c_controller , i3c_target , tb , recovery = await initialize (dut , timeout = 100 )
681
672
682
673
# set regular device dynamic address
683
674
await i3c_controller .i3c_ccc_write (
@@ -692,18 +683,7 @@ async def test_read_long(dut):
692
683
def make_word (bs ):
693
684
return (bs [3 ] << 24 ) | (bs [2 ] << 16 ) | (bs [1 ] << 8 ) | bs [0 ]
694
685
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 )]
707
687
708
688
await tb .write_csr (
709
689
tb .reg_map .I3C_EC .SECFWRECOVERYIF .PROT_CAP_2 .base_addr ,
@@ -742,6 +722,65 @@ def make_word(bs):
742
722
assert recovery_data == prot_cap [:15 ]
743
723
assert pec_ok
744
724
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
+
745
784
# Wait
746
785
await Timer (1 , "us" )
747
786
@@ -811,18 +850,7 @@ def make_word(bs):
811
850
# ..........
812
851
813
852
# 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 )]
826
854
827
855
await tb .write_csr (
828
856
tb .reg_map .I3C_EC .SECFWRECOVERYIF .PROT_CAP_2 .base_addr ,
0 commit comments