diff options
author | Alexandru M Stan <amstan@chromium.org> | 2017-11-30 20:43:15 -0800 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2018-05-30 00:56:47 +0000 |
commit | b26ecb434788fe58251fc3af01ce9ef9669a65c3 (patch) | |
tree | 42b8383f1836257d62fedb1b59aeebe26fb0f454 | |
parent | 511a97f99893b516397f34a3fbce8e2cde6abbeb (diff) | |
download | chrome-ec-b26ecb434788fe58251fc3af01ce9ef9669a65c3.tar.gz |
motion_sense: Lower jitter of EC->AP timestamp
When the EC sends an interrupt to the AP notifying it of new
accelerometer data we need to make sure the spot we record the timestamp
of the event is virtually identical to the spot the AP records the same
point in time.
Therefore a better spot for that is right next to the gpio toggling of
the interrupt line.
BUG=b:67743747
TEST=In the kernel, fifo_info->info.timestamp still has sane values.
TEST=CTS should still pass
BRANCH=master
Change-Id: Ic77101a045123e779f576c46b401c765304976fd
Signed-off-by: Alexandru M Stan <amstan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/802976
Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
(cherry picked from commit 1d518fb85cd7163a2fc390871046d8d6c398ed57)
Reviewed-on: https://chromium-review.googlesource.com/1077558
Commit-Queue: Philip Chen <philipchen@chromium.org>
Tested-by: Philip Chen <philipchen@chromium.org>
Reviewed-by: Philip Chen <philipchen@chromium.org>
-rw-r--r-- | common/mkbp_event.c | 12 | ||||
-rw-r--r-- | common/motion_sense.c | 2 | ||||
-rw-r--r-- | include/ec_commands.h | 4 | ||||
-rw-r--r-- | include/mkbp_event.h | 9 |
4 files changed, 25 insertions, 2 deletions
diff --git a/common/mkbp_event.c b/common/mkbp_event.c index 616f489df6..fcfe4f25a3 100644 --- a/common/mkbp_event.c +++ b/common/mkbp_event.c @@ -9,12 +9,14 @@ #include "chipset.h" #include "gpio.h" #include "host_command.h" +#include "hwtimer.h" #include "link_defs.h" #include "mkbp_event.h" #include "power.h" #include "util.h" static uint32_t events; +uint32_t mkbp_last_event_time; static void set_event(uint8_t event_type) { @@ -36,6 +38,13 @@ static int event_is_set(uint8_t event_type) */ static void set_host_interrupt(int active) { + static int old_active; + + interrupt_disable(); + + if (old_active == 0 && active == 1) + mkbp_last_event_time = __hw_clock_source_read(); + /* interrupt host by using active low EC_INT signal */ #ifdef CONFIG_MKBP_USE_HOST_EVENT if (active) @@ -43,6 +52,9 @@ static void set_host_interrupt(int active) #else gpio_set_level(GPIO_EC_INT_L, !active); #endif + + old_active = active; + interrupt_enable(); } /** diff --git a/common/motion_sense.c b/common/motion_sense.c index 89a7f870df..307af56323 100644 --- a/common/motion_sense.c +++ b/common/motion_sense.c @@ -189,7 +189,7 @@ static void motion_sense_get_fifo_info( fifo_info->count = fifo_queue_count; fifo_info->total_lost = motion_sense_fifo_lost; mutex_unlock(&g_sensor_mutex); - fifo_info->timestamp = __hw_clock_source_read(); + fifo_info->timestamp = mkbp_last_event_time; } #endif diff --git a/include/ec_commands.h b/include/ec_commands.h index 00c6dad089..2b076dae0c 100644 --- a/include/ec_commands.h +++ b/include/ec_commands.h @@ -2307,7 +2307,9 @@ struct __ec_todo_packed ec_response_motion_sense_fifo_info { uint16_t size; /* Amount of space used in the fifo */ uint16_t count; - /* Timestamp recorded in us */ + /* Timestamp recorded in us. + * aka accurate timestamp when host event was triggered. + */ uint32_t timestamp; /* Total amount of vector lost */ uint16_t total_lost; diff --git a/include/mkbp_event.h b/include/mkbp_event.h index cad43444b5..68e29c0cd4 100644 --- a/include/mkbp_event.h +++ b/include/mkbp_event.h @@ -9,6 +9,15 @@ #define __CROS_EC_MKBP_EVENT_H /* + * Last time the host received an interrupt. + * + * Retrieved via __hw_clock_source_read() as close as possible + * to the interrupt source. Intended to be virtually the same time the + * first line of the AP hard irq for the EC interrupt. + */ +extern uint32_t mkbp_last_event_time; + +/* * Sends an event to the AP. * * When this is called, the event data must be ready for query. Otherwise, |