diff options
author | Sam Hurst <shurst@google.com> | 2018-09-13 09:27:08 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-04-08 22:30:19 -0700 |
commit | 0fe6147a9d8d9feef5049aa6c6c4a6ad30d12b26 (patch) | |
tree | 05d4509bcfe68a248ec3fa58168f3de2536c2d9c /include/usb_sm.h | |
parent | e097feb8b2db20cd2435a483517356defa222db1 (diff) | |
download | chrome-ec-0fe6147a9d8d9feef5049aa6c6c4a6ad30d12b26.tar.gz |
chocodile_vpdmcu: Firmware for chocodile mcu
Implement Chocodile Charge-Through Vconn Powered firmware for mcu
using new Type-C/PD State machine stack.
BUG=b:115626873
BRANCH=none
TEST=manual
Charge-Through was tested on an Atlas running a DRP USB-C/PD state
machine with CTUnattached.SNK and CTAttached.SNK states.
Signed-off-by: Sam Hurst <shurst@chromium.org>
Change-Id: I847f1bcd2fc3ce41e66edd133a10c943d5e8c819
Reviewed-on: https://chromium-review.googlesource.com/1225250
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Sam Hurst <shurst@google.com>
Reviewed-by: Stefan Reinauer <reinauer@google.com>
Diffstat (limited to 'include/usb_sm.h')
-rw-r--r-- | include/usb_sm.h | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/include/usb_sm.h b/include/usb_sm.h new file mode 100644 index 0000000000..15de5f9ef4 --- /dev/null +++ b/include/usb_sm.h @@ -0,0 +1,67 @@ +/* Copyright 2019 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +/* USB State Machine Framework */ + +#ifndef __CROS_EC_USB_SM_H +#define __CROS_EC_USB_SM_H + +#define SM_OBJ(smo) ((struct sm_obj *)&smo) +#define SUPER(r, sig, s) ((((r) == 0) || ((sig) == ENTRY_SIG) || \ + ((sig) == EXIT_SIG)) ? 0 : ((uintptr_t)(s))) +#define RUN_SUPER 1 + +/* Local state machine states */ +enum sm_local_state { + SM_INIT, + SM_RUN, + SM_PAUSED +}; + +/* State Machine signals */ +enum signal { + ENTRY_SIG = 0, + RUN_SIG, + EXIT_SIG, + SUPER_SIG, +}; + +typedef unsigned int (*state_sig)(int port); +typedef unsigned int (*sm_state)(int port, enum signal sig); + +struct sm_obj { + sm_state task_state; + sm_state last_state; +}; + +/** + * Initialize a State Machine + * + * @param port USB-C port number + * @param obj State machine object + * @param target Initial state of state machine + */ +void init_state(int port, struct sm_obj *obj, sm_state target); + +/** + * Changes a state machines state + * + * @param port USB-C port number + * @param obj State machine object + * @param target State to transition to + * @return 0 + */ +int set_state(int port, struct sm_obj *obj, sm_state target); + +/** + * Executes a state machine + * + * @param port USB-C port number + * @param obj State machine object + * @param sig State machine signal + */ +void exe_state(int port, struct sm_obj *obj, enum signal sig); + +#endif /* __CROS_EC_USB_SM_H */ |