11
11
12
12
import cocotb
13
13
from cocotb .triggers import ClockCycles
14
+ from cocotb .regression import TestFactory
14
15
15
16
TGT_ADR = 0x5A
16
17
@@ -645,21 +646,32 @@ async def test_ccc_setmrl_bcast(dut):
645
646
assert mrl == int (sig )
646
647
647
648
648
- @cocotb .test ()
649
- async def test_ccc_rstact_direct (dut ):
650
- command = CCC .DIRECT .RSTACT
651
-
649
+ SUPPORTED_RESET_ACTIONS = [
650
+ I3cTargetResetAction .NO_RESET ,
651
+ I3cTargetResetAction .RESET_PERIPHERAL_ONLY ,
652
+ I3cTargetResetAction .RESET_WHOLE_TARGET ,
653
+ ]
654
+ async def test_ccc_rstact (dut , type , rstact ):
652
655
i3c_controller , _ , tb = await test_setup (dut )
653
656
await ClockCycles (tb .clk , 50 )
654
657
658
+ if type == "broadcast" :
659
+ command = CCC .BCAST .RSTACT
660
+ directed_data = None
661
+ reset_actions = rstact
662
+ elif type == "direct" :
663
+ command = CCC .DIRECT .RSTACT
664
+ directed_data = [(TGT_ADR , [])]
665
+ reset_actions = [(TGT_ADR , rstact )]
666
+ else :
667
+ assert False , "Unsupported RSTACT type, must be 'broadcast' or 'direct'"
668
+
655
669
# Send directed RSTACT
656
670
rst_action = 0xAA
657
671
await i3c_controller .i3c_ccc_write (
658
672
ccc = command ,
659
673
defining_byte = rst_action ,
660
- directed_data = [
661
- (TGT_ADR , []),
662
- ],
674
+ directed_data = directed_data ,
663
675
stop = False ,
664
676
)
665
677
@@ -671,35 +683,24 @@ async def test_ccc_rstact_direct(dut):
671
683
await i3c_controller .send_stop ()
672
684
673
685
# Start new frame and reset target with reset action set to peripheral reset
674
- await i3c_controller .target_reset (I3cTargetResetAction .RESET_PERIPHERAL_ONLY )
675
- assert dut .peripheral_reset_o == 1
676
- assert dut .escalated_reset_o == 0
677
- await ClockCycles (tb .clk , 50 )
678
-
679
-
680
- @cocotb .test ()
681
- async def test_ccc_rstact_bcast (dut ):
682
- command = CCC .BCAST .RSTACT
683
-
684
- i3c_controller , _ , tb = await test_setup (dut )
686
+ await i3c_controller .target_reset (reset_actions )
687
+ if rstact == I3cTargetResetAction .NO_RESET :
688
+ assert dut .peripheral_reset_o == 0
689
+ assert dut .escalated_reset_o == 0
690
+ elif rstact == I3cTargetResetAction .RESET_PERIPHERAL_ONLY :
691
+ assert dut .peripheral_reset_o == 1
692
+ assert dut .escalated_reset_o == 0
693
+ elif rstact == I3cTargetResetAction .RESET_WHOLE_TARGET :
694
+ assert dut .peripheral_reset_o == 0
695
+ assert dut .escalated_reset_o == 1
696
+ else :
697
+ assert False , f"Unsupported reset action ({ rstact } ), must be one of { SUPPORTED_RESET_ACTIONS } "
685
698
await ClockCycles (tb .clk , 50 )
686
699
687
- # Send broadcast RSTACT
688
- rst_action = 0xAA
689
- await i3c_controller .i3c_ccc_write (ccc = command , defining_byte = rst_action , stop = False )
690
-
691
- # Check if reset action got stored correctly in the logic after Target Reset Pattern
692
- sig = dut .xi3c_wrapper .i3c .xcontroller .xcontroller_standby .xcontroller_standby_i3c .rst_action_o
693
- assert int (sig ) == 0
694
- await i3c_controller .send_target_reset_pattern ()
695
- assert rst_action == int (sig )
696
- await i3c_controller .send_stop ()
697
-
698
- # Start new frame and reset target with reset action set to peripheral reset
699
- await i3c_controller .target_reset (I3cTargetResetAction .RESET_WHOLE_TARGET )
700
- assert dut .peripheral_reset_o == 0
701
- assert dut .escalated_reset_o == 1
702
- await ClockCycles (tb .clk , 50 )
700
+ rstact_tf = TestFactory (test_function = test_ccc_rstact )
701
+ rstact_tf .add_option (name = "rstact" , optionlist = SUPPORTED_RESET_ACTIONS )
702
+ rstact_tf .add_option (name = "type" , optionlist = ["broadcast" , "direct" ])
703
+ rstact_tf .generate_tests ()
703
704
704
705
705
706
@cocotb .test ()
0 commit comments