1 // Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #include <stdint.h> 16 #include <assert.h> 17 #include "soc/rtc.h" 18 19 typedef enum { 20 PM_LIGHT_SLEEP = BIT(2), /*!< WiFi PD, memory in light sleep */ 21 } pm_sleep_mode_t; 22 23 typedef enum{ 24 PM_SW_NOREJECT = 0, 25 PM_SW_REJECT = 1 26 } pm_sw_reject_t; 27 28 29 /* These MAC-related functions are defined in the closed source part of 30 * RTC library 31 */ 32 extern void pm_mac_init(void); 33 extern int pm_check_mac_idle(void); 34 extern void pm_mac_deinit(void); 35 36 /* This sleep-related function is called from the closed source part of RTC 37 * library. 38 */ pm_set_sleep_mode(pm_sleep_mode_t sleep_mode,void (* pmac_save_params)(void))39pm_sw_reject_t pm_set_sleep_mode(pm_sleep_mode_t sleep_mode, void(*pmac_save_params)(void)) 40 { 41 (void) pmac_save_params; /* unused */ 42 43 pm_mac_deinit(); 44 if (pm_check_mac_idle()) { 45 pm_mac_init(); 46 return PM_SW_REJECT; 47 } 48 49 rtc_sleep_config_t cfg = { 0 }; 50 51 switch (sleep_mode) { 52 case PM_LIGHT_SLEEP: 53 cfg.wifi_pd_en = 1; 54 cfg.dig_dbias_wak = 4; 55 cfg.dig_dbias_slp = 0; 56 cfg.rtc_dbias_wak = 0; 57 cfg.rtc_dbias_slp = 0; 58 cfg.lslp_meminf_pd = 1; 59 rtc_sleep_init(cfg); 60 break; 61 62 default: 63 assert(0 && "unsupported sleep mode"); 64 } 65 return PM_SW_NOREJECT; 66 } 67