rambi: Add acceleration data to LPC shared memory

After each read of the accelerometers, add accelerometer
data to LPC shared memory.

BUG=none
Original-BUG=chrome-os-partner:25599
BRANCH=rambi
TEST=Manual test by reading the LPC shared memory through cros_ec
in the kernel.

Original-Change-Id: If66df3fcb32b5423f4fa7dd471c219a1c4df7095
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/186456
Reviewed-by: Randall Spangler <rspangler@chromium.org>
(cherry picked from commit 919ea7fe1f830235ae56829a8ee4435679dec124)

Change-Id: I10525c45e868d0b04aa84c27cab3b6baeda2b0d5
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/187435
Reviewed-by: Randall Spangler <rspangler@chromium.org>
This commit is contained in:
Alec Berg
2014-02-13 14:16:17 -08:00
committed by chrome-internal-fetch
parent 89cae30e57
commit ff711e4a47
2 changed files with 51 additions and 8 deletions

View File

@@ -9,6 +9,7 @@
#include "common.h"
#include "console.h"
#include "hooks.h"
#include "host_command.h"
#include "math_util.h"
#include "motion_sense.h"
#include "timer.h"
@@ -33,6 +34,11 @@ static int accel_interval_ms = 250;
static int accel_disp;
#endif
/* For vector_3_t, define which coordinates are in which location. */
enum {
X, Y, Z
};
/* Pointer to constant acceleration orientation data. */
const struct accel_orientation * const p_acc_orient = &acc_orient;
@@ -116,6 +122,12 @@ void motion_sense_task(void)
timestamp_t ts0, ts1;
int wait_us;
int ret;
uint8_t *lpc_status;
uint16_t *lpc_data;
int sample_id = 0;
lpc_status = host_get_memmap(EC_MEMMAP_ACC_STATUS);
lpc_data = (uint16_t *)host_get_memmap(EC_MEMMAP_ACC_DATA);
/* Initialize accelerometers. */
ret = accel_init(ACCEL_LID);
@@ -132,10 +144,10 @@ void motion_sense_task(void)
ts0 = get_time();
/* Read all accelerations. */
accel_read(ACCEL_LID, &acc_lid_raw[0], &acc_lid_raw[1],
&acc_lid_raw[2]);
accel_read(ACCEL_BASE, &acc_base[0], &acc_base[1],
&acc_base[2]);
accel_read(ACCEL_LID, &acc_lid_raw[X], &acc_lid_raw[Y],
&acc_lid_raw[Z]);
accel_read(ACCEL_BASE, &acc_base[X], &acc_base[Y],
&acc_base[Z]);
/*
* Rotate the lid vector so the reference frame aligns with
@@ -149,16 +161,41 @@ void motion_sense_task(void)
/* TODO(crosbug.com/p/25597): Add filter to smooth lid angle. */
/*
* TODO(crosbug.com/p/25599): Add acceleration data to LPC
* shared memory.
* Set the busy bit before writing the sensor data. Increment
* the counter and clear the busy bit after writing the sensor
* data. On the host side, the host needs to make sure the busy
* bit is not set and that the counter remains the same before
* and after reading the data.
*/
*lpc_status |= EC_MEMMAP_ACC_STATUS_BUSY_BIT;
/*
* Copy sensor data to shared memory. Note that this code
* assumes little endian, which is what the host expects.
*/
lpc_data[0] = (int)lid_angle_deg;
lpc_data[1] = acc_base[X];
lpc_data[2] = acc_base[Y];
lpc_data[3] = acc_base[Z];
lpc_data[4] = acc_lid[X];
lpc_data[5] = acc_lid[Y];
lpc_data[6] = acc_lid[Z];
/*
* Increment sample id and clear busy bit to signal we finished
* updating data.
*/
sample_id = (sample_id + 1) &
EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK;
*lpc_status = sample_id;
#ifdef CONFIG_CMD_LID_ANGLE
if (accel_disp) {
CPRINTF("[%T ACC base=%-5d, %-5d, %-5d lid=%-5d, "
"%-5d, %-5d a=%-6.1d]\n",
acc_base[0], acc_base[1], acc_base[2],
acc_lid[0], acc_lid[1], acc_lid[2],
acc_base[X], acc_base[Y], acc_base[Z],
acc_lid[X], acc_lid[Y], acc_lid[Z],
(int)(10*lid_angle_deg));
}
#endif

View File

@@ -82,6 +82,12 @@
#define EC_MEMMAP_BATT_SERIAL 0x70 /* Battery Serial Number String */
#define EC_MEMMAP_BATT_TYPE 0x78 /* Battery Type String */
#define EC_MEMMAP_ALS 0x80 /* ALS readings in lux (uint16_t) */
#define EC_MEMMAP_ACC_STATUS 0x90 /* Accelerometer status */
#define EC_MEMMAP_ACC_DATA 0x92 /* Accelerometer data 0x92 - 0xa5 */
/* Define the format of the accelerometer mapped memory status byte. */
#define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f
#define EC_MEMMAP_ACC_STATUS_BUSY_BIT (1 << 4)
/* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */
#define EC_TEMP_SENSOR_ENTRIES 16