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