usbc: add sleep prevention in places that may require it

Add sleep prevention in crucial USB-C stack functions to make
state transitions faster and to send responses faster.

Signed-off-by: Michał Barnaś <mb@semihalf.com>
This commit is contained in:
Michał Barnaś 2023-08-23 14:40:27 +02:00 committed by Carles Cufí
commit 6fc22462a3
2 changed files with 32 additions and 0 deletions

View file

@ -345,6 +345,9 @@ void pe_message_received(const struct device *dev)
struct policy_engine *pe = data->pe;
atomic_set_bit(pe->flags, PE_FLAGS_MSG_RECEIVED);
/* Allow the PE to be executed once more and respond faster for the received message */
usbc_bypass_next_sleep(dev);
}
/**
@ -422,6 +425,9 @@ void pe_set_state(const struct device *dev, const enum usbc_pe_state state)
__ASSERT(state < ARRAY_SIZE(pe_states), "invalid pe_state %d", state);
smf_set_state(SMF_CTX(data->pe), &pe_states[state]);
/* Allow the PE to execute logic from the new state without additional delay */
usbc_bypass_next_sleep(dev);
}
/**

View file

@ -79,7 +79,15 @@ static void sink_power_sub_states(const struct device *dev)
*/
void tc_unattached_snk_entry(void *obj)
{
struct tc_sm_t *tc = (struct tc_sm_t *)obj;
LOG_INF("Unattached.SNK");
/*
* Allow the state machine to immediately check the state of CC lines and go into
* Attach.Wait state in case the Rp value is detected on the CC lines
*/
usbc_bypass_next_sleep(tc->dev);
}
/**
@ -109,6 +117,12 @@ void tc_attach_wait_snk_entry(void *obj)
LOG_INF("AttachWait.SNK");
tc->cc_state = TC_CC_NONE;
/*
* Allow the debounce timers to start immediately without additional delay added
* by going into sleep
*/
usbc_bypass_next_sleep(tc->dev);
}
/**
@ -138,6 +152,11 @@ void tc_attach_wait_snk_run(void *obj)
/* Wait for CC debounce */
if (usbc_timer_running(&tc->tc_t_cc_debounce) &&
usbc_timer_expired(&tc->tc_t_cc_debounce) == false) {
if (CONFIG_USBC_STATE_MACHINE_CYCLE_TIME >= TC_T_CC_DEBOUNCE_MIN_MS) {
/* Make sure the debounce time won't be longer than specified */
usbc_bypass_next_sleep(tc->dev);
}
return;
}
@ -156,6 +175,13 @@ void tc_attach_wait_snk_run(void *obj)
if (vbus_present) {
tc_set_state(dev, TC_ATTACHED_SNK_STATE);
}
/*
* In case of no VBUS present, this call prevents going into the sleep and allows for
* faster VBUS detection. In case of VBUS present, allows for immediate execution of logic
* from new state.
*/
usbc_bypass_next_sleep(tc->dev);
}
void tc_attach_wait_snk_exit(void *obj)