summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@chromium.org>2018-01-10 11:13:10 -0800
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2018-02-01 00:48:15 +0000
commit3f91d64389c1256d5f498b9927dc577b611c6d01 (patch)
tree302124e642cf9cc8675d5adc6c7305872e6b2a8c
parente3fbbaa8c7681d5698efc8346790e8dffc7caadc (diff)
downloadchrome-ec-3f91d64389c1256d5f498b9927dc577b611c6d01.tar.gz
pp: split fsm state in two
In preparation to conveying the PP state to gsctool let's split the 'PP_DETECT_IN_PROGRESS' physical presence FSM state in two: - PP_DETECT_AWAITING_PRESS, a state when user physical presence indication is expected - PP_DETECT_BETWEEN_PRESSES, a state when the previous indication was accepted, but the next one is not yet required. The code is modified to accept the disjunction of the twp new states as the old PP_DETECT_IN_PROGRESS state. BRANCH=cr50 BUG=b:62537474 TEST=successfully took Eve through 'ccd open' Change-Id: I0d229f2f8beeec01ea2a9106b0cbc3f9801ff479 Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/860997 Reviewed-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: Mary Ruthven <mruthven@chromium.org> (cherry picked from commit 25b59e26caa0fc1a8593d98ea5fc0af2a7650d09) Reviewed-on: https://chromium-review.googlesource.com/896759
-rw-r--r--common/physical_presence.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/common/physical_presence.c b/common/physical_presence.c
index 2f136caa84..0069a4fef9 100644
--- a/common/physical_presence.c
+++ b/common/physical_presence.c
@@ -36,7 +36,8 @@
enum pp_detect_state {
PP_DETECT_IDLE = 0,
- PP_DETECT_IN_PROGRESS,
+ PP_DETECT_AWAITING_PRESS,
+ PP_DETECT_BETWEEN_PRESSES,
PP_DETECT_FINISHING,
PP_DETECT_ABORT
};
@@ -56,6 +57,12 @@ static uint64_t pp_last_press; /* Time of last press */
*/
static struct mutex pp_mutex;
+static int pp_detect_in_progress(void)
+{
+ return ((pp_detect_state == PP_DETECT_AWAITING_PRESS) ||
+ (pp_detect_state == PP_DETECT_BETWEEN_PRESSES));
+}
+
/******************************************************************************/
/*
* Deferred functions
@@ -80,7 +87,7 @@ static void physical_detect_done(void)
*/
mutex_lock(&pp_mutex);
- if (pp_detect_state != PP_DETECT_IN_PROGRESS) {
+ if (!pp_detect_in_progress()) {
CPRINTF("\nPhysical presence check aborted.\n");
pp_detect_callback = NULL;
} else if (pp_press_count < pp_press_count_needed) {
@@ -118,6 +125,7 @@ DECLARE_DEFERRED(physical_detect_done);
*/
static void physical_detect_prompt(void)
{
+ pp_detect_state = PP_DETECT_AWAITING_PRESS;
CPRINTF("\n\nPress the physical button now!\n\n");
}
DECLARE_DEFERRED(physical_detect_prompt);
@@ -137,7 +145,7 @@ static void physical_detect_check_press(void)
CPRINTS("PP press dt=%.6ld", dt);
/* If we no longer care about presses, ignore them */
- if (pp_detect_state != PP_DETECT_IN_PROGRESS)
+ if (!pp_detect_in_progress())
goto pdpress_exit;
/* Ignore extra presses we don't need */
@@ -167,6 +175,7 @@ static void physical_detect_check_press(void)
/* Ok, we need this press */
CPRINTS("PP press counted!");
+ pp_detect_state = PP_DETECT_BETWEEN_PRESSES;
pp_last_press = now;
pp_press_count++;
@@ -211,7 +220,7 @@ int physical_detect_start(int is_long, void (*callback)(void))
pp_press_count = 0;
pp_last_press = get_time().val;
pp_detect_callback = callback;
- pp_detect_state = PP_DETECT_IN_PROGRESS;
+ pp_detect_state = PP_DETECT_BETWEEN_PRESSES;
mutex_unlock(&pp_mutex);
/* Start capturing button presses */
@@ -237,7 +246,7 @@ int physical_detect_busy(void)
void physical_detect_abort(void)
{
mutex_lock(&pp_mutex);
- if (pp_detect_state == PP_DETECT_IN_PROGRESS) {
+ if (pp_detect_in_progress()) {
CPRINTS("PP abort");
pp_detect_state = PP_DETECT_ABORT;
/* Speed up call to done */