blob: aa7e2537164cc754e7adddd25ea2f2ecccd44998 [file] [log] [blame]
Ashutosh Joshi8c3c46d2016-01-08 16:09:11 -08001/*
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 CONTEXT_HUB_H
18#define CONTEXT_HUB_H
19
20#include <stdint.h>
21#include <sys/cdefs.h>
22#include <sys/types.h>
23
24#include <hardware/hardware.h>
25
26/**
27 * This header file defines the interface of a Context Hub Implementation to
28 * the Android service exposing Context hub capabilities to applications.
29 * The Context hub is expected to a low power compute domain with the following
30 * defining charecteristics -
31 *
32 * 1) Access to sensors like accelerometer, gyroscope, magenetometer.
33 * 2) Access to radios like GPS, Wifi, Bluetooth etc.
34 * 3) Access to low power audio sensing.
35 *
36 * Implementations of this HAL can add additional sensors not defined by the
37 * Android API. Such information sources shall be private to the implementation.
38 *
39 * The Context Hub HAL exposes the construct of code download. A piece of binary
40 * code can be pushed to the context hub through the supported APIs.
41 *
42 * This version of the HAL designs in the possibility of multiple context hubs.
43 */
44
45__BEGIN_DECLS
46
47/*****************************************************************************/
48
49#define CONTEXT_HUB_HEADER_VERSION 1
50#define CONTEXT_HUB_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION_2(1, 0, CONTEXT_HUB_HEADER_VERSION)
51
52/**
53 * The id of this module
54 */
55#define CONTEXT_HUB_MODULE_ID "context_hub"
56
57/**
58 * Name of the device to open
59 */
60#define CONTEXT_HUB_HARDWARE_POLL "ctxt_poll"
61
62/**
63 * Memory types for code upload. Device-specific. At least HUB_MEM_TYPE_MAIN must be supported
64 */
65#define HUB_MEM_TYPE_MAIN 0
66#define HUB_MEM_TYPE_SECONDARY 1
67#define HUB_MEM_TYPE_TCM 2
68
69
70#define HUB_MEM_TYPE_FIRST_VENDOR 0x80000000ul
71
72
73/**
74 * Other memory types (likely not writeable, informational only)
75 */
76#define HUB_MEM_TYPE_BOOTLOADER 0xfffffffful
77#define HUB_MEM_TYPE_OS 0xfffffffeul
78#define HUB_MEM_TYPE_EEDATA 0xfffffffdul
79#define HUB_MEM_TYPE_RAM 0xfffffffcul
80
81/**
82 * Types of memory blocks on the context hub
83 * */
84#define MEM_FLAG_READ 0x1 // Memory can be written to
85#define MEM_FLAG_WRITE 0x2 // Memory can be written to
86#define MEM_FLAG_EXEC 0x4 // Memory can be executed from
87
88/**
89 * The following structure defines each memory block in detail
90 */
91struct mem_range_t {
92 uint32_t total_bytes;
93 uint32_t free_bytes;
94 uint32_t type; // HUB_MEM_TYPE_*
95 uint32_t mem_flags; // MEM_FLAG_*
96};
97
98
99/**
100 * App names may be strings, bytes, uints, etc. This caovers all types of app names
101 */
102struct hub_app_name_t {
103 uint32_t app_name_len;
104 const void *app_name;
105};
106
107struct hub_app_info {
108 const struct hub_app_name_t *name;
109 uint32_t version;
110 uint32_t num_mem_ranges;
111 const struct mem_range_t *mem_usage;
112};
113
114/**
115 * Following enum defines the types of sensors that a hub may declare support
116 * for. Declaration for support would mean that the hub can access and process
117 * data from that particular sensor type.
118 */
119
120typedef enum {
121 CONTEXT_SENSOR_RESERVED, // 0
122 CONTEXT_SENSOR_ACCELEROMETER, // 1
123 CONTEXT_SENSOR_GYROSCOPE, // 2
124 CONTEXT_SENSOR_MAGNETOMETER, // 3
125 CONTEXT_SENSOR_BAROMETER, // 4
126 CONTEXT_SENSOR_PROXIMITY_SENSOR, // 5
127 CONTEXT_SENSOR_AMBIENT_LIGHT_SENSOR, // 6
128
129 CONTEXT_SENSOR_GPS = 0x100, // 0x100
130 // Reserving this space for variants on GPS
131 CONTEXT_SENSOR_WIFI = 0x200, // 0x200
132 // Reserving this space for variants on WIFI
133 CONTEXT_SENSOR_AUDIO = 0x300, // 0x300
134 // Reserving this space for variants on Audio
135 CONTEXT_SENSOR_CAMERA = 0x400, // 0x400
136 // Reserving this space for variants on Camera
137 CONTEXT_SENSOR_BLE = 0x500, // 0x500
138
139 CONTEXT_SENSOR_MAX = 0xffffffff, //make sure enum size is set
140} context_sensor_e;
141
142/**
143 * Sensor types beyond CONTEXT_HUB_TYPE_PRIVATE_SENSOR_BASE are custom types
144 */
145#define CONTEXT_HUB_TYPE_PRIVATE_SENSOR_BASE 0x10000
146
147/**
148 * The following structure describes a sensor
149 */
150struct physical_sensor_description_t {
151 uint32_t sensor_type; // From the definitions above eg: 100
152 const char *type_string; // Type as a string. eg: "GPS"
153 const char *name; // Identifier eg: "Bosch BMI160"
154 const char *vendor; // Vendor : eg "STM"
155 uint32_t version; // Version : eg 0x1001
Greg Kaisere78619b2016-03-03 11:40:03 -0800156 uint32_t fifo_reserved_count; // Batching possible in hardware. Please
Ashutosh Joshi8c3c46d2016-01-08 16:09:11 -0800157 // note that here hardware does not include
Greg Kaisere78619b2016-03-03 11:40:03 -0800158 // the context hub itself. Thus, this
Ashutosh Joshi8c3c46d2016-01-08 16:09:11 -0800159 // definition may be different from say the
160 // number advertised in the sensors HAL
161 // which allows for batching in a hub.
162 uint32_t fifo_max_count; // maximum number of batchable events.
163 uint64_t min_delay_ms; // in milliseconds, corresponding to highest
164 // sampling freq.
165 uint64_t max_delay_ms; // in milliseconds, corresponds to minimum
166 // sampling frequency
167 float peak_power_mw; // At max frequency & no batching, power
168 // in milliwatts
169};
170
171struct connected_sensor_t {
172 uint32_t sensor_id; // identifier for this sensor
173
174 /* This union may be extended to other sensor types */
175 union {
176 struct physical_sensor_description_t physical_sensor;
177 };
178};
179
180
181
182/**
183 * Messages of this length or less must be supported by all implementations,
184 * longer lengths are supported up to max_supported_msg_len. This is exposed
185 * to third party apps, and since we do not know their msg data formats we
186 * cannot fragment for them. Our own messages are allowed to be bigger and
187 * this HAL will fragment as needed. "Our own" messages are messaegs defined
188 * in this file.
189 */
190#define HUB_REQUIRED_SUPPORTED_MSG_LEN 128
191
192struct hub_message_t {
193 const struct hub_app_name_t *app; /* To/From this nanoapp */
194 uint32_t message_type;
195 uint32_t message_len;
196 const void *message;
197};
198
199
200/**
201 * Definition of a context hub. A device may contain more than one low
202 * power domain. In that case, please add an entry for each hub. However,
203 * it is perfectly OK for a device to declare one context hub and manage
204 * them internally as several
205 */
206
207struct context_hub_t {
208 const char *name; // descriptive name eg: "Awesome Hub #1"
209 const char *vendor; // hub hardware vendor eg: "Qualcomm"
210 const char *toolchain; // toolchain to make binaries eg:"gcc ARM"
211 uint32_t platform_version; // Version of the hardware : eg 0x20
212 uint32_t toolchain_version; // Version of the toolchain : eg: 0x484
213 uint32_t hub_id; // a device unique id for this hub
214
215 float peak_mips; // Peak MIPS platform can deliver
216 float stopped_power_draw_mw; // if stopped, retention power, milliwatts
217 float sleep_power_draw_mw; // if sleeping, retention power, milliwatts
218 float peak_power_draw_mw; // for a busy CPUm power in milliwatts
219
220 const struct connected_sensor_t *connected_sensors; // array of connected sensors
221 uint32_t num_connected_sensors; // number of connected sensors
222
223 uint32_t max_supported_msg_len;
224 const struct hub_app_name_t *os_app_name; /* send msgs here for OS functions */
225};
226
227/**
228 * All communication between the context hubs and the Context Hub Service is in
229 * the form of messages. Some message types are distinguished and their
230 * Semantics shall be well defined.
231 * Custom message types should be defined starting above
232 * CONTEXT_HUB_PRIVATE_MSG_BASE
233 */
234
235typedef enum {
236 CONTEXT_HUB_APPS_ENABLE = 1, // 1: Enables the loaded nano-apps
237 CONTEXT_HUB_APPS_DISABLE, // 2: Disables any loaded nano-apps
238 CONTEXT_HUB_LOAD_APP, // 3: Load a supplied app
239 CONTEXT_HUB_UNLOAD_APP, // 4: Unload a specified app
240 CONTEXT_HUB_QUERY_APPS, // 5: Query for apps info on hub (gets struct hub_app_info[])
241 CONTEXT_HUB_QUERY_MEMORY, // 5: Query for memory info (gets struct mem_range_t[])
242 CONTEXT_HUB_LOAD_OS, // 6: Load up OS update
243} hub_messages_e;
244
245#define CONTEXT_HUB_TYPE_PRIVATE_MSG_BASE 0x10000
246
247
248/**
249 * A callback registers with the context hub service to pass messages
250 * coming from the hub to the service/clients.
251 */
252typedef int context_hub_callback(uint32_t hub_id, const struct hub_message_t *rxed_msg, void *cookie);
253
254
255/**
256 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
257 * and the fields of this data structure must begin with hw_module_t
258 * followed by module specific information.
259 */
260struct context_hub_module_t {
261 struct hw_module_t common;
262
263 /**
264 * Enumerate all available hubs.The list is returned in "list".
Dmitry Grinberg90e91402016-02-04 16:43:41 -0800265 * @return result : number of hubs in list or error (negative)
Ashutosh Joshi8c3c46d2016-01-08 16:09:11 -0800266 *
267 * This method shall be called at device bootup.
268 */
269 int (*get_hubs)(struct context_hub_module_t* module, const struct context_hub_t ** list);
270
271 /**
272 * Registers a callback for the HAL implementation to communicate
273 * with the context hub service.
274 * @return result : 0 if successful, error code otherwise
275 */
276 int (*subscribe_messages)(uint32_t hub_id, context_hub_callback cbk, void *cookie);
277
278 /**
279 * Send a message to a hub
280 * @return result : 0 if successful, error code otherwise
281 */
282 int (*send_message)(uint32_t hub_id, const struct hub_message_t *msg);
283
284};
285
286__END_DECLS
287
288#endif // CONTEXT_HUB_SENSORS_INTERFACE_H