1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef __SENSORS_PRIV_H__ 18 #define __SENSORS_PRIV_H__ 19 20 #include <inttypes.h> 21 #include <seos.h> 22 23 struct Sensor { 24 const struct SensorInfo *si; 25 uint32_t handle; /* here 0 means invalid */ 26 uint64_t currentLatency; /* here 0 means no batching */ 27 uint32_t currentRate; /* here 0 means off */ 28 TaggedPtr callInfo; /* pointer to ops struct or app tid */ 29 void *callData; 30 uint32_t initComplete:1; /* sensor finished initializing */ 31 uint32_t hasOnchange :1; /* sensor supports onchange and wants to be notified to send new clients current state */ 32 uint32_t hasOndemand :1; /* sensor supports ondemand and wants to get triggers */ 33 }; 34 35 struct SensorsInternalEvent { 36 union { 37 struct { 38 uint32_t handle; 39 uint32_t value1; 40 uint64_t value2; 41 }; 42 struct SensorRateChangeEvent rateChangeEvt; 43 struct SensorPowerEvent externalPowerEvt; 44 struct SensorSetRateEvent externalSetRateEvt; 45 struct SensorCfgDataEvent externalCfgDataEvt; 46 struct SensorSendDirectEventEvent externalSendDirectEvt; 47 struct SensorMarshallUserEventEvent externalMarshallEvt; 48 }; 49 }; 50 51 struct SensorsClientRequest { 52 uint32_t handle; 53 uint32_t clientTid; 54 uint64_t latency; 55 uint32_t rate; 56 }; 57 58 #define MAX_INTERNAL_EVENTS 32 //also used for external app sensors' setRate() calls 59 #define MAX_CLI_SENS_MATRIX_SZ 64 /* MAX(numClients * numSensors) */ 60 61 #define SENSOR_RATE_OFF UINT32_C(0x00000000) /* used in sensor state machine */ 62 #define SENSOR_RATE_POWERING_ON UINT32_C(0xFFFFFFF0) /* used in sensor state machine */ 63 #define SENSOR_RATE_POWERING_OFF UINT32_C(0xFFFFFFF1) /* used in sensor state machine */ 64 #define SENSOR_RATE_FW_UPLOADING UINT32_C(0xFFFFFFF2) /* used in sensor state machine */ 65 #define SENSOR_RATE_IMPOSSIBLE UINT32_C(0xFFFFFFF3) /* used in rate calc to indicate impossible combinations */ 66 #define SENSOR_LATENCY_INVALID UINT64_C(0xFFFFFFFFFFFFFFFF) 67 68 #define HANDLE_TO_TID(handle) (((handle) >> (32 - TASK_TID_BITS)) & TASK_TID_MASK) 69 #define EXT_APP_TID(s) HANDLE_TO_TID(s->handle) 70 #define LOCAL_APP_OPS(s) ((const struct SensorOps*)taggedPtrToPtr(s->callInfo)) 71 #define IS_LOCAL_APP(s) (taggedPtrIsPtr(s->callInfo)) 72 73 struct Sensor* sensorFindByHandle(uint32_t handle); 74 75 #endif // __SENSORS_PRIV_H__ 76