Skip to content

Commit f84ee58

Browse files
sambhurstcarlescufi
authored andcommitted
usb_c: Add protocol error flag
Use a flag to report a protocol error to the states. This keeps state specific actions in the state. Currently, those state specific actions are handled in the pe_report_error function. Signed-off-by: Sam Hurst <[email protected]>
1 parent 6984162 commit f84ee58

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

subsys/usb/usb_c/usbc_pe_common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ void pe_report_error(const struct device *dev, const enum pe_error e,
230230
*/
231231
if (pe_get_state(dev) == PE_SEND_SOFT_RESET ||
232232
pe_get_state(dev) == PE_SOFT_RESET) {
233-
pe_set_state(dev, PE_SNK_HARD_RESET);
233+
atomic_set_bit(pe->flags, PE_FLAGS_PROTOCOL_ERROR);
234234
return;
235235
}
236236

subsys/usb/usb_c/usbc_pe_common_internal.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ enum pe_flags {
106106
* Data Role Swap
107107
*/
108108
PE_FLAGS_WAIT_DATA_ROLE_SWAP = 12,
109+
/**
110+
* This flag is set when a protocol error occurs.
111+
*/
112+
PE_FLAGS_PROTOCOL_ERROR = 13,
109113

110114
/** Number of PE Flags */
111115
PE_FLAGS_COUNT

subsys/usb/usb_c/usbc_pe_snk_states.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -725,10 +725,11 @@ void pe_send_soft_reset_run(void *obj)
725725
}
726726
/*
727727
* The Policy Engine Shall transition to the PE_SNK_Hard_Reset state when:
728-
* 1: A SenderResponseTimer timeout occurs (Handled in pe_report_error function)
728+
* 1: A SenderResponseTimer timeout occurs
729729
* 2: Or the Protocol Layer indicates that a transmission error has occurred
730730
*/
731-
else if (usbc_timer_expired(&pe->pd_t_sender_response)) {
731+
else if (usbc_timer_expired(&pe->pd_t_sender_response) ||
732+
atomic_test_and_clear_bit(pe->flags, PE_FLAGS_PROTOCOL_ERROR)) {
732733
pe_set_state(dev, PE_SNK_HARD_RESET);
733734
}
734735
}
@@ -774,23 +775,24 @@ void pe_soft_reset_run(void *obj)
774775
if (atomic_test_and_clear_bit(pe->flags, PE_FLAGS_SEND_SOFT_RESET)) {
775776
/* Send Accept message */
776777
pe_send_ctrl_msg(dev, PD_PACKET_SOP, PD_CTRL_ACCEPT);
777-
return;
778778
}
779-
780779
/*
781780
* The Policy Engine Shall transition to the PE_SNK_Wait_for_Capabilities
782781
* state when:
783782
* 1: The Accept Message has been sent on SOP.
784783
*/
785-
if (atomic_test_and_clear_bit(pe->flags, PE_FLAGS_TX_COMPLETE)) {
784+
else if (atomic_test_and_clear_bit(pe->flags, PE_FLAGS_TX_COMPLETE)) {
786785
pe_set_state(dev, PE_SNK_WAIT_FOR_CAPABILITIES);
787786
}
788787
/*
789788
* The Policy Engine Shall transition to the PE_SNK_Hard_Reset
790789
* state when:
791790
* 1: The Protocol Layer indicates that a transmission error
792-
* has occurred. (Handled in pe_report_error function)
791+
* has occurred.
793792
*/
793+
else if (atomic_test_and_clear_bit(pe->flags, PE_FLAGS_PROTOCOL_ERROR)) {
794+
pe_set_state(dev, PE_SNK_HARD_RESET);
795+
}
794796
}
795797

796798
/**

0 commit comments

Comments
 (0)