usb_c: Check state machine array of states

Build time check that the number of states initialized
in the state machine array matches the number of enums
used to index said array.

Signed-off-by: Sam Hurst <sbh1187@gmail.com>
This commit is contained in:
Sam Hurst 2022-12-23 08:13:55 -08:00 committed by Carles Cufí
commit f04da7f7ab
5 changed files with 20 additions and 0 deletions

View file

@ -343,6 +343,7 @@ void pe_set_state(const struct device *dev, const enum usbc_pe_state state)
{
struct usbc_port_data *data = dev->data;
__ASSERT(state < ARRAY_SIZE(pe_states), "invalid pe_state %d", state);
smf_set_state(SMF_CTX(data->pe), &pe_states[state]);
}
@ -823,3 +824,4 @@ static const struct smf_state pe_states[] = {
NULL,
NULL),
};
BUILD_ASSERT(ARRAY_SIZE(pe_states) == PE_STATE_COUNT);

View file

@ -55,6 +55,9 @@ enum usbc_pe_state {
/** PE_Suspend. Not part of the PD specification. */
PE_SUSPEND,
/** Number of PE States */
PE_STATE_COUNT
};
/**

View file

@ -70,6 +70,9 @@ enum usbc_prl_tx_state_t {
/** PRL_Tx_Suspend. Not part of the PD specification. */
PRL_TX_SUSPEND,
/** Number of PRL_TX States */
PRL_TX_STATE_COUNT
};
/**
@ -87,6 +90,9 @@ enum usbc_prl_hr_state_t {
/** PRL_Hr_Suspend. Not part of the PD specification. */
PRL_HR_SUSPEND,
/** Number of PRL_HR States */
PRL_HR_STATE_COUNT
};
static const struct smf_state prl_tx_states[];
@ -374,6 +380,7 @@ static void prl_tx_set_state(const struct device *dev, const enum usbc_prl_tx_st
struct usbc_port_data *data = dev->data;
struct protocol_layer_tx_t *prl_tx = data->prl_tx;
__ASSERT(state < ARRAY_SIZE(prl_tx_states), "invalid prl_tx_state %d", state);
smf_set_state(SMF_CTX(prl_tx), &prl_tx_states[state]);
}
@ -385,6 +392,7 @@ static void prl_hr_set_state(const struct device *dev, const enum usbc_prl_hr_st
struct usbc_port_data *data = dev->data;
struct protocol_hard_reset_t *prl_hr = data->prl_hr;
__ASSERT(state < ARRAY_SIZE(prl_hr_states), "invalid prl_hr_state %d", state);
smf_set_state(SMF_CTX(prl_hr), &prl_hr_states[state]);
}
@ -1159,6 +1167,7 @@ static const struct smf_state prl_tx_states[] = {
NULL,
NULL),
};
BUILD_ASSERT(ARRAY_SIZE(prl_tx_states) == PRL_TX_STATE_COUNT);
/**
* @brief Protocol Layer Hard Reset State table
@ -1190,3 +1199,4 @@ static const struct smf_state prl_hr_states[] = {
NULL,
NULL),
};
BUILD_ASSERT(ARRAY_SIZE(prl_hr_states) == PRL_HR_STATE_COUNT);

View file

@ -127,6 +127,7 @@ void tc_set_state(const struct device *dev, const enum tc_state_t state)
struct usbc_port_data *data = dev->data;
struct tc_sm_t *tc = data->tc;
__ASSERT(state < ARRAY_SIZE(tc_states), "invalid tc_state %d", state);
smf_set_state(SMF_CTX(tc), &tc_states[state]);
}
@ -261,3 +262,4 @@ static const struct smf_state tc_states[] = {
NULL,
&tc_states[TC_CC_OPEN_SUPER_STATE]),
};
BUILD_ASSERT(ARRAY_SIZE(tc_states) == TC_STATE_COUNT);

View file

@ -33,6 +33,9 @@ enum tc_state_t {
TC_ATTACH_WAIT_SNK_STATE,
/** Attached Sink State */
TC_ATTACHED_SNK_STATE,
/** Number of TC States */
TC_STATE_COUNT
};
/**