1 /* 2 * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #include <stdint.h> 8 #include <assert.h> 9 #include "soc/rtc.h" 10 #include "soc/rtc_cntl_reg.h" 11 #include "soc/syscon_reg.h" 12 13 typedef enum { 14 PM_LIGHT_SLEEP = BIT(2), /*!< WiFi PD, memory in light sleep */ 15 } pm_sleep_mode_t; 16 17 typedef enum{ 18 PM_SW_NOREJECT = 0, 19 PM_SW_REJECT = 1 20 } pm_sw_reject_t; 21 22 23 /* These MAC-related functions are defined in the closed source part of 24 * RTC library 25 */ 26 extern void pm_mac_init(void); 27 extern int pm_check_mac_idle(void); 28 extern void pm_mac_deinit(void); 29 30 /* This sleep-related function is called from the closed source part of RTC 31 * library. 32 */ pm_set_sleep_mode(pm_sleep_mode_t sleep_mode,void (* pmac_save_params)(void))33pm_sw_reject_t pm_set_sleep_mode(pm_sleep_mode_t sleep_mode, void(*pmac_save_params)(void)) 34 { 35 (void) pmac_save_params; /* unused */ 36 37 pm_mac_deinit(); 38 if (pm_check_mac_idle()) { 39 pm_mac_init(); 40 return PM_SW_REJECT; 41 } 42 43 rtc_sleep_config_t cfg = { 0 }; 44 45 switch (sleep_mode) { 46 case PM_LIGHT_SLEEP: 47 cfg.wifi_pd_en = 1; 48 cfg.dig_dbias_wak = 4; 49 cfg.dig_dbias_slp = 0; 50 cfg.rtc_dbias_wak = 0; 51 cfg.rtc_dbias_slp = 0; 52 rtc_sleep_init(cfg); 53 break; 54 55 default: 56 assert(0 && "unsupported sleep mode"); 57 } 58 return PM_SW_NOREJECT; 59 } 60