• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 EVENTNUMS_H
18 #define EVENTNUMS_H
19 
20 #include <stdint.h>
21 #include "toolchain.h"
22 
23 /* These define ranges of reserved events */
24 // local events are 16-bit always
25 #define EVT_NO_FIRST_USER_EVENT          0x00000100    //all events lower than this are reserved for the OS. all of them are nondiscardable necessarily!
26 #define EVT_NO_FIRST_SENSOR_EVENT        0x00000200    //sensor type SENSOR_TYPE_x produces events of type EVT_NO_FIRST_SENSOR_EVENT + SENSOR_TYPE_x for all Google-defined sensors
27 #define EVT_NO_SENSOR_CONFIG_EVENT       0x00000300    //event to configure sensors
28 #define EVT_APP_START                    0x00000400    //sent when an app can actually start
29 #define EVT_APP_TO_HOST                  0x00000401    //app data to host. Type is struct HostHubRawPacket
30 #define EVT_MARSHALLED_SENSOR_DATA       0x00000402    //marshalled event data. Type is MarshalledUserEventData
31 #define EVT_RESET_REASON                 0x00000403    //reset reason to host.
32 #define EVT_APP_TO_SENSOR_HAL_DATA       0x00000404    //sensor driver out of band data update to sensor hal
33 #define EVT_APP_STARTED                  0x00000405    //sent when a app has successfully started
34 #define EVT_APP_STOPPED                  0x00000406    //sent when a app has stopped
35 #define EVT_APP_TO_HOST_CHRE             0x00000407    //app data to host. Type is struct HostHubChrePacket
36 #define EVT_DEBUG_LOG                    0x00007F01    //send message payload to Linux kernel log
37 #define EVT_MASK                         0x0000FFFF
38 
39 // host-side events are 32-bit
40 
41 // DEBUG_LOG_EVT is normally undefined, or defined with a special value, recognized by nanohub driver: 0x3B474F4C
42 // if defined with this value, the log message payload will appear in Linux kernel message log.
43 // If defined with other value, it will still be sent to nanohub driver, and then forwarded to userland
44 // verbatim, where it could be logged by nanohub HAL (by turning on it's logging via 'setprop persist.nanohub.debug 1'
45 #ifdef DEBUG_LOG_EVT
46 #define HOST_EVT_DEBUG_LOG               DEBUG_LOG_EVT
47 #endif
48 
49 #define HOST_HUB_RAW_PACKET_MAX_LEN      128
50 
51 SET_PACKED_STRUCT_MODE_ON
52 struct HostHubRawPacket {
53     uint64_t appId;
54     uint8_t dataLen; //not incl this header, 128 bytes max
55     //raw data in unspecified format here
56 }ATTRIBUTE_PACKED;
57 SET_PACKED_STRUCT_MODE_OFF
58 
59 #define HOST_HUB_CHRE_PACKET_MAX_LEN     128
60 
61 SET_PACKED_STRUCT_MODE_ON
62 struct HostHubChrePacket {
63     uint64_t appId;
64     uint8_t messageSize; //not incl this header, 128 bytes max
65     uint32_t messageType;
66     uint16_t hostEndpoint;
67     //raw data in unspecified format here
68 }ATTRIBUTE_PACKED;
69 SET_PACKED_STRUCT_MODE_OFF
70 
71 SET_PACKED_STRUCT_MODE_ON
72 struct NanohubMsgChreHdrV10 {
73     uint8_t size;
74     uint32_t appEvent;
75 }ATTRIBUTE_PACKED;
76 SET_PACKED_STRUCT_MODE_OFF
77 
78 SET_PACKED_STRUCT_MODE_ON
79 struct NanohubMsgChreHdr {
80     uint8_t size;
81     uint32_t appEvent;
82     uint16_t endpoint;
83 }ATTRIBUTE_PACKED;
84 SET_PACKED_STRUCT_MODE_OFF
85 
86 SET_PACKED_STRUCT_MODE_ON
87 struct MarshalledUserEventData {
88     //for matching
89     uint32_t origEvtType;
90 
91     int32_t dataLen;  //use negative here to indicate marshalling error.
92     //raw data in unspecified format here
93 
94 }ATTRIBUTE_PACKED;
95 SET_PACKED_STRUCT_MODE_OFF
96 
97 
98 /*
99  * When sensor drivers use EVT_APP_TO_HOST, e.g. for reporting calibration data,
100  * the data segment of struct HostHubRawPacket is strongly recommended to begin
101  * with this header to allow for common parsing. But this is not a requirement,
102  * as these messages are inherently application-specific.
103  */
104 SET_PACKED_STRUCT_MODE_ON
105 struct SensorAppEventHeader {
106     uint8_t msgId;
107     uint8_t sensorType;
108     uint8_t status; // 0 for success, else application-specific error code
109 }ATTRIBUTE_PACKED;
110 SET_PACKED_STRUCT_MODE_OFF
111 
112 #define SENSOR_APP_EVT_STATUS_SUCCESS    0x00
113 #define SENSOR_APP_EVT_STATUS_ERROR      0x01 // General failure
114 #define SENSOR_APP_EVT_STATUS_BUSY       0x02
115 
116 #define SENSOR_APP_MSG_ID_CAL_RESULT     0x00 // Status of calibration, with resulting biases
117 #define SENSOR_APP_MSG_ID_TEST_RESULT    0x01 // Status of self-test
118 
119 /*
120  * These events are in private OS-reserved range, and are sent targettedly
121  * to one app. This is OK since real OS-reserved internal events will never
122  * go to apps, as that region is reserved for them. We thus achieve succesful
123  * overloading of the range.
124  */
125 
126 //for all apps
127 #define EVT_APP_FREE_EVT_DATA            0x000000FF    //sent to an external app when its event has been marked for freeing. Data: struct AppEventFreeData
128 // this event is never enqueued; it goes directly to the app.
129 // It notifies app that have outstanding IO, that is is about to end;
130 // Expected app behavior is to not send any more events to system;
131 // any events sent after this point will be silently ignored by the system;
132 // any outstanding events will be allowed to proceed to completion. (this is SIG_STOP)
133 #define EVT_APP_STOP                     0x000000FE
134 // Internal event, with task pointer as event data;
135 // system ends the task unconditionally; no further checks performed (this is SIG_KILL)
136 #define EVT_APP_END                      0x000000FD
137 #define EVT_APP_BEGIN                    0x000000FC
138 //for host comms
139 #define EVT_APP_FROM_HOST_CHRE           0x000000F9    //host data to an app. Type is struct HostMsgHdrChre
140 #define EVT_APP_FROM_HOST                0x000000F8    //host data to an app. Type is struct HostMsgHdr
141 
142 //for apps that use I2C
143 #define EVT_APP_I2C_CBK                  0x000000F0    //data pointer points to struct I2cEventData
144 
145 //for apps that claim to be a sensor
146 #define EVT_APP_SENSOR_POWER             0x000000EF    //data pointer is not a pointer, it is a bool encoded as (void*)
147 #define EVT_APP_SENSOR_FW_UPLD           0x000000EE
148 #define EVT_APP_SENSOR_SET_RATE          0x000000ED    //data pointer points to a "const struct SensorSetRateEvent"
149 #define EVT_APP_SENSOR_FLUSH             0x000000EC
150 #define EVT_APP_SENSOR_TRIGGER           0x000000EB
151 #define EVT_APP_SENSOR_CALIBRATE         0x000000EA
152 #define EVT_APP_SENSOR_CFG_DATA          0x000000E9
153 #define EVT_APP_SENSOR_SEND_ONE_DIR_EVT  0x000000E8
154 #define EVT_APP_SENSOR_MARSHALL          0x000000E7    // for external sensors that send events of "user type"
155 #define EVT_APP_SENSOR_SELF_TEST         0x000000E6
156 
157 //for timers
158 #define EVT_APP_TIMER                    0x000000DF
159 
160 #endif /* EVENTNUMS_H */
161