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 <sensors.h>
22 #include <seos.h>
23 
24 struct Sensor {
25     const struct SensorInfo *si;
26     uint32_t handle;         /* here 0 means invalid */
27     uint64_t currentLatency; /* here 0 means no batching */
28     uint32_t currentRate;    /* here 0 means off */
29     TaggedPtr callInfo;      /* pointer to ops struct or app tid */
30     void *callData;
31     uint32_t initComplete:1; /* sensor finished initializing */
32     uint32_t hasOnchange :1; /* sensor supports onchange and wants to be notified to send new clients current state */
33     uint32_t hasOndemand :1; /* sensor supports ondemand and wants to get triggers */
34 };
35 
36 struct SensorsInternalEvent {
37     union {
38         struct {
39             uint32_t handle;
40             uint32_t value1;
41             uint64_t value2;
42         };
43         struct SensorRateChangeEvent rateChangeEvt;
44         struct SensorPowerEvent externalPowerEvt;
45         struct SensorSetRateEvent externalSetRateEvt;
46         struct SensorCfgDataEvent externalCfgDataEvt;
47         struct SensorSendDirectEventEvent externalSendDirectEvt;
48         struct SensorMarshallUserEventEvent externalMarshallEvt;
49     };
50 };
51 
52 struct SensorsClientRequest {
53     uint32_t handle;
54     uint32_t clientTid;
55     uint64_t latency;
56     uint32_t rate;
57 };
58 
59 #define MAX_INTERNAL_EVENTS       32 //also used for external app sensors' setRate() calls
60 #define MAX_CLI_SENS_MATRIX_SZ    64 /* MAX(numClients * numSensors) */
61 
62 #define SENSOR_RATE_OFF           UINT32_C(0x00000000) /* used in sensor state machine */
63 #define SENSOR_RATE_POWERING_ON   UINT32_C(0xFFFFFFF0) /* used in sensor state machine */
64 #define SENSOR_RATE_POWERING_OFF  UINT32_C(0xFFFFFFF1) /* used in sensor state machine */
65 #define SENSOR_RATE_FW_UPLOADING  UINT32_C(0xFFFFFFF2) /* used in sensor state machine */
66 #define SENSOR_RATE_IMPOSSIBLE    UINT32_C(0xFFFFFFF3) /* used in rate calc to indicate impossible combinations */
67 #define SENSOR_LATENCY_INVALID    UINT64_C(0xFFFFFFFFFFFFFFFF)
68 
69 #define HANDLE_TO_TID(handle) (((handle) >> (32 - TASK_TID_BITS)) & TASK_TID_MASK)
70 #define EXT_APP_TID(s) HANDLE_TO_TID(s->handle)
71 #define LOCAL_APP_OPS(s) ((const struct SensorOps*)taggedPtrToPtr(s->callInfo))
72 #define IS_LOCAL_APP(s) (taggedPtrIsPtr(s->callInfo))
73 
74 struct Sensor* sensorFindByHandle(uint32_t handle);
75 
76 #endif // __SENSORS_PRIV_H__
77