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_DEBUG_LOG 0x00007F01 // send message payload to Linux kernel log 34 #define EVT_MASK 0x0000FFFF 35 36 // host-side events are 32-bit 37 38 // DEBUG_LOG_EVT is normally undefined, or defined with a special value, recognized by nanohub driver: 0x3B474F4C 39 // if defined with this value, the log message payload will appear in Linux kernel message log. 40 // If defined with other value, it will still be sent to nanohub driver, and then forwarded to userland 41 // verbatim, where it could be logged by nanohub HAL (by turning on it's logging via 'setprop persist.nanohub.debug 1' 42 #ifdef DEBUG_LOG_EVT 43 #define HOST_EVT_DEBUG_LOG DEBUG_LOG_EVT 44 #endif 45 46 #define HOST_HUB_RAW_PACKET_MAX_LEN 128 47 48 SET_PACKED_STRUCT_MODE_ON 49 struct HostHubRawPacket { 50 uint64_t appId; 51 uint8_t dataLen; //not incl this header, 128 bytes max 52 //raw data in unspecified format here 53 }ATTRIBUTE_PACKED; 54 SET_PACKED_STRUCT_MODE_OFF 55 56 SET_PACKED_STRUCT_MODE_ON 57 struct NanohubMsgChreHdr { 58 uint8_t size; 59 uint32_t appEvent; 60 }ATTRIBUTE_PACKED; 61 SET_PACKED_STRUCT_MODE_OFF 62 63 SET_PACKED_STRUCT_MODE_ON 64 struct MarshalledUserEventData { 65 //for matching 66 uint32_t origEvtType; 67 68 int32_t dataLen; //use negative here to indicate marshalling error. 69 //raw data in unspecified format here 70 71 }ATTRIBUTE_PACKED; 72 SET_PACKED_STRUCT_MODE_OFF 73 74 75 /* 76 * When sensor drivers use EVT_APP_TO_HOST, e.g. for reporting calibration data, 77 * the data segment of struct HostHubRawPacket is strongly recommended to begin 78 * with this header to allow for common parsing. But this is not a requirement, 79 * as these messages are inherently application-specific. 80 */ 81 SET_PACKED_STRUCT_MODE_ON 82 struct SensorAppEventHeader { 83 uint8_t msgId; 84 uint8_t sensorType; 85 uint8_t status; // 0 for success, else application-specific error code 86 }ATTRIBUTE_PACKED; 87 SET_PACKED_STRUCT_MODE_OFF 88 89 #define SENSOR_APP_EVT_STATUS_SUCCESS 0x00 90 #define SENSOR_APP_EVT_STATUS_ERROR 0x01 // General failure 91 #define SENSOR_APP_EVT_STATUS_BUSY 0x02 92 93 #define SENSOR_APP_MSG_ID_CAL_RESULT 0x00 // Status of calibration, with resulting biases 94 #define SENSOR_APP_MSG_ID_TEST_RESULT 0x01 // Status of self-test 95 96 /* 97 * These events are in private OS-reserved range, and are sent targettedly 98 * to one app. This is OK since real OS-reserved internal events will never 99 * go to apps, as that region is reserved for them. We thus achieve succesful 100 * overloading of the range. 101 */ 102 103 //for all apps 104 #define EVT_APP_FREE_EVT_DATA 0x000000FF //sent to an external app when its event has been marked for freeing. Data: struct AppEventFreeData 105 // this event is never enqueued; it goes directly to the app. 106 // It notifies app that hav outstanding IO, that is is about to end; 107 // Expected app behavior is to not send any more events to system; 108 // any events sent after this point will be silently ignored by the system; 109 // any outstading events will be allowed to proceed to completion. (this is SIG_STOP) 110 #define EVT_APP_STOP 0x000000FE 111 // Internal event, with task pointer as event data; 112 // system ends the task unconditionally; no further checks performed (this is SIG_KILL) 113 #define EVT_APP_END 0x000000FD 114 //for host comms 115 #define EVT_APP_FROM_HOST 0x000000F8 //host data to an app. Type is struct HostMsgHdr 116 #define EVT_APP_FROM_HOST_CHRE 0x000000F9 //host data to an app. Type is struct HostMsgHdrChre 117 118 //for apps that use I2C 119 #define EVT_APP_I2C_CBK 0x000000F0 //data pointer points to struct I2cEventData 120 121 //for apps that claim to be a sensor 122 #define EVT_APP_SENSOR_POWER 0x000000EF //data pointer is not a pointer, it is a bool encoded as (void*) 123 #define EVT_APP_SENSOR_FW_UPLD 0x000000EE 124 #define EVT_APP_SENSOR_SET_RATE 0x000000ED //data pointer points to a "const struct SensorSetRateEvent" 125 #define EVT_APP_SENSOR_FLUSH 0x000000EC 126 #define EVT_APP_SENSOR_TRIGGER 0x000000EB 127 #define EVT_APP_SENSOR_CALIBRATE 0x000000EA 128 #define EVT_APP_SENSOR_CFG_DATA 0x000000E9 129 #define EVT_APP_SENSOR_SEND_ONE_DIR_EVT 0x000000E8 130 #define EVT_APP_SENSOR_MARSHALL 0x000000E7 // for external sensors that send events of "user type" 131 #define EVT_APP_SENSOR_SELF_TEST 0x000000E6 132 133 //for timers 134 #define EVT_APP_TIMER 0x000000DF 135 136 #endif /* EVENTNUMS_H */ 137