1 /* 2 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. 3 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without modification, 6 * are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, this list of 9 * conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 * of conditions and the following disclaimer in the documentation and/or other materials 13 * provided with the distribution. 14 * 15 * 3. Neither the name of the copyright holder nor the names of its contributors may be used 16 * to endorse or promote products derived from this software without specific prior written 17 * permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #ifndef _LOS_PM_H 33 #define _LOS_PM_H 34 35 #include "los_config.h" 36 #include "los_typedef.h" 37 #include "los_list.h" 38 #include "los_seq_buf.h" 39 #include "los_errno.h" 40 41 typedef enum { 42 LOS_SYS_NORMAL_SLEEP = 0, 43 LOS_SYS_LIGHT_SLEEP, 44 LOS_SYS_DEEP_SLEEP, 45 LOS_SYS_SHUTDOWN, 46 } LOS_SysSleepEnum; 47 48 typedef enum { 49 LOS_PM_TYPE_DEVICE = 0, 50 LOS_PM_TYPE_TICK_TIMER, /* reserved */ 51 LOS_PM_TYPE_SYSCTRL, 52 } LOS_PmNodeType; 53 54 typedef struct { 55 UINT32 (*suspend)(UINT32 mode); /* The device enters low power consumption, Unlocked task scheduling. */ 56 VOID (*resume)(UINT32 mode); /* The device exits from low power consumption, Unlocked task scheduling. */ 57 } LosPmDevice; 58 59 typedef struct { 60 /* Preparations before the CPU enters low power consumption. 61 * All modes except normal mode are invoked. 62 * Unlocked task scheduling. 63 */ 64 UINT32 (*early)(UINT32 mode); 65 /* The system performs low-power recovery. 66 * All modes except normal mode are invoked. 67 * Unlocked task scheduling. 68 */ 69 VOID (*late)(UINT32 mode); 70 /* The system enters the Normal sleep mode. 71 * In normal mode, the value cannot be NULL. 72 */ 73 UINT32 (*normalSuspend)(VOID); 74 /* The system recovers from normal sleep. 75 * The value can be NULL. 76 */ 77 VOID (*normalResume)(VOID); 78 /* The system enters the light sleep mode. 79 * In light sleep mode, the value cannot be NULL. 80 */ 81 UINT32 (*lightSuspend)(VOID); 82 /* The system recovers from light sleep. 83 * The value can be NULL. 84 */ 85 VOID (*lightResume)(VOID); 86 /* The system enters the deep sleep mode. 87 * In deep sleep mode, the value cannot be NULL. 88 */ 89 UINT32 (*deepSuspend)(VOID); 90 /* The system recovers from deep sleep. 91 * The value can be NULL. 92 */ 93 VOID (*deepResume)(VOID); 94 /* The system enters the shutdown mode. 95 * In shutdown mode, the value cannot be NULL. 96 */ 97 UINT32 (*shutdownSuspend)(VOID); 98 /* The system recovers from shutdown. 99 * In shutdown mode, the value cannot be NULL. 100 */ 101 VOID (*shutdownResume)(VOID); 102 } LosPmSysctrl; 103 104 /** 105 * @ingroup los_pm 106 * @brief Register a power management node. 107 * 108 * @par Description: 109 * This API is used to register a power management node. 110 * 111 * @attention None. 112 * 113 * @param type [IN] The types supported by the PM module. 114 * @param node [IN] power management node. 115 * 116 * @retval error code, LOS_OK means success. 117 * @par Dependency: 118 * <ul><li>los_pm.h: the header file that contains the API declaration.</li></ul> 119 * @see LOS_PmUnregister 120 */ 121 UINT32 LOS_PmRegister(LOS_PmNodeType type, VOID *node); 122 123 /** 124 * @ingroup los_pm 125 * @brief Unregister a power management node. 126 * 127 * @par Description: 128 * This API is used to unregister a power management node. 129 * 130 * @attention None. 131 * 132 * @param type [IN] The types supported by the PM module. 133 * @param node [IN] power management node. 134 * 135 * @retval error code, LOS_OK means success. 136 * @par Dependency: 137 * <ul><li>los_pm.h: the header file that contains the API declaration.</li></ul> 138 * @see LOS_PmRegister 139 */ 140 UINT32 LOS_PmUnregister(LOS_PmNodeType type, VOID *node); 141 142 /** 143 * @ingroup los_pm 144 * @brief Set the system wake up flag. 145 * 146 * @par Description: 147 * This API is used to set the system wake-up flag. 148 * 149 * @attention None. 150 * 151 * @param None. 152 * 153 * @retval None. 154 * @par Dependency: 155 * <ul><li>los_pm.h: the header file that contains the API declaration.</li></ul> 156 * @see 157 */ 158 VOID LOS_PmWakeSet(VOID); 159 160 /** 161 * @ingroup los_pm 162 * @brief Get the low power mode of the current system. 163 * 164 * @par Description: 165 * This API is used to get the low power mode of the current system. 166 * 167 * @attention None. 168 * 169 * @param None. 170 * 171 * @retval error code, LOS_OK means success. 172 * @par Dependency: 173 * <ul><li>los_pm.h: the header file that contains the API declaration.</li></ul> 174 * @see 175 */ 176 LOS_SysSleepEnum LOS_PmModeGet(VOID); 177 178 /** 179 * @ingroup los_pm 180 * @brief Set low power mode. 181 * 182 * @par Description: 183 * This API is used to set low power mode. 184 * 185 * @attention None. 186 * 187 * @param mode [IN] low power mode. 188 * 189 * @retval error code, LOS_OK means success. 190 * @par Dependency: 191 * <ul><li>los_pm.h: the header file that contains the API declaration.</li></ul> 192 * @see LOS_PmModeGet 193 */ 194 UINT32 LOS_PmModeSet(LOS_SysSleepEnum mode); 195 196 /** 197 * @ingroup los_pm 198 * @brief Get the low power mode of the current system. 199 * 200 * @par Description: 201 * This API is used to get the low power mode of the current system. 202 * 203 * @attention None. 204 * 205 * @param None. 206 * 207 * @retval Number of locks held. 208 * @par Dependency: 209 * <ul><li>los_pm.h: the header file that contains the API declaration.</li></ul> 210 * @see 211 */ 212 UINT32 LOS_PmLockCountGet(VOID); 213 214 /** 215 * @ingroup los_pm 216 * @brief Request to obtain the lock in current mode, so that the system will not enter 217 * this mode when it enters the idle task next time. 218 * 219 * @par Description: 220 * This API is used to obtain the lock in current mode. 221 * 222 * @attention None. 223 * 224 * @param name [IN] Who requests the lock. 225 * 226 * @retval error code, LOS_OK means success. 227 * @par Dependency: 228 * <ul><li>los_pm.h: the header file that contains the API declaration.</li></ul> 229 * @see LOS_PmLockRelease 230 */ 231 UINT32 LOS_PmLockRequest(const CHAR *name); 232 233 /** 234 * @ingroup los_pm 235 * @brief Request to obtain the lock in current mode, so that the system will not enter 236 * this mode when it enters the idle task next time. After the specified interval, the 237 * lock is automatically released. 238 * 239 * @par Description: 240 * This API is used to obtain the delay lock in current mode. 241 * 242 * @attention None. 243 * 244 * @param name [IN] Who requests the lock. 245 * @param millisecond [IN] Specifies the time to automatically release the lock. 246 * 247 * @retval error code, LOS_OK means success. 248 * @par Dependency: 249 * <ul><li>los_pm.h: the header file that contains the API declaration.</li></ul> 250 * @see LOS_PmLockRelease 251 */ 252 UINT32 LOS_PmTimeLockRequest(const CHAR *name, UINT64 millisecond); 253 254 /** 255 * @ingroup los_pm 256 * @brief Release the lock in current mode so that the next time the system enters 257 * the idle task, it will enter this mode. 258 * 259 * @par Description: 260 * This API is used to release the lock in current mode. 261 * 262 * @attention None. 263 * 264 * @param name [IN] Who releases the lock. 265 * 266 * @retval error code, LOS_OK means success. 267 * @par Dependency: 268 * <ul><li>los_pm.h: the header file that contains the API declaration.</li></ul> 269 * @see LOS_PmLockRequest 270 */ 271 UINT32 LOS_PmLockRelease(const CHAR *name); 272 273 /** 274 * @ingroup los_pm 275 * @brief Gets the current PM lock status. 276 * 277 * @par Description: 278 * This API is used to Get the current PM lock status. 279 * 280 * @attention None. 281 * 282 * @param None. 283 * 284 * @retval Number of awakening sources of the device. 285 * @par Dependency: 286 * <ul><li>los_pm.h: the header file that contains the API declaration.</li></ul> 287 * @see 288 */ 289 UINT32 LOS_PmReadLock(VOID); 290 291 /** 292 * @ingroup los_pm 293 * @brief The system enters the low-power flow. 294 * 295 * @par Description: 296 * This API is used to enter the system into a low-power process. 297 * 298 * @attention None. 299 * 300 * @param wakeCount [IN] Number of wake sources. 301 * 302 * @retval error code, LOS_OK means success. 303 * @par Dependency: 304 * <ul><li>los_pm.h: the header file that contains the API declaration.</li></ul> 305 * @see 306 */ 307 UINT32 LOS_PmSuspend(UINT32 wakeCount); 308 309 /** 310 * @ingroup los_pm 311 * @brief Output the locking information of the pm lock. 312 * 313 * @par Description: 314 * This API is used to output the locking information of the pm lock. 315 * 316 * @attention None. 317 * 318 * @param m [IN] . 319 * 320 * @retval error code, LOS_OK means success. 321 * @par Dependency: 322 * <ul><li>los_pm.h: the header file that contains the API declaration.</li></ul> 323 * @see LOS_PmLockRequest 324 */ 325 VOID LOS_PmLockInfoShow(struct SeqBuf *m); 326 327 #endif 328