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 __HOSTINTF_H
18 #define __HOSTINTF_H
19 
20 #include <stdint.h>
21 #include <atomicBitset.h>
22 #include <sensors.h>
23 #include "toolchain.h"
24 
25 /**
26  * System-facing hostIntf API
27  */
28 
29 #define HOSTINTF_MAX_INTERRUPTS     256
30 #define HOSTINTF_SENSOR_DATA_MAX    240
31 
32 enum HostIntfDataType
33 {
34     HOSTINTF_DATA_TYPE_LOG,
35     HOSTINTF_DATA_TYPE_APP_TO_HOST,
36     HOSTINTF_DATA_TYPE_RESET_REASON,
37     HOSTINTF_DATA_TYPE_APP_TO_SENSOR_HAL,         // for config data upload
38 };
39 
40 SET_PACKED_STRUCT_MODE_ON
41 struct HostIntfDataBuffer
42 {
43     union
44     {
45         struct
46         {
47             uint8_t sensType;
48             uint8_t length;
49             uint8_t dataType;
50             uint8_t interrupt;
51         };
52         uint32_t evtType;
53     };
54     union
55     {
56         struct
57         {
58             uint64_t referenceTime;
59             union
60             {
61                 struct SensorFirstSample firstSample;
62                 struct SingleAxisDataPoint single[HOSTINTF_SENSOR_DATA_MAX / sizeof(struct SingleAxisDataPoint)];
63                 struct TripleAxisDataPoint triple[HOSTINTF_SENSOR_DATA_MAX / sizeof(struct TripleAxisDataPoint)];
64                 struct RawTripleAxisDataPoint rawTriple[HOSTINTF_SENSOR_DATA_MAX / sizeof(struct RawTripleAxisDataPoint)];
65             };
66         };
67         uint8_t buffer[sizeof(uint64_t) + HOSTINTF_SENSOR_DATA_MAX];
68     };
69 } ATTRIBUTE_PACKED;
70 SET_PACKED_STRUCT_MODE_OFF
71 
72 void hostIntfCopyInterrupts(void *dst, uint32_t numBits);
73 void hostIntfClearInterrupts();
74 void hostIntfSetInterrupt(uint32_t bit);
75 bool hostIntfGetInterrupt(uint32_t bit);
76 void hostIntfClearInterrupt(uint32_t bit);
77 void hostIntfSetInterruptMask(uint32_t bit);
78 bool hostIntfGetInterruptMask(uint32_t bit);
79 void hostIntfClearInterruptMask(uint32_t bit);
80 void hostIntfPacketFree(void *ptr);
81 bool hostIntfPacketDequeue(void *ptr, uint32_t *wakeup, uint32_t *nonwakeup);
82 void hostIntfSetBusy(bool busy);
83 void hostIntfRxPacket(bool wakeupActive);
84 void hostIntfTxAck(void *buffer, uint8_t len);
85 
86 #endif /* __HOSTINTF_H */
87