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 #include <stdarg.h> 18 19 #include <gpio.h> 20 #include <osApi.h> 21 #include <sensors.h> 22 #include <seos.h> 23 #include <util.h> 24 25 /* CHRE syscalls */ 26 #include <chre.h> 27 #include <chreApi.h> 28 #include <syscall.h> 29 #include <syscall_defs.h> 30 31 #define SYSCALL_CHRE_API(name) \ 32 SYSCALL_NO(SYSCALL_DOMAIN_CHRE, SYSCALL_CHRE_MAIN, SYSCALL_CHRE_MAIN_API, SYSCALL_CHRE_MAIN_API_ ## name) 33 34 uint64_t chreGetAppId(void) 35 { 36 uint64_t appId = 0; 37 (void)syscallDo1P(SYSCALL_CHRE_API(GET_APP_ID), &appId); 38 return appId; 39 } 40 41 uint32_t chreGetInstanceId(void) 42 { 43 return syscallDo0P(SYSCALL_CHRE_API(GET_INST_ID)); 44 } 45 46 uint64_t chreGetTime(void) { 47 uint64_t time_ns = 0; 48 (void)syscallDo1P(SYSCALL_CHRE_API(GET_TIME), &time_ns); 49 return time_ns; 50 } 51 52 void chreLog(enum chreLogLevel level, const char *str, ...) 53 { 54 va_list vl; 55 56 va_start(vl, str); 57 (void)syscallDo3P(SYSCALL_CHRE_API(LOG), level, str, VA_LIST_TO_INTEGER(vl)); 58 va_end(vl); 59 } 60 61 uint32_t chreTimerSet(uint64_t duration, const void* cookie, bool oneShot) 62 { 63 uint32_t dur_lo = duration; 64 uint32_t dur_hi = duration >> 32; 65 return syscallDo4P(SYSCALL_CHRE_API(TIMER_SET), dur_lo, dur_hi, cookie, oneShot); 66 } 67 68 bool chreTimerCancel(uint32_t timerId) 69 { 70 return syscallDo1P(SYSCALL_CHRE_API(TIMER_CANCEL), timerId); 71 } 72 73 void chreAbort(uint32_t abortCode) 74 { 75 (void)syscallDo1P(SYSCALL_CHRE_API(ABORT), abortCode); 76 } 77 78 void* chreHeapAlloc(uint32_t bytes) 79 { 80 return (void *)syscallDo1P(SYSCALL_CHRE_API(HEAP_ALLOC), bytes); 81 } 82 83 void chreHeapFree(void* ptr) 84 { 85 (void)syscallDo1P(SYSCALL_CHRE_API(HEAP_FREE), ptr); 86 } 87 88 bool chreSensorFindDefault(uint8_t sensorType, uint32_t *handle) 89 { 90 return syscallDo2P(SYSCALL_CHRE_API(SENSOR_FIND_DEFAULT), sensorType, handle); 91 } 92 93 bool chreGetSensorInfo(uint32_t sensorHandle, struct chreSensorInfo *info) 94 { 95 return syscallDo2P(SYSCALL_CHRE_API(SENSOR_GET_INFO), sensorHandle, info); 96 } 97 98 bool chreGetSensorSamplingStatus(uint32_t sensorHandle, 99 struct chreSensorSamplingStatus *status) 100 { 101 return syscallDo2P(SYSCALL_CHRE_API(SENSOR_GET_STATUS), sensorHandle, status); 102 } 103 104 bool chreSensorConfigure(uint32_t sensorHandle, 105 enum chreSensorConfigureMode mode, 106 uint64_t interval, uint64_t latency) 107 { 108 uint32_t interval_lo = interval; 109 uint32_t interval_hi = interval >> 32; 110 uint32_t latency_lo = latency; 111 uint32_t latency_hi = latency >> 32; 112 return syscallDo6P(SYSCALL_CHRE_API(SENSOR_CONFIG), sensorHandle, mode, 113 interval_lo, interval_hi, latency_lo, latency_hi); 114 } 115 116 bool chreSendEvent(uint16_t eventType, void *eventData, 117 chreEventCompleteFunction *freeCallback, 118 uint32_t targetInstanceId) 119 { 120 return syscallDo4P(SYSCALL_CHRE_API(SEND_EVENT), eventType, eventData, freeCallback, targetInstanceId); 121 } 122 123 bool chreSendMessageToHost(void *message, uint32_t messageSize, 124 uint32_t reservedMessageType, 125 chreMessageFreeFunction *freeCallback) 126 { 127 return syscallDo4P(SYSCALL_CHRE_API(SEND_MSG), message, messageSize, reservedMessageType, freeCallback); 128 } 129 130 uint32_t chreGetApiVersion(void) 131 { 132 return syscallDo0P(SYSCALL_CHRE_API(GET_OS_API_VERSION)); 133 } 134 135 uint32_t chreGetVersion(void) 136 { 137 return syscallDo0P(SYSCALL_CHRE_API(GET_OS_VERSION)); 138 } 139 140 uint64_t chreGetPlatformId(void) 141 { 142 uint64_t plat = 0; 143 (void)syscallDo1P(SYSCALL_CHRE_API(GET_PLATFORM_ID), &plat); 144 return plat; 145 } 146