From 1a26718cf863cffb1ec89fc574844a6f9fe11197 Mon Sep 17 00:00:00 2001 From: Peter Sarkozi Date: Sat, 17 Jun 2023 15:20:22 +0200 Subject: [PATCH 1/2] Deep Sleep support --- beken378/driver/sys_ctrl/sys_ctrl.c | 12 ++++++------ beken378/func/include/manual_ps_pub.h | 2 +- beken378/func/power_save/manual_ps.c | 22 ++++++++++++---------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/beken378/driver/sys_ctrl/sys_ctrl.c b/beken378/driver/sys_ctrl/sys_ctrl.c index 636de14..57c3d92 100644 --- a/beken378/driver/sys_ctrl/sys_ctrl.c +++ b/beken378/driver/sys_ctrl/sys_ctrl.c @@ -1709,15 +1709,15 @@ void sctrl_enter_rtos_idle_sleep(PS_DEEP_CTRL_PARAM deep_param) reg = 0xFFFFFFFF; REG_WRITE(SCTRL_GPIO_WAKEUP_INT_STATUS,reg); - if(deep_param.deep_wkway == PS_DEEP_WAKEUP_RTC - && deep_param.param != 0xffffffff) + if(deep_param.wake_up_way == PS_DEEP_WAKEUP_RTC + && deep_param.sleep_time != 0xffffffff) { reg = REG_READ(SCTRL_ROSC_TIMER); reg |= ROSC_TIMER_INT_STATUS_BIT; REG_WRITE(SCTRL_ROSC_TIMER,reg); reg = REG_READ(SCTRL_ROSC_TIMER); reg &= ~(ROSC_TIMER_PERIOD_MASK << ROSC_TIMER_PERIOD_POSI); - reg |= (deep_param.param << ROSC_TIMER_PERIOD_POSI); + reg |= (deep_param.sleep_time << ROSC_TIMER_PERIOD_POSI); REG_WRITE(SCTRL_ROSC_TIMER,reg); reg = REG_READ(SCTRL_ROSC_TIMER); reg |= ROSC_TIMER_ENABLE_BIT; @@ -1733,13 +1733,13 @@ void sctrl_enter_rtos_idle_sleep(PS_DEEP_CTRL_PARAM deep_param) reg |= (0x1 << 8); REG_WRITE(SCTRL_BLOCK_EN_MUX, reg); } - else if(deep_param.deep_wkway == PS_DEEP_WAKEUP_GPIO) + else if(deep_param.wake_up_way == PS_DEEP_WAKEUP_GPIO) { reg = 0xFFFFFFFF; REG_WRITE(SCTRL_GPIO_WAKEUP_INT_STATUS,reg); - reg = deep_param.gpio_lv; + reg = deep_param.gpio_edge_map; REG_WRITE(SCTRL_GPIO_WAKEUP_TYPE,reg); - reg = deep_param.param; + reg = deep_param.gpio_index_map; REG_WRITE(SCTRL_GPIO_WAKEUP_EN,reg); } diff --git a/beken378/func/include/manual_ps_pub.h b/beken378/func/include/manual_ps_pub.h index 09be2a2..dd16954 100644 --- a/beken378/func/include/manual_ps_pub.h +++ b/beken378/func/include/manual_ps_pub.h @@ -58,7 +58,7 @@ typedef enum { MANUAL_MODE_IDLE = 1, } MANUAL_MODE; -#define PS_SUPPORT_MANUAL_SLEEP 0 +#define PS_SUPPORT_MANUAL_SLEEP 1 typedef void ( *ps_wakeup_cb ) ( void ); extern void deep_sleep_wakeup_with_gpio ( UINT32 gpio_index_map, UINT32 gpio_edge_map ); extern void bk_enter_deep_sleep_mode ( PS_DEEP_CTRL_PARAM *deep_param ); diff --git a/beken378/func/power_save/manual_ps.c b/beken378/func/power_save/manual_ps.c index 9b88e4f..81a0932 100644 --- a/beken378/func/power_save/manual_ps.c +++ b/beken378/func/power_save/manual_ps.c @@ -179,21 +179,21 @@ void idle_sleep_wakeup_with_timer ( UINT32 sleep_time ) if ( sleep_time != 0xffffffff ) { os_printf ( "idle sleep with rtc,%d ms\r\n", sleep_time ); - deep_param.param = ( ( sleep_time * 102400 ) / 3125 ) ; + deep_param.sleep_time = ( ( sleep_time * 102400 ) / 3125 ) ; - if ( deep_param.param > 0xffff ) //only 16 bit - deep_param.param = 0xffff; - else if ( deep_param.param < 32 ) - deep_param.param = 32; + if ( deep_param.sleep_time > 0xffff ) //only 16 bit + deep_param.sleep_time = 0xffff; + else if ( deep_param.sleep_time < 32 ) + deep_param.sleep_time = 32; } else { os_printf ( "idle sleep forever\r\n" ); - deep_param.param = 0xffffffff; + deep_param.sleep_time = 0xffffffff; } param = LPO_SELECT_ROSC; sddev_control ( SCTRL_DEV_NAME, CMD_SCTRL_SET_LOW_PWR_CLK, ¶m ); - deep_param.deep_wkway = PS_DEEP_WAKEUP_RTC; + deep_param.wake_up_way = PS_DEEP_WAKEUP_RTC; os_printf ( "enter rtc ps\r\n" ); GLOBAL_INT_DECLARATION(); GLOBAL_INT_DISABLE(); @@ -241,9 +241,9 @@ void idle_sleep_wakeup_with_gpio ( UINT32 gpio_index_map, UINT32 gpio_edge_map ) ps_pwm0_disable(); uart_wait_tx_over(); wifi_mac_state_set_idle(); - deep_param.deep_wkway = PS_DEEP_WAKEUP_GPIO; - deep_param.param = gpio_index_map; - deep_param.gpio_lv = gpio_edge_map; + deep_param.wake_up_way = PS_DEEP_WAKEUP_GPIO; + deep_param.gpio_index_map = gpio_index_map; + deep_param.gpio_edge_map = gpio_edge_map; sddev_control ( SCTRL_DEV_NAME, CMD_SCTRL_RTOS_IDLE_SLEEP, &deep_param ); delay ( 5 ); sddev_control ( SCTRL_DEV_NAME, CMD_SCTRL_RTOS_IDLE_WAKEUP, 0 ); @@ -532,6 +532,8 @@ void bk_enter_deep_sleep_mode ( PS_DEEP_CTRL_PARAM *deep_param ) deep_param->sleep_time = 32768 * deep_param->sleep_time; } + + bk_misc_update_set_type(RESET_SOURCE_DEEPPS_GPIO); GLOBAL_INT_DECLARATION(); GLOBAL_INT_DISABLE(); From 8ca71f03bd98b768a45d0cc2bd178fe72ec16b31 Mon Sep 17 00:00:00 2001 From: Peter Sarkozi Date: Sat, 17 Jun 2023 21:04:46 +0200 Subject: [PATCH 2/2] Remove unnecessary override --- beken378/func/include/manual_ps_pub.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beken378/func/include/manual_ps_pub.h b/beken378/func/include/manual_ps_pub.h index dd16954..09be2a2 100644 --- a/beken378/func/include/manual_ps_pub.h +++ b/beken378/func/include/manual_ps_pub.h @@ -58,7 +58,7 @@ typedef enum { MANUAL_MODE_IDLE = 1, } MANUAL_MODE; -#define PS_SUPPORT_MANUAL_SLEEP 1 +#define PS_SUPPORT_MANUAL_SLEEP 0 typedef void ( *ps_wakeup_cb ) ( void ); extern void deep_sleep_wakeup_with_gpio ( UINT32 gpio_index_map, UINT32 gpio_edge_map ); extern void bk_enter_deep_sleep_mode ( PS_DEEP_CTRL_PARAM *deep_param );