motion_sense: Move angle calculation under LPC_MODE

When LPC mode is used, there is an assumption that the first
2 sensors are accelerometers, and the optional 3rd is a gyro.

Put the code that fill lpc_data with #ifdef.
Prevent lpc space corruption if more than 3 sensors are present.

BRANCH=smaug
TEST=Compile. Smaug works
BUG=None

Change-Id: I12c9b823efb57d7b190a1813228f6f02fa0bebcb
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/290073
This commit is contained in:
Gwendal Grignou
2015-07-31 10:54:27 -07:00
committed by ChromeOS Commit Bot
parent 0085573ff4
commit e2f233faaf
2 changed files with 15 additions and 5 deletions

View File

@@ -290,6 +290,7 @@ static inline void set_present(uint8_t *lpc_status)
*lpc_status |= EC_MEMMAP_ACC_STATUS_PRESENCE_BIT;
}
#ifdef CONFIG_LPC
/* Update/Write LPC data */
static inline void update_sense_data(uint8_t *lpc_status,
uint16_t *lpc_data, int *psample_id)
@@ -318,7 +319,8 @@ static inline void update_sense_data(uint8_t *lpc_status,
#else
lpc_data[0] = LID_ANGLE_UNRELIABLE;
#endif
for (i = 0; i < motion_sensor_count; i++) {
/* Assumptions on the list of sensors */
for (i = 0; i < MIN(motion_sensor_count, 3); i++) {
sensor = &motion_sensors[i];
lpc_data[1+3*i] = sensor->xyz[X];
lpc_data[2+3*i] = sensor->xyz[Y];
@@ -333,6 +335,7 @@ static inline void update_sense_data(uint8_t *lpc_status,
EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK;
*lpc_status = EC_MEMMAP_ACC_STATUS_PRESENCE_BIT | *psample_id;
}
#endif
static int motion_sense_read(struct motion_sensor_t *sensor)
{
@@ -407,19 +410,21 @@ void motion_sense_task(void)
{
int i, ret, wait_us, fifo_flush_needed = 0;
timestamp_t ts_begin_task, ts_end_task;
uint8_t *lpc_status;
uint16_t *lpc_data;
uint32_t event = 0;
int sample_id = 0;
int rd_cnt;
struct motion_sensor_t *sensor;
#ifdef CONFIG_ACCEL_FIFO
timestamp_t ts_last_int;
#endif
#ifdef CONFIG_LPC
int sample_id = 0;
uint8_t *lpc_status;
uint16_t *lpc_data;
lpc_status = host_get_memmap(EC_MEMMAP_ACC_STATUS);
lpc_data = (uint16_t *)host_get_memmap(EC_MEMMAP_ACC_DATA);
set_present(lpc_status);
#endif
#ifdef CONFIG_ACCEL_FIFO
ts_last_int = get_time();
@@ -483,7 +488,9 @@ void motion_sense_task(void)
CPRINTF("]\n");
}
#endif
#ifdef CONFIG_LPC
update_sense_data(lpc_status, lpc_data, &sample_id);
#endif
ts_end_task = get_time();
#ifdef CONFIG_ACCEL_FIFO

View File

@@ -90,7 +90,10 @@
/* Unused 0x84 - 0x8f */
#define EC_MEMMAP_ACC_STATUS 0x90 /* Accelerometer status (8 bits )*/
/* Unused 0x91 */
#define EC_MEMMAP_ACC_DATA 0x92 /* Accelerometer data 0x92 - 0x9f */
#define EC_MEMMAP_ACC_DATA 0x92 /* Accelerometers data 0x92 - 0x9f */
/* 0x92: Lid Angle if available, LID_ANGLE_UNRELIABLE otherwise */
/* 0x94 - 0x99: 1st Accelerometer */
/* 0x9a - 0x9f: 2nd Accelerometer */
#define EC_MEMMAP_GYRO_DATA 0xa0 /* Gyroscope data 0xa0 - 0xa5 */
/* Unused 0xa6 - 0xdf */