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 <sbh1187@gmail.com>
This commit is contained in:
Sam Hurst 2023-01-07 14:28:19 -08:00 committed by Carles Cufí
commit f84ee58abd
3 changed files with 13 additions and 7 deletions

View file

@ -230,7 +230,7 @@ void pe_report_error(const struct device *dev, const enum pe_error e,
*/ */
if (pe_get_state(dev) == PE_SEND_SOFT_RESET || if (pe_get_state(dev) == PE_SEND_SOFT_RESET ||
pe_get_state(dev) == PE_SOFT_RESET) { pe_get_state(dev) == PE_SOFT_RESET) {
pe_set_state(dev, PE_SNK_HARD_RESET); atomic_set_bit(pe->flags, PE_FLAGS_PROTOCOL_ERROR);
return; return;
} }

View file

@ -106,6 +106,10 @@ enum pe_flags {
* Data Role Swap * Data Role Swap
*/ */
PE_FLAGS_WAIT_DATA_ROLE_SWAP = 12, PE_FLAGS_WAIT_DATA_ROLE_SWAP = 12,
/**
* This flag is set when a protocol error occurs.
*/
PE_FLAGS_PROTOCOL_ERROR = 13,
/** Number of PE Flags */ /** Number of PE Flags */
PE_FLAGS_COUNT PE_FLAGS_COUNT

View file

@ -725,10 +725,11 @@ void pe_send_soft_reset_run(void *obj)
} }
/* /*
* The Policy Engine Shall transition to the PE_SNK_Hard_Reset state when: * The Policy Engine Shall transition to the PE_SNK_Hard_Reset state when:
* 1: A SenderResponseTimer timeout occurs (Handled in pe_report_error function) * 1: A SenderResponseTimer timeout occurs
* 2: Or the Protocol Layer indicates that a transmission error has occurred * 2: Or the Protocol Layer indicates that a transmission error has occurred
*/ */
else if (usbc_timer_expired(&pe->pd_t_sender_response)) { else if (usbc_timer_expired(&pe->pd_t_sender_response) ||
atomic_test_and_clear_bit(pe->flags, PE_FLAGS_PROTOCOL_ERROR)) {
pe_set_state(dev, PE_SNK_HARD_RESET); pe_set_state(dev, PE_SNK_HARD_RESET);
} }
} }
@ -774,23 +775,24 @@ void pe_soft_reset_run(void *obj)
if (atomic_test_and_clear_bit(pe->flags, PE_FLAGS_SEND_SOFT_RESET)) { if (atomic_test_and_clear_bit(pe->flags, PE_FLAGS_SEND_SOFT_RESET)) {
/* Send Accept message */ /* Send Accept message */
pe_send_ctrl_msg(dev, PD_PACKET_SOP, PD_CTRL_ACCEPT); pe_send_ctrl_msg(dev, PD_PACKET_SOP, PD_CTRL_ACCEPT);
return;
} }
/* /*
* The Policy Engine Shall transition to the PE_SNK_Wait_for_Capabilities * The Policy Engine Shall transition to the PE_SNK_Wait_for_Capabilities
* state when: * state when:
* 1: The Accept Message has been sent on SOP. * 1: The Accept Message has been sent on SOP.
*/ */
if (atomic_test_and_clear_bit(pe->flags, PE_FLAGS_TX_COMPLETE)) { else if (atomic_test_and_clear_bit(pe->flags, PE_FLAGS_TX_COMPLETE)) {
pe_set_state(dev, PE_SNK_WAIT_FOR_CAPABILITIES); pe_set_state(dev, PE_SNK_WAIT_FOR_CAPABILITIES);
} }
/* /*
* The Policy Engine Shall transition to the PE_SNK_Hard_Reset * The Policy Engine Shall transition to the PE_SNK_Hard_Reset
* state when: * state when:
* 1: The Protocol Layer indicates that a transmission error * 1: The Protocol Layer indicates that a transmission error
* has occurred. (Handled in pe_report_error function) * has occurred.
*/ */
else if (atomic_test_and_clear_bit(pe->flags, PE_FLAGS_PROTOCOL_ERROR)) {
pe_set_state(dev, PE_SNK_HARD_RESET);
}
} }
/** /**