-
Notifications
You must be signed in to change notification settings - Fork 47
type-c-service: Don't restart sink ready timeout if contract is same #737
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
RobertZ2011
wants to merge
1
commit into
OpenDevicePartnership:main
Choose a base branch
from
RobertZ2011:type-c-sink-ready-change
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+37
−19
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ use embassy_futures::yield_now; | |
| use embassy_sync::pubsub::WaitResult; | ||
| use embassy_time::{Duration, Timer}; | ||
| use embedded_services::debug; | ||
| use embedded_services::power::policy::PowerCapability; | ||
| use embedded_services::type_c::Cached; | ||
| use embedded_services::type_c::controller::{InternalResponseData, Response}; | ||
| use embedded_usb_pd::constants::{T_PS_TRANSITION_EPR_MS, T_PS_TRANSITION_SPR_MS}; | ||
|
|
@@ -48,36 +49,50 @@ where | |
| state: &mut dyn DynPortState<'_>, | ||
| status: &PortStatus, | ||
| port: LocalPortId, | ||
| new_contract: bool, | ||
| new_contract: Option<PowerCapability>, | ||
| sink_ready: bool, | ||
| ) -> Result<(), PdError> { | ||
| if port.0 as usize >= state.num_ports() { | ||
| return Err(PdError::InvalidPort); | ||
| } | ||
|
|
||
| let deadline = &mut state | ||
| let port_state = state | ||
| .port_states_mut() | ||
| .get_mut(port.0 as usize) | ||
| .ok_or(PdError::InvalidPort)? | ||
| .sink_ready_deadline; | ||
| .ok_or(PdError::InvalidPort)?; | ||
|
|
||
| if new_contract && !sink_ready { | ||
| // Start the timeout | ||
| // Double the spec maximum transition time to provide a safety margin for hardware/controller delays our out-of-spec controllers. | ||
| let timeout_ms = if status.epr { | ||
| T_PS_TRANSITION_EPR_MS | ||
| let available_sink_contract = port_state.status.available_sink_contract; | ||
| let deadline = &mut port_state.sink_ready_deadline; | ||
|
|
||
| // Check if we need to start the timeout | ||
| if let Some(new_contract) = new_contract { | ||
| let contract_changed = Some(new_contract) != available_sink_contract; | ||
|
|
||
| // Don't start the timeout if the sink is already ready or if the contract didn't change. | ||
| // The latter ensures that soft resets won't continually reset the ready timeout | ||
| if !sink_ready && contract_changed { | ||
| // Start the timeout | ||
| // Double the spec maximum transition time to provide a safety margin for hardware/controller delays our out-of-spec controllers. | ||
| let timeout_ms = if status.epr { | ||
| T_PS_TRANSITION_EPR_MS | ||
| } else { | ||
| T_PS_TRANSITION_SPR_MS | ||
| } | ||
| .maximum | ||
| .0 * 2; | ||
|
|
||
| debug!("Port{}: Sink ready timeout started for {}ms", port.0, timeout_ms); | ||
| *deadline = Some(Instant::now() + Duration::from_millis(timeout_ms as u64)); | ||
| } else { | ||
| T_PS_TRANSITION_SPR_MS | ||
| debug!( | ||
| "Port{}: Not starting sink ready timeout, sink_ready: {}, contract_changed: {}", | ||
| port.0, sink_ready, contract_changed | ||
| ); | ||
| } | ||
| .maximum | ||
| .0 * 2; | ||
| } | ||
|
|
||
| debug!("Port{}: Sink ready timeout started for {}ms", port.0, timeout_ms); | ||
| *deadline = Some(Instant::now() + Duration::from_millis(timeout_ms as u64)); | ||
| } else if deadline.is_some() | ||
| && (!status.is_connected() || status.available_sink_contract.is_none() || sink_ready) | ||
| { | ||
| // Clear the timeout | ||
| // Check if we need to clear the timeout | ||
| if deadline.is_some() && (!status.is_connected() || status.available_sink_contract.is_none() || sink_ready) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is checked now even in the case where we just set a deadline, is that what we want? |
||
| debug!("Port{}: Sink ready timeout cleared", port.0); | ||
| *deadline = None; | ||
| } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like we can keep
new_contractas a bool and just check whetherport_state.status.available_sink_contractis the same asstatus.available_sink_contract. The option inside an option makes it a bit confusing.