static void motion_sense_insert_timestamp(void) { struct ec_response_motion_sensor_data vector; vector.flags = MOTIONSENSE_SENSOR_FLAG_TIMESTAMP; vector.timestamp = __hw_clock_source_read(); motion_sense_fifo_add_unit(&vector, motion_sensors, 0); }
static int motion_sense_process(struct motion_sensor_t *sensor, uint32_t event, const timestamp_t *ts, int *flush_needed) { int ret = EC_SUCCESS; #ifdef CONFIG_ACCEL_INTERRUPTS if ((event & TASK_EVENT_MOTION_INTERRUPT_MASK) && (sensor->drv->irq_handler != NULL)) { sensor->drv->irq_handler(sensor, event); sensor->last_collection = ts->le.lo; } #endif #ifdef CONFIG_ACCEL_FIFO if (sensor->drv->load_fifo != NULL) { /* Load fifo is filling raw_xyz sensor vector */ sensor->drv->load_fifo(sensor); } else if (motion_sensor_time_to_read(ts, sensor)) { struct ec_response_motion_sensor_data vector; ret = motion_sense_read(sensor); if (ret == EC_SUCCESS) { vector.flags = 0; vector.data[X] = sensor->raw_xyz[X]; vector.data[Y] = sensor->raw_xyz[Y]; vector.data[Z] = sensor->raw_xyz[Z]; motion_sense_fifo_add_unit(&vector, sensor, 3); sensor->last_collection = ts->le.lo; } } else { ret = EC_ERROR_BUSY; } if (event & TASK_EVENT_MOTION_FLUSH_PENDING) { int flush_pending; flush_pending = atomic_read_clear(&sensor->flush_pending); for (; flush_pending > 0; flush_pending--) { *flush_needed = 1; motion_sense_insert_flush(sensor); } } #else if (motion_sensor_time_to_read(ts, sensor)) { /* Get latest data for local calculation */ ret = motion_sense_read(sensor); } else { ret = EC_ERROR_BUSY; } if (ret == EC_SUCCESS) { sensor->last_collection = ts->le.lo; mutex_lock(&g_sensor_mutex); memcpy(sensor->xyz, sensor->raw_xyz, sizeof(sensor->xyz)); mutex_unlock(&g_sensor_mutex); } #endif return ret; }
static int si114x_read_results(struct motion_sensor_t *s, int nb) { int i, ret, val; struct si114x_drv_data_t *data = SI114X_GET_DATA(s); struct si114x_typed_data_t *type_data = SI114X_GET_TYPED_DATA(s); #ifdef CONFIG_ACCEL_FIFO struct ec_response_motion_sensor_data vector; #endif /* Read ALX result */ for (i = 0; i < nb; i++) { ret = raw_read16(s->port, s->addr, type_data->base_data_reg + i * 2, &val); if (ret) break; /* Add offset, calibration */ if (val + type_data->offset <= 0) { val = 1; } else if (val != SI114X_OVERFLOW) { val += type_data->offset; /* * Proxmitiy sensor data is inverse of the distance. * Return back something proportional to distance, * we affine with the scale parmeter. */ if (s->type == MOTIONSENSE_TYPE_PROX) val = SI114X_PS_INVERSION(val); val = val * type_data->scale + val * type_data->uscale / 10000; } s->raw_xyz[i] = val; } if (ret != EC_SUCCESS) return ret; if (s->type == MOTIONSENSE_TYPE_PROX) data->covered = (s->raw_xyz[0] < SI114X_COVERED_THRESHOLD); else if (data->covered) /* * The sensor (proximity & light) is covered. The light data * will most likely be incorrect (darker than expected), so * ignore the measurement. */ return EC_SUCCESS; /* Add in fifo if changed only */ for (i = 0; i < nb; i++) { if (s->raw_xyz[i] != s->xyz[i]) break; } if (i == nb) return EC_SUCCESS; #ifdef CONFIG_ACCEL_FIFO vector.flags = 0; for (i = 0; i < nb; i++) vector.data[i] = s->raw_xyz[i]; for (i = nb; i < 3; i++) vector.data[i] = 0; vector.sensor_num = s - motion_sensors; motion_sense_fifo_add_unit(&vector, s, nb); #else /* We need to copy raw_xyz into xyz with mutex */ #endif return EC_SUCCESS; }