summaryrefslogtreecommitdiff
path: root/common/device_state.c
diff options
context:
space:
mode:
authorMary Ruthven <mruthven@chromium.org>2017-01-18 17:39:44 -0800
committerchrome-bot <chrome-bot@chromium.org>2017-01-23 13:38:22 -0800
commit8f118e01679402232ae70882345b4b919f980723 (patch)
tree785cefe6c9241a6aa8aa9e6857a97e79eb8c6c3c /common/device_state.c
parent38c5661f14f8a4be018e4b6e1641071c5f1fe866 (diff)
downloadchrome-ec-8f118e01679402232ae70882345b4b919f980723.tar.gz
device_state: signal if device_set_state changed the state
Each device keeps track of the last known state. If device_set_state updates the device state to a new known state, then return true. Cr50 uses this returned value to check if the state has changed instead of calculating it itself. BUG=none BRANCH=none TEST=device detection still works Change-Id: I8afac178c2c731def6f4f62ff7023fe169ec1479 Signed-off-by: Mary Ruthven <mruthven@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/430970 Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Diffstat (limited to 'common/device_state.c')
-rw-r--r--common/device_state.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/common/device_state.c b/common/device_state.c
index ee82846b84..fd9ebcf14b 100644
--- a/common/device_state.c
+++ b/common/device_state.c
@@ -12,15 +12,16 @@ int device_get_state(enum device_type device)
return device_states[device].state;
}
-void device_set_state(enum device_type device, enum device_state state)
+int device_set_state(enum device_type device, enum device_state state)
{
- if (device_states[device].state == state)
- return;
+ device_states[device].state = state;
- if (state != DEVICE_STATE_UNKNOWN)
+ if (state != DEVICE_STATE_UNKNOWN &&
+ device_states[device].last_known_state != state) {
device_states[device].last_known_state = state;
-
- device_states[device].state = state;
+ return 1;
+ }
+ return 0;
}
static void check_device_state(void)