Quinn Male | 2e88375 | 2019-03-22 11:28:54 -0700 | [diff] [blame] | 1 | /* st_common_defs.h |
| 2 | * |
Zhou Song | ebe8a93 | 2020-02-10 12:18:31 +0800 | [diff] [blame] | 3 | * Copyright (c) 2016-2020, The Linux Foundation. All rights reserved. |
Quinn Male | 2e88375 | 2019-03-22 11:28:54 -0700 | [diff] [blame] | 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are |
| 7 | * met: |
| 8 | * * Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * * Redistributions in binary form must reproduce the above |
| 11 | * copyright notice, this list of conditions and the following |
| 12 | * disclaimer in the documentation and/or other materials provided |
| 13 | * with the distribution. |
| 14 | * * Neither the name of The Linux Foundation nor the names of its |
| 15 | * contributors may be used to endorse or promote products derived |
| 16 | * from this software without specific prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 19 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 20 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 22 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 25 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 27 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 28 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | #ifndef ST_COMMON_DEFS_H |
| 31 | #define ST_COMMON_DEFS_H |
| 32 | |
| 33 | #include <stdbool.h> |
| 34 | #include <dlfcn.h> |
| 35 | |
| 36 | /* #define VERY_VERBOSE_LOGGING */ |
| 37 | #ifdef VERY_VERBOSE_LOGGING |
| 38 | #define ALOGVV ALOGV |
| 39 | #else |
| 40 | #define ALOGVV(a...) do { } while(0) |
| 41 | #endif |
| 42 | |
| 43 | #define NSECS_PER_MSEC (1000000LL) |
| 44 | #define NSECS_PER_SEC (1000000000LL) |
| 45 | |
| 46 | #define SOUND_TRIGGER_APE_BUFFER_DURATION_MS (480) |
| 47 | #define SOUND_TRIGGER_PCM_BUFFER_DURATION_MS (160) |
| 48 | |
| 49 | #define SOUND_TRIGGER_CPE_LAB_DRV_BUF_DURATION_MS (240) |
| 50 | #define ST_GRAPHITE_LAB_BUF_DURATION_MS (480) |
| 51 | |
| 52 | #define SOUND_TRIGGER_SAMPLING_RATE_16000 (16000) |
| 53 | #define SOUND_TRIGGER_SAMPLING_RATE_48000 (48000) |
| 54 | #define SOUND_TRIGGER_SAMPLING_RATE_384000 (384000) |
| 55 | |
| 56 | #define SOUND_TRIGGER_CHANNEL_MODE_MONO (1) |
| 57 | #define SOUND_TRIGGER_CHANNEL_MODE_STEREO (2) |
| 58 | #define SOUND_TRIGGER_CHANNEL_MODE_TRI (3) |
| 59 | #define SOUND_TRIGGER_CHANNEL_MODE_QUAD (4) |
| 60 | #define SOUND_TRIGGER_CHANNEL_MODE_HEX (6) |
| 61 | #define SOUND_TRIGGER_CHANNEL_MODE_OCT (8) |
| 62 | |
| 63 | #define SOUND_TRIGGER_BIT_WIDTH (16) |
| 64 | |
| 65 | #define ST_READ_WAIT_TIME_OUT_SEC (2) |
| 66 | |
| 67 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) |
| 68 | #define MAX(a, b) ((a) > (b) ? (a) : (b)) |
| 69 | #define SET_BIT(a, b) (a |= b) |
| 70 | #define CLEAR_BIT(a, b) (a &= ~(b)) |
| 71 | #define CHECK_BIT(a, b) ((a) & (b)) |
| 72 | |
| 73 | #define SET_STATE(a, b) SET_BIT(a, b) |
| 74 | #define CLEAR_STATE(a, b) CLEAR_BIT(a, b) |
| 75 | #define CHECK_STATE(a, b) CHECK_BIT(a, b) |
| 76 | |
| 77 | #define ALIGN(number, align) \ |
| 78 | ((number + align - 1) & ~(align - 1)) |
| 79 | #define CALCULATE_PERIOD_SIZE(duration_ms, sample_rate, period_cnt, align) \ |
| 80 | (ALIGN(((sample_rate * duration_ms) /(period_cnt * 1000)), align)) |
| 81 | |
| 82 | #define GET_WAIT_TIMESPEC(timeout, wait_time) \ |
| 83 | do {\ |
| 84 | clock_gettime(CLOCK_MONOTONIC, &timeout); \ |
| 85 | timeout.tv_sec += wait_time / NSECS_PER_SEC; \ |
| 86 | timeout.tv_nsec += wait_time % NSECS_PER_SEC; \ |
| 87 | if (timeout.tv_nsec >= NSECS_PER_SEC) { \ |
| 88 | timeout.tv_sec += 1; \ |
| 89 | timeout.tv_nsec -= NSECS_PER_SEC; \ |
| 90 | } \ |
| 91 | } while(0) |
| 92 | |
| 93 | /* fwk mode definitions */ |
| 94 | #define SOUND_TRIGGER_EVENT_NON_TIME_STAMP_MODE (0) |
| 95 | #define SOUND_TRIGGER_EVENT_TIME_STAMP_MODE (1) |
| 96 | |
| 97 | #define DEFAULT_CUSTOM_CONFIG_MINOR_VERSION (2) |
| 98 | #define CUSTOM_CONFIG_OPAQUE_DATA_SIZE (12) |
| 99 | #define MAX_LIB_HANDLE_SIZE (64) |
| 100 | #define KW_LEN_WARNING (500) |
| 101 | #define PREROLL_LEN_WARNING (150) |
| 102 | #define GENERIC_DET_EVENT_HEADER_SIZE (8) |
| 103 | #define FIRST_STAGE_KW_START_TOLERANCE_MS (300) |
| 104 | #define FIRST_STAGE_KW_END_TOLERANCE_MS (240) |
Zhou Song | ebe8a93 | 2020-02-10 12:18:31 +0800 | [diff] [blame] | 105 | #define VOP_DATA_BEFORE_TRUE_KW_START_MS (360) |
Quinn Male | 2e88375 | 2019-03-22 11:28:54 -0700 | [diff] [blame] | 106 | #define CNN_DATA_AFTER_TRUE_KW_END_MS (200) |
| 107 | #define GENERIC_DET_EVENT_USER_LEVEL_OFFSET (17) |
| 108 | #define GCS_NON_GENERIC_USER_LEVEL_OFFSET (3) |
| 109 | #define LSM_NON_GENERIC_USER_LEVEL_OFFSET (1) |
| 110 | #define GENERIC_DET_EVENT_KW_START_OFFSET (3) |
| 111 | #define GENERIC_DET_EVENT_KW_END_OFFSET (4) |
| 112 | #define CONF_LEVELS_INTF_VERSION_0002 (0x02) |
| 113 | |
| 114 | #define KEY_ID_CONFIDENCE_LEVELS (0x2000) |
| 115 | #define KEY_ID_KEYWORD_POSITION_STATS (0x2001) |
Quinn Male | 5874945 | 2020-03-26 17:14:56 -0700 | [diff] [blame] | 116 | #define KEY_ID_TIMESTAMP_INFO (0x2002) |
| 117 | #define KEY_ID_MULTI_MODEL_RESULT_INFO (0x2004) |
Quinn Male | 2e88375 | 2019-03-22 11:28:54 -0700 | [diff] [blame] | 118 | |
| 119 | #define DLSYM(handle, ptr, symbol, err) \ |
| 120 | do {\ |
| 121 | err = 0;\ |
| 122 | ptr = dlsym(handle, #symbol);\ |
| 123 | if (ptr == NULL) {\ |
| 124 | ALOGW("%s: %s not found. %s", __func__, #symbol, dlerror());\ |
| 125 | err = -ENODEV;\ |
| 126 | }\ |
| 127 | } while(0) |
| 128 | |
| 129 | typedef enum { |
| 130 | ST_DEVICE_HW_NONE, |
| 131 | ST_DEVICE_HW_APE, |
| 132 | ST_DEVICE_HW_CPE, |
| 133 | ST_DEVICE_HW_ARM |
| 134 | }st_hw_type_t; |
| 135 | |
| 136 | typedef enum st_exec_mode { |
| 137 | ST_EXEC_MODE_NONE = -1, |
| 138 | ST_EXEC_MODE_ADSP, |
| 139 | ST_EXEC_MODE_CPE, |
| 140 | ST_EXEC_MODE_ARM, |
| 141 | ST_EXEC_MODE_MAX |
| 142 | } st_exec_mode_t; |
| 143 | |
| 144 | /* defines possible configuration modes for |
| 145 | execution mode that can be selecet through |
| 146 | config file */ |
| 147 | typedef enum st_exec_mode_config { |
| 148 | EXEC_MODE_CFG_APE, |
| 149 | EXEC_MODE_CFG_CPE, |
| 150 | EXEC_MODE_CFG_DYNAMIC, |
| 151 | EXEC_MODE_CFG_ARM |
| 152 | } st_exec_mode_config_t; |
| 153 | |
| 154 | #endif /* ST_COMMON_DEFS_H */ |