TCPMv2: PD Timers - Add PE SrcTransition to framework
BRANCH=none
TEST=make runtests
Tested-by: Denis Brockus
@@ -652,14 +652,6 @@ static struct policy_engine {
*/
uint64_t swap_source_start_timer;
- /*
- * Used to wait for tSrcTransition between sending an Accept for a
- * Request or receiving a GoToMin and transitioning the power supply.
- * See PD 3.0, table 7-11 and table 7-22 This is not a named timer in
- * the spec.
- */
- uint64_t src_transition_timer;
-
/* Counters */
/*
@@ -2459,8 +2451,6 @@ static void pe_src_transition_supply_entry(int port)
{
print_current_state(port);
- pe[port].src_transition_timer = TIMER_DISABLED;
-
/* Send a GotoMin Message or otherwise an Accept Message */
if (PE_CHK_FLAG(port, PE_FLAGS_ACCEPT)) {
PE_CLR_FLAG(port, PE_FLAGS_ACCEPT);
@@ -2468,7 +2458,6 @@ static void pe_src_transition_supply_entry(int port)
} else {
send_ctrl_msg(port, TCPC_TX_SOP, PD_CTRL_GOTO_MIN);
}
-
}
static void pe_src_transition_supply_run(int port)
@@ -2522,15 +2511,15 @@ static void pe_src_transition_supply_run(int port)
} else {
/* NOTE: First pass through this code block */
/* Wait for tSrcTransition before changing supply. */
- pe[port].src_transition_timer =
- get_time().val + PD_T_SRC_TRANSITION;
+ pd_timer_enable(port, PE_TIMER_SRC_TRANSITION,
+ PD_T_SRC_TRANSITION);
}
return;
}
- if (get_time().val > pe[port].src_transition_timer) {
- pe[port].src_transition_timer = TIMER_DISABLED;
+ if (pd_timer_is_expired(port, PE_TIMER_SRC_TRANSITION)) {
+ pd_timer_disable(port, PE_TIMER_SRC_TRANSITION);
/* Transition power supply and send PS_RDY. */
pd_transition_voltage(pe[port].requested_idx);
send_ctrl_msg(port, TCPC_TX_SOP, PD_CTRL_PS_RDY);
@@ -2547,6 +2536,11 @@ static void pe_src_transition_supply_run(int port)
}
}
+static void pe_src_transition_supply_exit(int port)
+{
+ pd_timer_disable(port, PE_TIMER_SRC_TRANSITION);
+}
+
/*
* Transitions state after receiving a Not Supported extended message. Under
* appropriate conditions, transitions to a PE_{SRC,SNK}_Chunk_Received.
@@ -6854,6 +6848,7 @@ static __const_data const struct usb_state pe_states[] = {
[PE_SRC_TRANSITION_SUPPLY] = {
.entry = pe_src_transition_supply_entry,
.run = pe_src_transition_supply_run,
+ .exit = pe_src_transition_supply_exit,
},
[PE_SRC_READY] = {
.entry = pe_src_ready_entry,
