lib: smf: constant number of arguments for SMF_CREATE_STATE()

This sets the number of arguments for SMF_CREATE_STATE() to always
be the same, independent of the selected Kconfig options.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
This commit is contained in:
Fin Maaß 2024-04-09 13:56:44 +02:00 committed by Carles Cufí
commit 7d83a8a68a
8 changed files with 115 additions and 99 deletions

View file

@ -47,12 +47,6 @@ The following macro can be used for easy state creation:
* :c:macro:`SMF_CREATE_STATE` Create a state * :c:macro:`SMF_CREATE_STATE` Create a state
.. note:: The :c:macro:`SMF_CREATE_STATE` macro takes an additional parameter
for the parent state when :kconfig:option:`CONFIG_SMF_ANCESTOR_SUPPORT` is
enabled . The :c:macro:`SMF_CREATE_STATE` macro takes two additional
parameters for the parent state and initial transition when the
:kconfig:option:`CONFIG_SMF_INITIAL_TRANSITION` option is enabled.
State Machine Creation State Machine Creation
====================== ======================
@ -62,9 +56,9 @@ enum. For example, the following creates three flat states::
enum demo_state { S0, S1, S2 }; enum demo_state { S0, S1, S2 };
const struct smf_state demo_states[] = { const struct smf_state demo_states[] = {
[S0] = SMF_CREATE_STATE(s0_entry, s0_run, s0_exit), [S0] = SMF_CREATE_STATE(s0_entry, s0_run, s0_exit, NULL, NULL),
[S1] = SMF_CREATE_STATE(s1_entry, s1_run, s1_exit), [S1] = SMF_CREATE_STATE(s1_entry, s1_run, s1_exit, NULL, NULL),
[S2] = SMF_CREATE_STATE(s2_entry, s2_run, s2_exit) [S2] = SMF_CREATE_STATE(s2_entry, s2_run, s2_exit, NULL, NULL)
}; };
And this example creates three hierarchical states:: And this example creates three hierarchical states::
@ -72,9 +66,9 @@ And this example creates three hierarchical states::
enum demo_state { S0, S1, S2 }; enum demo_state { S0, S1, S2 };
const struct smf_state demo_states[] = { const struct smf_state demo_states[] = {
[S0] = SMF_CREATE_STATE(s0_entry, s0_run, s0_exit, parent_s0), [S0] = SMF_CREATE_STATE(s0_entry, s0_run, s0_exit, parent_s0, NULL),
[S1] = SMF_CREATE_STATE(s1_entry, s1_run, s1_exit, parent_s12), [S1] = SMF_CREATE_STATE(s1_entry, s1_run, s1_exit, parent_s12, NULL),
[S2] = SMF_CREATE_STATE(s2_entry, s2_run, s2_exit, parent_s12) [S2] = SMF_CREATE_STATE(s2_entry, s2_run, s2_exit, parent_s12, NULL)
}; };
@ -211,11 +205,11 @@ Code::
/* Populate state table */ /* Populate state table */
static const struct smf_state demo_states[] = { static const struct smf_state demo_states[] = {
[S0] = SMF_CREATE_STATE(s0_entry, s0_run, s0_exit), [S0] = SMF_CREATE_STATE(s0_entry, s0_run, s0_exit, NULL, NULL),
/* State S1 does not have an entry action */ /* State S1 does not have an entry action */
[S1] = SMF_CREATE_STATE(NULL, s1_run, s1_exit), [S1] = SMF_CREATE_STATE(NULL, s1_run, s1_exit, NULL, NULL),
/* State S2 does not have an exit action */ /* State S2 does not have an exit action */
[S2] = SMF_CREATE_STATE(s2_entry, s2_run, NULL), [S2] = SMF_CREATE_STATE(s2_entry, s2_run, NULL, NULL, NULL),
}; };
int main(void) int main(void)
@ -314,12 +308,12 @@ Code::
/* Populate state table */ /* Populate state table */
static const struct smf_state demo_states[] = { static const struct smf_state demo_states[] = {
/* Parent state does not have a run action */ /* Parent state does not have a run action */
[PARENT] = SMF_CREATE_STATE(parent_entry, NULL, parent_exit, NULL), [PARENT] = SMF_CREATE_STATE(parent_entry, NULL, parent_exit, NULL, NULL),
/* Child states do not have entry or exit actions */ /* Child states do not have entry or exit actions */
[S0] = SMF_CREATE_STATE(NULL, s0_run, NULL, &demo_states[PARENT]), [S0] = SMF_CREATE_STATE(NULL, s0_run, NULL, &demo_states[PARENT], NULL),
[S1] = SMF_CREATE_STATE(NULL, s1_run, NULL, &demo_states[PARENT]), [S1] = SMF_CREATE_STATE(NULL, s1_run, NULL, &demo_states[PARENT], NULL),
/* State S2 do ot have entry or exit actions and no parent */ /* State S2 do ot have entry or exit actions and no parent */
[S2] = SMF_CREATE_STATE(NULL, s2_run, NULL, NULL), [S2] = SMF_CREATE_STATE(NULL, s2_run, NULL, NULL, NULL),
}; };
int main(void) int main(void)
@ -445,8 +439,8 @@ Code::
/* Populate state table */ /* Populate state table */
static const struct smf_state demo_states[] = { static const struct smf_state demo_states[] = {
[S0] = SMF_CREATE_STATE(s0_entry, s0_run, NULL), [S0] = SMF_CREATE_STATE(s0_entry, s0_run, NULL, NULL, NULL),
[S1] = SMF_CREATE_STATE(s1_entry, s1_run, NULL), [S1] = SMF_CREATE_STATE(s1_entry, s1_run, NULL, NULL, NULL),
}; };
void button_pressed(const struct device *dev, void button_pressed(const struct device *dev,

View file

@ -13,6 +13,8 @@
#ifndef ZEPHYR_INCLUDE_SMF_H_ #ifndef ZEPHYR_INCLUDE_SMF_H_
#define ZEPHYR_INCLUDE_SMF_H_ #define ZEPHYR_INCLUDE_SMF_H_
#include <zephyr/sys/util.h>
/** /**
* @brief State Machine Framework API * @brief State Machine Framework API
* @defgroup smf State Machine Framework API * @defgroup smf State Machine Framework API
@ -20,24 +22,6 @@
* @{ * @{
*/ */
#ifdef CONFIG_SMF_ANCESTOR_SUPPORT
/**
* @brief Macro to create a hierarchical state.
*
* @param _entry State entry function
* @param _run State run function
* @param _exit State exit function
* @param _parent State parent object or NULL
*/
#ifndef CONFIG_SMF_INITIAL_TRANSITION
#define SMF_CREATE_STATE(_entry, _run, _exit, _parent) \
{ \
.entry = _entry, \
.run = _run, \
.exit = _exit, \
.parent = _parent \
}
#else
/** /**
* @brief Macro to create a hierarchical state. * @brief Macro to create a hierarchical state.
* *
@ -47,33 +31,14 @@
* @param _parent State parent object or NULL * @param _parent State parent object or NULL
* @param _initial State initial transition object or NULL * @param _initial State initial transition object or NULL
*/ */
#define SMF_CREATE_STATE(_entry, _run, _exit, _parent, _initial) \ #define SMF_CREATE_STATE(_entry, _run, _exit, _parent, _initial) \
{ \ { \
.entry = _entry, \ .entry = _entry, \
.run = _run, \ .run = _run, \
.exit = _exit, \ .exit = _exit, \
.parent = _parent, \ IF_ENABLED(CONFIG_SMF_ANCESTOR_SUPPORT, (.parent = _parent,)) \
.initial = _initial \ IF_ENABLED(CONFIG_SMF_INITIAL_TRANSITION, (.initial = _initial,)) \
} }
#endif /* CONFIG_SMF_INITIAL_TRANSITION */
#else
/**
* @brief Macro to create a flat state.
*
* @param _entry State entry function
* @param _run State run function
* @param _exit State exit function
*/
#define SMF_CREATE_STATE(_entry, _run, _exit) \
{ \
.entry = _entry, \
.run = _run, \
.exit = _exit \
}
#endif /* CONFIG_SMF_ANCESTOR_SUPPORT */
/** /**
* @brief Macro to cast user defined object to state machine * @brief Macro to cast user defined object to state machine

View file

@ -1251,12 +1251,14 @@ static const struct smf_state pe_states[PE_STATE_COUNT] = {
NULL, NULL,
pe_sender_response_run, pe_sender_response_run,
pe_sender_response_exit, pe_sender_response_exit,
NULL,
NULL), NULL),
#ifdef CONFIG_USBC_CSM_SOURCE_ONLY #ifdef CONFIG_USBC_CSM_SOURCE_ONLY
[PE_SRC_HARD_RESET_PARENT] = SMF_CREATE_STATE( [PE_SRC_HARD_RESET_PARENT] = SMF_CREATE_STATE(
pe_src_hard_reset_parent_entry, pe_src_hard_reset_parent_entry,
pe_src_hard_reset_parent_run, pe_src_hard_reset_parent_run,
pe_src_hard_reset_parent_exit, pe_src_hard_reset_parent_exit,
NULL,
NULL), NULL),
#endif #endif
#ifdef CONFIG_USBC_CSM_SINK_ONLY #ifdef CONFIG_USBC_CSM_SINK_ONLY
@ -1264,148 +1266,177 @@ static const struct smf_state pe_states[PE_STATE_COUNT] = {
pe_snk_startup_entry, pe_snk_startup_entry,
pe_snk_startup_run, pe_snk_startup_run,
NULL, NULL,
NULL,
NULL), NULL),
[PE_SNK_DISCOVERY] = SMF_CREATE_STATE( [PE_SNK_DISCOVERY] = SMF_CREATE_STATE(
pe_snk_discovery_entry, pe_snk_discovery_entry,
pe_snk_discovery_run, pe_snk_discovery_run,
NULL, NULL,
NULL,
NULL), NULL),
[PE_SNK_WAIT_FOR_CAPABILITIES] = SMF_CREATE_STATE( [PE_SNK_WAIT_FOR_CAPABILITIES] = SMF_CREATE_STATE(
pe_snk_wait_for_capabilities_entry, pe_snk_wait_for_capabilities_entry,
pe_snk_wait_for_capabilities_run, pe_snk_wait_for_capabilities_run,
pe_snk_wait_for_capabilities_exit, pe_snk_wait_for_capabilities_exit,
NULL,
NULL), NULL),
[PE_SNK_EVALUATE_CAPABILITY] = SMF_CREATE_STATE( [PE_SNK_EVALUATE_CAPABILITY] = SMF_CREATE_STATE(
pe_snk_evaluate_capability_entry, pe_snk_evaluate_capability_entry,
NULL, NULL,
NULL, NULL,
NULL,
NULL), NULL),
[PE_SNK_SELECT_CAPABILITY] = SMF_CREATE_STATE( [PE_SNK_SELECT_CAPABILITY] = SMF_CREATE_STATE(
pe_snk_select_capability_entry, pe_snk_select_capability_entry,
pe_snk_select_capability_run, pe_snk_select_capability_run,
NULL, NULL,
&pe_states[PE_SENDER_RESPONSE_PARENT]), &pe_states[PE_SENDER_RESPONSE_PARENT],
NULL),
[PE_SNK_READY] = SMF_CREATE_STATE( [PE_SNK_READY] = SMF_CREATE_STATE(
pe_snk_ready_entry, pe_snk_ready_entry,
pe_snk_ready_run, pe_snk_ready_run,
pe_snk_ready_exit, pe_snk_ready_exit,
NULL,
NULL), NULL),
[PE_SNK_HARD_RESET] = SMF_CREATE_STATE( [PE_SNK_HARD_RESET] = SMF_CREATE_STATE(
pe_snk_hard_reset_entry, pe_snk_hard_reset_entry,
pe_snk_hard_reset_run, pe_snk_hard_reset_run,
NULL, NULL,
NULL,
NULL), NULL),
[PE_SNK_TRANSITION_TO_DEFAULT] = SMF_CREATE_STATE( [PE_SNK_TRANSITION_TO_DEFAULT] = SMF_CREATE_STATE(
pe_snk_transition_to_default_entry, pe_snk_transition_to_default_entry,
pe_snk_transition_to_default_run, pe_snk_transition_to_default_run,
NULL, NULL,
NULL,
NULL), NULL),
[PE_SNK_GIVE_SINK_CAP] = SMF_CREATE_STATE( [PE_SNK_GIVE_SINK_CAP] = SMF_CREATE_STATE(
pe_snk_give_sink_cap_entry, pe_snk_give_sink_cap_entry,
pe_snk_give_sink_cap_run, pe_snk_give_sink_cap_run,
NULL, NULL,
NULL,
NULL), NULL),
[PE_SNK_GET_SOURCE_CAP] = SMF_CREATE_STATE( [PE_SNK_GET_SOURCE_CAP] = SMF_CREATE_STATE(
pe_snk_get_source_cap_entry, pe_snk_get_source_cap_entry,
pe_snk_get_source_cap_run, pe_snk_get_source_cap_run,
NULL, NULL,
&pe_states[PE_SENDER_RESPONSE_PARENT]), &pe_states[PE_SENDER_RESPONSE_PARENT],
NULL),
[PE_SNK_TRANSITION_SINK] = SMF_CREATE_STATE( [PE_SNK_TRANSITION_SINK] = SMF_CREATE_STATE(
pe_snk_transition_sink_entry, pe_snk_transition_sink_entry,
pe_snk_transition_sink_run, pe_snk_transition_sink_run,
pe_snk_transition_sink_exit, pe_snk_transition_sink_exit,
NULL,
NULL), NULL),
#else #else
[PE_SRC_STARTUP] = SMF_CREATE_STATE( [PE_SRC_STARTUP] = SMF_CREATE_STATE(
pe_src_startup_entry, pe_src_startup_entry,
pe_src_startup_run, pe_src_startup_run,
NULL, NULL,
NULL,
NULL), NULL),
[PE_SRC_DISCOVERY] = SMF_CREATE_STATE( [PE_SRC_DISCOVERY] = SMF_CREATE_STATE(
pe_src_discovery_entry, pe_src_discovery_entry,
pe_src_discovery_run, pe_src_discovery_run,
pe_src_discovery_exit, pe_src_discovery_exit,
&pe_states[PE_SENDER_RESPONSE_PARENT]), &pe_states[PE_SENDER_RESPONSE_PARENT],
NULL),
[PE_SRC_SEND_CAPABILITIES] = SMF_CREATE_STATE( [PE_SRC_SEND_CAPABILITIES] = SMF_CREATE_STATE(
pe_src_send_capabilities_entry, pe_src_send_capabilities_entry,
pe_src_send_capabilities_run, pe_src_send_capabilities_run,
NULL, NULL,
&pe_states[PE_SENDER_RESPONSE_PARENT]), &pe_states[PE_SENDER_RESPONSE_PARENT],
NULL),
[PE_SRC_NEGOTIATE_CAPABILITY] = SMF_CREATE_STATE( [PE_SRC_NEGOTIATE_CAPABILITY] = SMF_CREATE_STATE(
pe_src_negotiate_capability_entry, pe_src_negotiate_capability_entry,
NULL, NULL,
NULL, NULL,
NULL,
NULL), NULL),
[PE_SRC_CAPABILITY_RESPONSE] = SMF_CREATE_STATE( [PE_SRC_CAPABILITY_RESPONSE] = SMF_CREATE_STATE(
pe_src_capability_response_entry, pe_src_capability_response_entry,
pe_src_capability_response_run, pe_src_capability_response_run,
NULL, NULL,
NULL,
NULL), NULL),
[PE_SRC_TRANSITION_SUPPLY] = SMF_CREATE_STATE( [PE_SRC_TRANSITION_SUPPLY] = SMF_CREATE_STATE(
pe_src_transition_supply_entry, pe_src_transition_supply_entry,
pe_src_transition_supply_run, pe_src_transition_supply_run,
pe_src_transition_supply_exit, pe_src_transition_supply_exit,
NULL,
NULL), NULL),
[PE_SRC_READY] = SMF_CREATE_STATE( [PE_SRC_READY] = SMF_CREATE_STATE(
pe_src_ready_entry, pe_src_ready_entry,
pe_src_ready_run, pe_src_ready_run,
pe_src_ready_exit, pe_src_ready_exit,
NULL,
NULL), NULL),
[PE_SRC_TRANSITION_TO_DEFAULT] = SMF_CREATE_STATE( [PE_SRC_TRANSITION_TO_DEFAULT] = SMF_CREATE_STATE(
pe_src_transition_to_default_entry, pe_src_transition_to_default_entry,
pe_src_transition_to_default_run, pe_src_transition_to_default_run,
pe_src_transition_to_default_exit, pe_src_transition_to_default_exit,
NULL,
NULL), NULL),
[PE_SRC_HARD_RESET_RECEIVED] = SMF_CREATE_STATE( [PE_SRC_HARD_RESET_RECEIVED] = SMF_CREATE_STATE(
NULL, NULL,
NULL, NULL,
NULL, NULL,
&pe_states[PE_SRC_HARD_RESET_PARENT]), &pe_states[PE_SRC_HARD_RESET_PARENT],
NULL),
[PE_SRC_HARD_RESET] = SMF_CREATE_STATE( [PE_SRC_HARD_RESET] = SMF_CREATE_STATE(
pe_src_hard_reset_entry, pe_src_hard_reset_entry,
NULL, NULL,
NULL, NULL,
&pe_states[PE_SRC_HARD_RESET_PARENT]), &pe_states[PE_SRC_HARD_RESET_PARENT],
NULL),
#endif #endif
[PE_GET_SINK_CAP] = SMF_CREATE_STATE( [PE_GET_SINK_CAP] = SMF_CREATE_STATE(
pe_get_sink_cap_entry, pe_get_sink_cap_entry,
pe_get_sink_cap_run, pe_get_sink_cap_run,
NULL, NULL,
&pe_states[PE_SENDER_RESPONSE_PARENT]), &pe_states[PE_SENDER_RESPONSE_PARENT],
NULL),
[PE_SEND_SOFT_RESET] = SMF_CREATE_STATE( [PE_SEND_SOFT_RESET] = SMF_CREATE_STATE(
pe_send_soft_reset_entry, pe_send_soft_reset_entry,
pe_send_soft_reset_run, pe_send_soft_reset_run,
NULL, NULL,
&pe_states[PE_SENDER_RESPONSE_PARENT]), &pe_states[PE_SENDER_RESPONSE_PARENT],
NULL),
[PE_SOFT_RESET] = SMF_CREATE_STATE( [PE_SOFT_RESET] = SMF_CREATE_STATE(
pe_soft_reset_entry, pe_soft_reset_entry,
pe_soft_reset_run, pe_soft_reset_run,
NULL, NULL,
NULL,
NULL), NULL),
[PE_SEND_NOT_SUPPORTED] = SMF_CREATE_STATE( [PE_SEND_NOT_SUPPORTED] = SMF_CREATE_STATE(
pe_send_not_supported_entry, pe_send_not_supported_entry,
pe_send_not_supported_run, pe_send_not_supported_run,
NULL, NULL,
NULL,
NULL), NULL),
[PE_DRS_EVALUATE_SWAP] = SMF_CREATE_STATE( [PE_DRS_EVALUATE_SWAP] = SMF_CREATE_STATE(
pe_drs_evaluate_swap_entry, pe_drs_evaluate_swap_entry,
pe_drs_evaluate_swap_run, pe_drs_evaluate_swap_run,
NULL, NULL,
NULL,
NULL), NULL),
[PE_DRS_SEND_SWAP] = SMF_CREATE_STATE( [PE_DRS_SEND_SWAP] = SMF_CREATE_STATE(
pe_drs_send_swap_entry, pe_drs_send_swap_entry,
pe_drs_send_swap_run, pe_drs_send_swap_run,
NULL, NULL,
&pe_states[PE_SENDER_RESPONSE_PARENT]), &pe_states[PE_SENDER_RESPONSE_PARENT],
NULL),
[PE_CHUNK_RECEIVED] = SMF_CREATE_STATE( [PE_CHUNK_RECEIVED] = SMF_CREATE_STATE(
pe_chunk_received_entry, pe_chunk_received_entry,
pe_chunk_received_run, pe_chunk_received_run,
NULL, NULL,
NULL,
NULL), NULL),
[PE_SUSPEND] = SMF_CREATE_STATE( [PE_SUSPEND] = SMF_CREATE_STATE(
pe_suspend_entry, pe_suspend_entry,
pe_suspend_run, pe_suspend_run,
NULL, NULL,
NULL,
NULL), NULL),
}; };
BUILD_ASSERT(ARRAY_SIZE(pe_states) == PE_STATE_COUNT); BUILD_ASSERT(ARRAY_SIZE(pe_states) == PE_STATE_COUNT);

View file

@ -1265,37 +1265,44 @@ static const struct smf_state prl_tx_states[PRL_TX_STATE_COUNT] = {
prl_tx_phy_layer_reset_entry, prl_tx_phy_layer_reset_entry,
NULL, NULL,
NULL, NULL,
NULL,
NULL), NULL),
[PRL_TX_WAIT_FOR_MESSAGE_REQUEST] = SMF_CREATE_STATE( [PRL_TX_WAIT_FOR_MESSAGE_REQUEST] = SMF_CREATE_STATE(
prl_tx_wait_for_message_request_entry, prl_tx_wait_for_message_request_entry,
prl_tx_wait_for_message_request_run, prl_tx_wait_for_message_request_run,
NULL, NULL,
NULL,
NULL), NULL),
[PRL_TX_LAYER_RESET_FOR_TRANSMIT] = SMF_CREATE_STATE( [PRL_TX_LAYER_RESET_FOR_TRANSMIT] = SMF_CREATE_STATE(
prl_tx_layer_reset_for_transmit_entry, prl_tx_layer_reset_for_transmit_entry,
NULL, NULL,
NULL, NULL,
NULL,
NULL), NULL),
[PRL_TX_WAIT_FOR_PHY_RESPONSE] = SMF_CREATE_STATE( [PRL_TX_WAIT_FOR_PHY_RESPONSE] = SMF_CREATE_STATE(
prl_tx_wait_for_phy_response_entry, prl_tx_wait_for_phy_response_entry,
prl_tx_wait_for_phy_response_run, prl_tx_wait_for_phy_response_run,
prl_tx_wait_for_phy_response_exit, prl_tx_wait_for_phy_response_exit,
NULL,
NULL), NULL),
[PRL_TX_SUSPEND] = SMF_CREATE_STATE( [PRL_TX_SUSPEND] = SMF_CREATE_STATE(
prl_tx_suspend_entry, prl_tx_suspend_entry,
prl_tx_suspend_run, prl_tx_suspend_run,
NULL, NULL,
NULL,
NULL), NULL),
#ifdef CONFIG_USBC_CSM_SINK_ONLY #ifdef CONFIG_USBC_CSM_SINK_ONLY
[PRL_TX_SNK_START_AMS] = SMF_CREATE_STATE( [PRL_TX_SNK_START_AMS] = SMF_CREATE_STATE(
prl_tx_snk_start_ams_entry, prl_tx_snk_start_ams_entry,
prl_tx_snk_start_ams_run, prl_tx_snk_start_ams_run,
NULL, NULL,
NULL,
NULL), NULL),
[PRL_TX_SNK_PENDING] = SMF_CREATE_STATE( [PRL_TX_SNK_PENDING] = SMF_CREATE_STATE(
prl_tx_snk_pending_entry, prl_tx_snk_pending_entry,
prl_tx_snk_pending_run, prl_tx_snk_pending_run,
NULL, NULL,
NULL,
NULL), NULL),
#endif #endif
#ifdef CONFIG_USBC_CSM_SOURCE_ONLY #ifdef CONFIG_USBC_CSM_SOURCE_ONLY
@ -1303,11 +1310,13 @@ static const struct smf_state prl_tx_states[PRL_TX_STATE_COUNT] = {
prl_tx_src_source_tx_entry, prl_tx_src_source_tx_entry,
prl_tx_src_source_tx_run, prl_tx_src_source_tx_run,
NULL, NULL,
NULL,
NULL), NULL),
[PRL_TX_SRC_PENDING] = SMF_CREATE_STATE( [PRL_TX_SRC_PENDING] = SMF_CREATE_STATE(
prl_tx_src_pending_entry, prl_tx_src_pending_entry,
prl_tx_src_pending_run, prl_tx_src_pending_run,
prl_tx_src_pending_exit, prl_tx_src_pending_exit,
NULL,
NULL), NULL),
#endif #endif
}; };
@ -1321,26 +1330,31 @@ static const struct smf_state prl_hr_states[PRL_HR_STATE_COUNT] = {
prl_hr_wait_for_request_entry, prl_hr_wait_for_request_entry,
prl_hr_wait_for_request_run, prl_hr_wait_for_request_run,
NULL, NULL,
NULL,
NULL), NULL),
[PRL_HR_RESET_LAYER] = SMF_CREATE_STATE( [PRL_HR_RESET_LAYER] = SMF_CREATE_STATE(
prl_hr_reset_layer_entry, prl_hr_reset_layer_entry,
NULL, NULL,
NULL, NULL,
NULL,
NULL), NULL),
[PRL_HR_WAIT_FOR_PHY_HARD_RESET_COMPLETE] = SMF_CREATE_STATE( [PRL_HR_WAIT_FOR_PHY_HARD_RESET_COMPLETE] = SMF_CREATE_STATE(
prl_hr_wait_for_phy_hard_reset_complete_entry, prl_hr_wait_for_phy_hard_reset_complete_entry,
prl_hr_wait_for_phy_hard_reset_complete_run, prl_hr_wait_for_phy_hard_reset_complete_run,
prl_hr_wait_for_phy_hard_reset_complete_exit, prl_hr_wait_for_phy_hard_reset_complete_exit,
NULL,
NULL), NULL),
[PRL_HR_WAIT_FOR_PE_HARD_RESET_COMPLETE] = SMF_CREATE_STATE( [PRL_HR_WAIT_FOR_PE_HARD_RESET_COMPLETE] = SMF_CREATE_STATE(
prl_hr_wait_for_pe_hard_reset_complete_entry, prl_hr_wait_for_pe_hard_reset_complete_entry,
prl_hr_wait_for_pe_hard_reset_complete_run, prl_hr_wait_for_pe_hard_reset_complete_run,
NULL, NULL,
NULL,
NULL), NULL),
[PRL_HR_SUSPEND] = SMF_CREATE_STATE( [PRL_HR_SUSPEND] = SMF_CREATE_STATE(
prl_hr_suspend_entry, prl_hr_suspend_entry,
prl_hr_suspend_run, prl_hr_suspend_run,
NULL, NULL,
NULL,
NULL), NULL),
}; };
BUILD_ASSERT(ARRAY_SIZE(prl_hr_states) == PRL_HR_STATE_COUNT); BUILD_ASSERT(ARRAY_SIZE(prl_hr_states) == PRL_HR_STATE_COUNT);

View file

@ -326,18 +326,21 @@ static const struct smf_state tc_states[TC_STATE_COUNT] = {
tc_cc_open_entry, tc_cc_open_entry,
NULL, NULL,
NULL, NULL,
NULL,
NULL), NULL),
#ifdef CONFIG_USBC_CSM_SINK_ONLY #ifdef CONFIG_USBC_CSM_SINK_ONLY
[TC_CC_RD_SUPER_STATE] = SMF_CREATE_STATE( [TC_CC_RD_SUPER_STATE] = SMF_CREATE_STATE(
tc_cc_rd_entry, tc_cc_rd_entry,
NULL, NULL,
NULL, NULL,
NULL,
NULL), NULL),
#else #else
[TC_CC_RP_SUPER_STATE] = SMF_CREATE_STATE( [TC_CC_RP_SUPER_STATE] = SMF_CREATE_STATE(
tc_cc_rp_entry, tc_cc_rp_entry,
NULL, NULL,
NULL, NULL,
NULL,
NULL), NULL),
#endif #endif
/* Normal States */ /* Normal States */
@ -346,48 +349,57 @@ static const struct smf_state tc_states[TC_STATE_COUNT] = {
tc_unattached_snk_entry, tc_unattached_snk_entry,
tc_unattached_snk_run, tc_unattached_snk_run,
NULL, NULL,
&tc_states[TC_CC_RD_SUPER_STATE]), &tc_states[TC_CC_RD_SUPER_STATE],
NULL),
[TC_ATTACH_WAIT_SNK_STATE] = SMF_CREATE_STATE( [TC_ATTACH_WAIT_SNK_STATE] = SMF_CREATE_STATE(
tc_attach_wait_snk_entry, tc_attach_wait_snk_entry,
tc_attach_wait_snk_run, tc_attach_wait_snk_run,
tc_attach_wait_snk_exit, tc_attach_wait_snk_exit,
&tc_states[TC_CC_RD_SUPER_STATE]), &tc_states[TC_CC_RD_SUPER_STATE],
NULL),
[TC_ATTACHED_SNK_STATE] = SMF_CREATE_STATE( [TC_ATTACHED_SNK_STATE] = SMF_CREATE_STATE(
tc_attached_snk_entry, tc_attached_snk_entry,
tc_attached_snk_run, tc_attached_snk_run,
tc_attached_snk_exit, tc_attached_snk_exit,
NULL,
NULL), NULL),
#else #else
[TC_UNATTACHED_SRC_STATE] = SMF_CREATE_STATE( [TC_UNATTACHED_SRC_STATE] = SMF_CREATE_STATE(
tc_unattached_src_entry, tc_unattached_src_entry,
tc_unattached_src_run, tc_unattached_src_run,
NULL, NULL,
&tc_states[TC_CC_RP_SUPER_STATE]), &tc_states[TC_CC_RP_SUPER_STATE],
NULL),
[TC_UNATTACHED_WAIT_SRC_STATE] = SMF_CREATE_STATE( [TC_UNATTACHED_WAIT_SRC_STATE] = SMF_CREATE_STATE(
tc_unattached_wait_src_entry, tc_unattached_wait_src_entry,
tc_unattached_wait_src_run, tc_unattached_wait_src_run,
tc_unattached_wait_src_exit, tc_unattached_wait_src_exit,
NULL,
NULL), NULL),
[TC_ATTACH_WAIT_SRC_STATE] = SMF_CREATE_STATE( [TC_ATTACH_WAIT_SRC_STATE] = SMF_CREATE_STATE(
tc_attach_wait_src_entry, tc_attach_wait_src_entry,
tc_attach_wait_src_run, tc_attach_wait_src_run,
tc_attach_wait_src_exit, tc_attach_wait_src_exit,
&tc_states[TC_CC_RP_SUPER_STATE]), &tc_states[TC_CC_RP_SUPER_STATE],
NULL),
[TC_ATTACHED_SRC_STATE] = SMF_CREATE_STATE( [TC_ATTACHED_SRC_STATE] = SMF_CREATE_STATE(
tc_attached_src_entry, tc_attached_src_entry,
tc_attached_src_run, tc_attached_src_run,
tc_attached_src_exit, tc_attached_src_exit,
NULL,
NULL), NULL),
#endif #endif
[TC_DISABLED_STATE] = SMF_CREATE_STATE( [TC_DISABLED_STATE] = SMF_CREATE_STATE(
tc_disabled_entry, tc_disabled_entry,
tc_disabled_run, tc_disabled_run,
NULL, NULL,
&tc_states[TC_CC_OPEN_SUPER_STATE]), &tc_states[TC_CC_OPEN_SUPER_STATE],
NULL),
[TC_ERROR_RECOVERY_STATE] = SMF_CREATE_STATE( [TC_ERROR_RECOVERY_STATE] = SMF_CREATE_STATE(
tc_error_recovery_entry, tc_error_recovery_entry,
tc_error_recovery_run, tc_error_recovery_run,
NULL, NULL,
&tc_states[TC_CC_OPEN_SUPER_STATE]), &tc_states[TC_CC_OPEN_SUPER_STATE],
NULL),
}; };
BUILD_ASSERT(ARRAY_SIZE(tc_states) == TC_STATE_COUNT); BUILD_ASSERT(ARRAY_SIZE(tc_states) == TC_STATE_COUNT);

View file

@ -213,10 +213,10 @@ static void state_d_exit(void *obj)
} }
static const struct smf_state test_states[] = { static const struct smf_state test_states[] = {
[STATE_A] = SMF_CREATE_STATE(state_a_entry, state_a_run, state_a_exit), [STATE_A] = SMF_CREATE_STATE(state_a_entry, state_a_run, state_a_exit, NULL, NULL),
[STATE_B] = SMF_CREATE_STATE(state_b_entry, state_b_run, state_b_exit), [STATE_B] = SMF_CREATE_STATE(state_b_entry, state_b_run, state_b_exit, NULL, NULL),
[STATE_C] = SMF_CREATE_STATE(state_c_entry, state_c_run, state_c_exit), [STATE_C] = SMF_CREATE_STATE(state_c_entry, state_c_run, state_c_exit, NULL, NULL),
[STATE_D] = SMF_CREATE_STATE(state_d_entry, state_d_run, state_d_exit), [STATE_D] = SMF_CREATE_STATE(state_d_entry, state_d_run, state_d_exit, NULL, NULL),
}; };
ZTEST(smf_tests, test_smf_flat) ZTEST(smf_tests, test_smf_flat)

View file

@ -412,15 +412,15 @@ static void d_entry(void *obj)
} }
static const struct smf_state test_states[] = { static const struct smf_state test_states[] = {
[P05] SMF_CREATE_STATE(p05_entry, p05_run, p05_exit, NULL), [P05] SMF_CREATE_STATE(p05_entry, p05_run, p05_exit, NULL, NULL),
[P04] SMF_CREATE_STATE(p04_entry, p04_run, p04_exit, &test_states[P05]), [P04] SMF_CREATE_STATE(p04_entry, p04_run, p04_exit, &test_states[P05], NULL),
[P03] SMF_CREATE_STATE(p03_entry, p03_run, p03_exit, &test_states[P04]), [P03] SMF_CREATE_STATE(p03_entry, p03_run, p03_exit, &test_states[P04], NULL),
[P02] SMF_CREATE_STATE(p02_entry, p02_run, p02_exit, &test_states[P03]), [P02] SMF_CREATE_STATE(p02_entry, p02_run, p02_exit, &test_states[P03], NULL),
[P01] SMF_CREATE_STATE(p01_entry, p01_run, p01_exit, &test_states[P02]), [P01] SMF_CREATE_STATE(p01_entry, p01_run, p01_exit, &test_states[P02], NULL),
[A] = SMF_CREATE_STATE(a_entry, a_run, a_exit, &test_states[P01]), [A] = SMF_CREATE_STATE(a_entry, a_run, a_exit, &test_states[P01], NULL),
[B] = SMF_CREATE_STATE(b_entry, b_run, b_exit, &test_states[P01]), [B] = SMF_CREATE_STATE(b_entry, b_run, b_exit, &test_states[P01], NULL),
[C] = SMF_CREATE_STATE(c_entry, c_run, c_exit, NULL), [C] = SMF_CREATE_STATE(c_entry, c_run, c_exit, NULL, NULL),
[D] = SMF_CREATE_STATE(d_entry, NULL, NULL, NULL), [D] = SMF_CREATE_STATE(d_entry, NULL, NULL, NULL, NULL),
}; };
ZTEST(smf_tests, test_smf_hierarchical_5_ancestors) ZTEST(smf_tests, test_smf_hierarchical_5_ancestors)

View file

@ -338,17 +338,17 @@ static void state_d_exit(void *obj)
static const struct smf_state test_states[] = { static const struct smf_state test_states[] = {
[PARENT_AB] = SMF_CREATE_STATE(parent_ab_entry, parent_ab_run, [PARENT_AB] = SMF_CREATE_STATE(parent_ab_entry, parent_ab_run,
parent_ab_exit, NULL), parent_ab_exit, NULL, NULL),
[PARENT_C] = SMF_CREATE_STATE(parent_c_entry, parent_c_run, [PARENT_C] = SMF_CREATE_STATE(parent_c_entry, parent_c_run,
parent_c_exit, NULL), parent_c_exit, NULL, NULL),
[STATE_A] = SMF_CREATE_STATE(state_a_entry, state_a_run, state_a_exit, [STATE_A] = SMF_CREATE_STATE(state_a_entry, state_a_run, state_a_exit,
&test_states[PARENT_AB]), &test_states[PARENT_AB], NULL),
[STATE_B] = SMF_CREATE_STATE(state_b_entry, state_b_run, state_b_exit, [STATE_B] = SMF_CREATE_STATE(state_b_entry, state_b_run, state_b_exit,
&test_states[PARENT_AB]), &test_states[PARENT_AB], NULL),
[STATE_C] = SMF_CREATE_STATE(state_c_entry, state_c_run, state_c_exit, [STATE_C] = SMF_CREATE_STATE(state_c_entry, state_c_run, state_c_exit,
&test_states[PARENT_C]), &test_states[PARENT_C], NULL),
[STATE_D] = SMF_CREATE_STATE(state_d_entry, state_d_run, state_d_exit, [STATE_D] = SMF_CREATE_STATE(state_d_entry, state_d_run, state_d_exit,
NULL), NULL, NULL),
}; };
ZTEST(smf_tests, test_smf_hierarchical) ZTEST(smf_tests, test_smf_hierarchical)