1 /* 2 * Copyright (c) 2022 Espressif Systems (Shanghai) Co., Ltd. 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #include <zephyr/kernel.h> 8 #include <zephyr/pm/pm.h> 9 #include <esp_sleep.h> 10 11 #include <zephyr/logging/log.h> 12 LOG_MODULE_DECLARE(soc, CONFIG_SOC_LOG_LEVEL); 13 14 static uint32_t intenable; 15 16 /* Invoke Low Power/System Off specific Tasks */ pm_state_set(enum pm_state state,uint8_t substate_id)17void pm_state_set(enum pm_state state, uint8_t substate_id) 18 { 19 ARG_UNUSED(substate_id); 20 21 switch (state) { 22 case PM_STATE_STANDBY: 23 intenable = XTENSA_RSR("INTENABLE"); 24 __asm__ volatile ("waiti 0"); 25 break; 26 default: 27 LOG_DBG("Unsupported power state %u", state); 28 break; 29 } 30 } 31 32 /* Handle SOC specific activity after Low Power Mode Exit */ pm_state_exit_post_ops(enum pm_state state,uint8_t substate_id)33void pm_state_exit_post_ops(enum pm_state state, uint8_t substate_id) 34 { 35 ARG_UNUSED(substate_id); 36 37 switch (state) { 38 case PM_STATE_STANDBY: 39 z_xt_ints_on(intenable); 40 esp_light_sleep_start(); 41 break; 42 default: 43 LOG_DBG("Unsupported power state %u", state); 44 break; 45 } 46 } 47