1 /* 2 * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 */ 4 #ifndef __HAL_SLEEP_H__ 5 #define __HAL_SLEEP_H__ 6 7 #ifdef __cplusplus 8 extern "C" { 9 #endif 10 11 #include "plat_types.h" 12 13 enum HAL_CPU_WAKE_LOCK_USER_T { 14 HAL_CPU_WAKE_LOCK_USER_RTOS, 15 HAL_CPU_WAKE_LOCK_USER_EXTERNAL, 16 HAL_CPU_WAKE_LOCK_USER_AUDIOFLINGER, 17 HAL_CPU_WAKE_LOCK_USER_3, 18 HAL_CPU_WAKE_LOCK_USER_4, 19 HAL_CPU_WAKE_LOCK_USER_5, 20 HAL_CPU_WAKE_LOCK_USER_6, 21 HAL_CPU_WAKE_LOCK_USER_7, 22 HAL_CPU_WAKE_LOCK_USER_8, 23 HAL_CPU_WAKE_LOCK_USER_9, 24 HAL_CPU_WAKE_LOCK_USER_10, 25 HAL_CPU_WAKE_LOCK_USER_11, 26 HAL_CPU_WAKE_LOCK_USER_12, 27 HAL_CPU_WAKE_LOCK_USER_13, 28 HAL_CPU_WAKE_LOCK_USER_14, 29 HAL_CPU_WAKE_LOCK_USER_15, 30 HAL_CPU_WAKE_LOCK_USER_16, 31 HAL_CPU_WAKE_LOCK_USER_17, 32 HAL_CPU_WAKE_LOCK_USER_18, 33 HAL_CPU_WAKE_LOCK_USER_19, 34 HAL_CPU_WAKE_LOCK_USER_20, 35 HAL_CPU_WAKE_LOCK_USER_21, 36 HAL_CPU_WAKE_LOCK_USER_22, 37 HAL_CPU_WAKE_LOCK_USER_23, 38 HAL_CPU_WAKE_LOCK_USER_24, 39 HAL_CPU_WAKE_LOCK_USER_25, 40 HAL_CPU_WAKE_LOCK_USER_26, 41 HAL_CPU_WAKE_LOCK_USER_27, 42 HAL_CPU_WAKE_LOCK_USER_28, 43 HAL_CPU_WAKE_LOCK_USER_29, 44 HAL_CPU_WAKE_LOCK_USER_30, 45 HAL_CPU_WAKE_LOCK_USER_31, 46 47 HAL_CPU_WAKE_LOCK_USER_QTY 48 }; 49 50 enum HAL_SYS_WAKE_LOCK_USER_T { 51 HAL_SYS_WAKE_LOCK_USER_INTERSYS, 52 HAL_SYS_WAKE_LOCK_USER_INTERSYS_HCI, 53 HAL_SYS_WAKE_LOCK_USER_2, 54 HAL_SYS_WAKE_LOCK_USER_3, 55 HAL_SYS_WAKE_LOCK_USER_4, 56 HAL_SYS_WAKE_LOCK_USER_TRANSQ, 57 HAL_SYS_WAKE_LOCK_USER_6, 58 HAL_SYS_WAKE_LOCK_USER_7, 59 HAL_SYS_WAKE_LOCK_USER_8, 60 HAL_SYS_WAKE_LOCK_USER_9, 61 HAL_SYS_WAKE_LOCK_USER_10, 62 HAL_SYS_WAKE_LOCK_USER_11, 63 HAL_SYS_WAKE_LOCK_USER_12, 64 HAL_SYS_WAKE_LOCK_USER_13, 65 HAL_SYS_WAKE_LOCK_USER_14, 66 HAL_SYS_WAKE_LOCK_USER_15, 67 HAL_SYS_WAKE_LOCK_USER_16, 68 HAL_SYS_WAKE_LOCK_USER_17, 69 HAL_SYS_WAKE_LOCK_USER_18, 70 HAL_SYS_WAKE_LOCK_USER_19, 71 HAL_SYS_WAKE_LOCK_USER_20, 72 HAL_SYS_WAKE_LOCK_USER_21, 73 HAL_SYS_WAKE_LOCK_USER_22, 74 HAL_SYS_WAKE_LOCK_USER_23, 75 HAL_SYS_WAKE_LOCK_USER_24, 76 HAL_SYS_WAKE_LOCK_USER_25, 77 HAL_SYS_WAKE_LOCK_USER_26, 78 HAL_SYS_WAKE_LOCK_USER_27, 79 HAL_SYS_WAKE_LOCK_USER_28, 80 HAL_SYS_WAKE_LOCK_USER_29, 81 HAL_SYS_WAKE_LOCK_USER_30, 82 HAL_SYS_WAKE_LOCK_USER_31, 83 84 HAL_SYS_WAKE_LOCK_USER_QTY 85 }; 86 87 enum HAL_CHIP_WAKE_LOCK_USER_T { 88 HAL_CHIP_WAKE_LOCK_USER_ANC, 89 HAL_CHIP_WAKE_LOCK_USER_1, 90 HAL_CHIP_WAKE_LOCK_USER_2, 91 HAL_CHIP_WAKE_LOCK_USER_3, 92 HAL_CHIP_WAKE_LOCK_USER_4, 93 HAL_CHIP_WAKE_LOCK_USER_5, 94 HAL_CHIP_WAKE_LOCK_USER_6, 95 HAL_CHIP_WAKE_LOCK_USER_7, 96 HAL_CHIP_WAKE_LOCK_USER_8, 97 HAL_CHIP_WAKE_LOCK_USER_9, 98 HAL_CHIP_WAKE_LOCK_USER_10, 99 HAL_CHIP_WAKE_LOCK_USER_11, 100 HAL_CHIP_WAKE_LOCK_USER_12, 101 HAL_CHIP_WAKE_LOCK_USER_13, 102 HAL_CHIP_WAKE_LOCK_USER_14, 103 HAL_CHIP_WAKE_LOCK_USER_15, 104 HAL_CHIP_WAKE_LOCK_USER_16, 105 HAL_CHIP_WAKE_LOCK_USER_17, 106 HAL_CHIP_WAKE_LOCK_USER_18, 107 HAL_CHIP_WAKE_LOCK_USER_19, 108 HAL_CHIP_WAKE_LOCK_USER_20, 109 HAL_CHIP_WAKE_LOCK_USER_21, 110 HAL_CHIP_WAKE_LOCK_USER_22, 111 HAL_CHIP_WAKE_LOCK_USER_23, 112 HAL_CHIP_WAKE_LOCK_USER_24, 113 HAL_CHIP_WAKE_LOCK_USER_25, 114 HAL_CHIP_WAKE_LOCK_USER_26, 115 HAL_CHIP_WAKE_LOCK_USER_27, 116 HAL_CHIP_WAKE_LOCK_USER_28, 117 HAL_CHIP_WAKE_LOCK_USER_29, 118 HAL_CHIP_WAKE_LOCK_USER_30, 119 HAL_CHIP_WAKE_LOCK_USER_31, 120 121 HAL_CHIP_WAKE_LOCK_USER_QTY 122 }; 123 124 enum HAL_SLEEP_HOOK_USER_T { 125 HAL_SLEEP_HOOK_USER_NVRECORD = 0, 126 HAL_SLEEP_HOOK_USER_OTA, 127 HAL_SLEEP_HOOK_NORFLASH_API, 128 HAL_SLEEP_HOOK_DUMP_LOG, 129 HAL_SLEEP_HOOK_USER_QTY 130 }; 131 132 enum HAL_DEEP_SLEEP_HOOK_USER_T { 133 HAL_DEEP_SLEEP_HOOK_USER_WDT = 0, 134 HAL_DEEP_SLEEP_HOOK_USER_NVRECORD, 135 HAL_DEEP_SLEEP_HOOK_USER_OTA, 136 HAL_DEEP_SLEEP_HOOK_NORFLASH_API, 137 HAL_DEEP_SLEEP_HOOK_DUMP_LOG, 138 HAL_DEEP_SLEEP_HOOK_USER_QTY 139 }; 140 141 enum HAL_SLEEP_STATUS_T { 142 HAL_SLEEP_STATUS_DEEP, 143 HAL_SLEEP_STATUS_LIGHT, 144 }; 145 146 struct CPU_USAGE_T { 147 uint8_t busy; 148 uint8_t light_sleep; 149 uint8_t sys_deep_sleep; 150 uint8_t chip_deep_sleep; 151 }; 152 153 typedef int (*HAL_SLEEP_HOOK_HANDLER)(void); 154 typedef int (*HAL_DEEP_SLEEP_HOOK_HANDLER)(void); 155 156 int hal_sleep_irq_pending(void); 157 158 int hal_sleep_specific_irq_pending(const uint32_t *irq, uint32_t cnt); 159 160 enum HAL_SLEEP_STATUS_T hal_sleep_enter_sleep(void); 161 162 enum HAL_SLEEP_STATUS_T hal_sleep_light_sleep(void); 163 164 int hal_sleep_set_sleep_hook(enum HAL_SLEEP_HOOK_USER_T user, HAL_SLEEP_HOOK_HANDLER handler); 165 166 int hal_sleep_set_deep_sleep_hook(enum HAL_DEEP_SLEEP_HOOK_USER_T user, HAL_DEEP_SLEEP_HOOK_HANDLER handler); 167 168 int hal_cpu_wake_lock(enum HAL_CPU_WAKE_LOCK_USER_T user); 169 170 int hal_cpu_wake_unlock(enum HAL_CPU_WAKE_LOCK_USER_T user); 171 172 int hal_sys_wake_lock(enum HAL_SYS_WAKE_LOCK_USER_T user); 173 174 int hal_sys_wake_unlock(enum HAL_SYS_WAKE_LOCK_USER_T user); 175 176 int hal_chip_wake_lock(enum HAL_CHIP_WAKE_LOCK_USER_T user); 177 178 int hal_chip_wake_unlock(enum HAL_CHIP_WAKE_LOCK_USER_T user); 179 180 void hal_sleep_start_stats(uint32_t stats_interval_ms, uint32_t trace_interval_ms); 181 182 int hal_sleep_get_stats(struct CPU_USAGE_T *usage); 183 184 #ifdef __cplusplus 185 } 186 #endif 187 188 #endif 189 190