diff options
author | Paul Fagerburg <pfagerburg@google.com> | 2020-07-22 12:17:54 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-07-23 20:23:34 +0000 |
commit | dbe53ae07fdd735bd518614e66e472697fd4f19b (patch) | |
tree | 66896e8c10361980cf9285a20d6cfeb9f52be214 /common | |
parent | 8850f12ce079659f926e7ded69cc7fa6a928e227 (diff) | |
download | chrome-ec-dbe53ae07fdd735bd518614e66e472697fd4f19b.tar.gz |
tests: restructure pd_task re-init
The unit tests need to re-init pd_task as part of each test. Replace
the `goto` with an extra `while` loop, and break up the task into
separate init and loop portions to make it clearer what's happening
when the event for the re-init comes through.
BUG=b:160975343
BRANCH=None
TEST=`TEST_LIST_HOST=usb_typec_drp_acc_trysrc make runhosttests`
Signed-off-by: Paul Fagerburg <pfagerburg@google.com>
Change-Id: Ied9bdb0c2c8924a335c12dcec05df05fc3236c50
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2313781
Tested-by: Paul Fagerburg <pfagerburg@chromium.org>
Reviewed-by: Denis Brockus <dbrockus@chromium.org>
Reviewed-by: Jett Rink <jettrink@chromium.org>
Commit-Queue: Paul Fagerburg <pfagerburg@chromium.org>
Diffstat (limited to 'common')
-rw-r--r-- | common/usbc/usbc_task.c | 100 |
1 files changed, 59 insertions, 41 deletions
diff --git a/common/usbc/usbc_task.c b/common/usbc/usbc_task.c index 9b5382160b..be7182f3b7 100644 --- a/common/usbc/usbc_task.c +++ b/common/usbc/usbc_task.c @@ -154,18 +154,9 @@ void pd_interrupt_handler_task(void *p) } #endif /* HAS_TASK_PD_INT_C0 || HAS_TASK_PD_INT_C1 || HAS_TASK_PD_INT_C2 */ -void pd_task(void *u) -{ - int port = TASK_ID_TO_PD_PORT(task_get_current()); - - /* - * If port does not exist, return - */ - if (port >= board_get_usb_pd_port_count()) - return; - -test_only_restart: +static void pd_task_init(int port) +{ if (IS_ENABLED(CONFIG_USB_TYPEC_SM)) tc_state_init(port); @@ -178,42 +169,69 @@ test_only_restart: */ if (IS_ENABLED(HAS_DEFFERED_INTERRUPT_HANDLER)) schedule_deferred_pd_interrupt(port); +} +static bool pd_task_loop(int port) +{ + /* wait for next event/packet or timeout expiration */ + const uint32_t evt = + task_wait_event(paused[port] + ? -1 + : USBC_EVENT_TIMEOUT); - while (1) { - /* wait for next event/packet or timeout expiration */ - const uint32_t evt = - task_wait_event(paused[port] - ? -1 - : USBC_EVENT_TIMEOUT); - - /* - * Re-use TASK_EVENT_RESET_DONE in tests to restart the USB task - */ - if (IS_ENABLED(TEST_BUILD) && (evt & TASK_EVENT_RESET_DONE)) - goto test_only_restart; + /* + * Re-use TASK_EVENT_RESET_DONE in tests to restart the USB task + * if this code is running in a unit test. + */ + if (IS_ENABLED(TEST_BUILD) && (evt & TASK_EVENT_RESET_DONE)) + return false; - /* handle events that affect the state machine as a whole */ - if (IS_ENABLED(CONFIG_USB_TYPEC_SM)) - tc_event_check(port, evt); + /* handle events that affect the state machine as a whole */ + if (IS_ENABLED(CONFIG_USB_TYPEC_SM)) + tc_event_check(port, evt); - /* - * run port controller task to check CC and/or read incoming - * messages - */ - if (IS_ENABLED(CONFIG_USB_PD_TCPC)) - tcpc_run(port, evt); + /* + * run port controller task to check CC and/or read incoming + * messages + */ + if (IS_ENABLED(CONFIG_USB_PD_TCPC)) + tcpc_run(port, evt); + + /* Run policy engine state machine */ + if (IS_ENABLED(CONFIG_USB_PE_SM)) + pe_run(port, evt, tc_get_pd_enabled(port)); + + /* Run protocol state machine */ + if (IS_ENABLED(CONFIG_USB_PRL_SM)) + prl_run(port, evt, tc_get_pd_enabled(port)); + + /* Run TypeC state machine */ + if (IS_ENABLED(CONFIG_USB_TYPEC_SM)) + tc_run(port); - /* Run policy engine state machine */ - if (IS_ENABLED(CONFIG_USB_PE_SM)) - pe_run(port, evt, tc_get_pd_enabled(port)); + return true; +} - /* Run protocol state machine */ - if (IS_ENABLED(CONFIG_USB_PRL_SM)) - prl_run(port, evt, tc_get_pd_enabled(port)); +void pd_task(void *u) +{ + int port = TASK_ID_TO_PD_PORT(task_get_current()); - /* Run TypeC state machine */ - if (IS_ENABLED(CONFIG_USB_TYPEC_SM)) - tc_run(port); + /* + * If port does not exist, return + */ + if (port >= board_get_usb_pd_port_count()) + return; + + while (1) { + pd_task_init(port); + + /* As long as pd_task_loop returns true, keep running the loop. + * pd_task_loop returns false when the code needs to re-init + * the task, so once the code breaks out of the inner while + * loop, the re-init code at the top of the outer while loop + * will run. + */ + while (pd_task_loop(port)) + continue; } } |