1 #if (AOS_COMP_PWRMGMT > 0) 2 #include <hal/wifi.h> 3 #include "pwrmgmt_api.h" 4 #include <cpu_pwr.h> 5 6 #define SET_BIT(off) ((uint32_t)1 << (off)) 7 8 uint32_t sleep_type = SLEEP_CG; /* 0 is power gate, 1 is clock gate */ 9 10 static sys_time_t cpu_pwr_active_exit_tick = 0; 11 static uint32_t cpu_suspend_lock = 0; 12 cpu_pwr_ready_status_get(void)13int cpu_pwr_ready_status_get(void) 14 { 15 if (cpu_pwr_is_suspend() == 1) { 16 return 0; 17 } 18 19 if(krhino_sys_tick_get() < cpu_pwr_active_exit_tick) { 20 return 0; 21 } 22 23 return 1; 24 } 25 pwrmgmt_cpu_active_msec_set(uint32_t active_time)26int pwrmgmt_cpu_active_msec_set(uint32_t active_time) 27 { 28 tick_t active_tick = 0; 29 sys_time_t current_active_exit_tick = 0; 30 31 if (active_time == 0) { 32 return 0; 33 } 34 35 active_tick = krhino_ms_to_ticks(active_time); 36 37 /* if active time is less than 1 tick */ 38 if (active_tick == 0) { 39 active_tick = 1; 40 } 41 42 current_active_exit_tick = krhino_sys_tick_get() + active_tick; 43 if (current_active_exit_tick > cpu_pwr_active_exit_tick) { 44 cpu_pwr_active_exit_tick = current_active_exit_tick; 45 } 46 47 return 0; 48 } 49 pwrmgmt_sleep_type_set(uint32_t type)50uint32_t pwrmgmt_sleep_type_set(uint32_t type) 51 { 52 sleep_type = type; 53 return 0; 54 } 55 pwrmgmt_wifi_powersave_suspend(uint32_t suspend_module)56int pwrmgmt_wifi_powersave_suspend(uint32_t suspend_module) 57 { 58 hal_wifi_module_t *module = NULL; 59 60 module = hal_wifi_get_default_module(); 61 hal_wifi_exit_powersave(module); 62 } 63 pwrmgmt_wifi_powersave_resume(uint32_t resume_module)64int pwrmgmt_wifi_powersave_resume(uint32_t resume_module) 65 { 66 hal_wifi_module_t *module = NULL; 67 68 module = hal_wifi_get_default_module(); 69 hal_wifi_enter_powersave(module, WIFI_CONFIG_RECEIVE_DTIM); 70 } 71 pwrmgmt_cpu_lowpower_suspend(uint32_t suspend_module)72int pwrmgmt_cpu_lowpower_suspend(uint32_t suspend_module) 73 { 74 if (cpu_suspend_lock == 0) { 75 cpu_pwr_suspend(); 76 } 77 78 cpu_suspend_lock |= SET_BIT(suspend_module); 79 } 80 pwrmgmt_cpu_lowpower_resume(uint32_t resume_module)81int pwrmgmt_cpu_lowpower_resume(uint32_t resume_module) 82 { 83 cpu_suspend_lock &= ~SET_BIT(resume_module); 84 85 if (cpu_suspend_lock == 0) { 86 cpu_pwr_resume(); 87 } 88 } 89 pwrmgmt_cpu_minisleep_msec_set(uint32_t time_ms)90int pwrmgmt_cpu_minisleep_msec_set(uint32_t time_ms) 91 { 92 cpu_pwr_minisleep_msec_set(time_ms); 93 return 0; 94 } 95 pwrmgmt_cpu_minisleep_msec_get(void)96uint32_t pwrmgmt_cpu_minisleep_msec_get(void) 97 { 98 return cpu_pwr_minisleep_msec_get(); 99 } 100 101 #endif 102