改了sleep.c,看起来OK了?
This commit is contained in:
parent
678f23f95e
commit
013bbfb3d3
|
@ -127,7 +127,7 @@ void BSP_KEY_EnterLowpower(void)
|
||||||
// PWR_PeriphWakeUpCfg(ENABLE, RB_SLP_GPIO_WAKE, Long_Delay);
|
// PWR_PeriphWakeUpCfg(ENABLE, RB_SLP_GPIO_WAKE, Long_Delay);
|
||||||
PWR_PeriphWakeUpCfg(ENABLE, RB_GPIO_WAKE_MODE | RB_SLP_GPIO_WAKE, Long_Delay);
|
PWR_PeriphWakeUpCfg(ENABLE, RB_GPIO_WAKE_MODE | RB_SLP_GPIO_WAKE, Long_Delay);
|
||||||
|
|
||||||
PWR_PeriphWakeUpCfg(ENABLE, RB_SLP_GPIO_WAKE | RB_SLP_BAT_WAKE, Long_Delay);
|
// PWR_PeriphWakeUpCfg(ENABLE, RB_SLP_GPIO_WAKE | RB_SLP_BAT_WAKE, Long_Delay);
|
||||||
|
|
||||||
BSP_RequestSleep();
|
BSP_RequestSleep();
|
||||||
#endif
|
#endif
|
||||||
|
|
147
HAL/SLEEP.c
147
HAL/SLEEP.c
|
@ -30,6 +30,8 @@
|
||||||
static volatile bool block_sleep_flag = false;
|
static volatile bool block_sleep_flag = false;
|
||||||
static volatile bool block_boost_flag = false;
|
static volatile bool block_boost_flag = false;
|
||||||
|
|
||||||
|
static uint32_t block_sleep = 0;
|
||||||
|
|
||||||
__HIGH_CODE
|
__HIGH_CODE
|
||||||
void BSP_RequestSleep(void)
|
void BSP_RequestSleep(void)
|
||||||
{
|
{
|
||||||
|
@ -60,6 +62,82 @@ void BSP_NoNeedBoost(void)
|
||||||
BOOST_OFF_DEINIT;
|
BOOST_OFF_DEINIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__HIGH_CODE
|
||||||
|
void LowPower_Idle_ext(void)
|
||||||
|
{
|
||||||
|
FLASH_ROM_SW_RESET();
|
||||||
|
// R8_FLASH_CTRL = 0x04; //flash关闭
|
||||||
|
// PFIC->SCTLR &= ~(1 << 2); // sleep
|
||||||
|
__WFE();
|
||||||
|
__nop();
|
||||||
|
__nop();
|
||||||
|
}
|
||||||
|
|
||||||
|
__HIGH_CODE
|
||||||
|
void LowPower_Sleep_ext(uint16_t rm)
|
||||||
|
{
|
||||||
|
|
||||||
|
uint8_t x32Mpw;
|
||||||
|
uint16_t power_plan;
|
||||||
|
uint16_t clk_sys_cfg;
|
||||||
|
uint16_t hfck_pwr_ctrl;
|
||||||
|
|
||||||
|
clk_sys_cfg = R16_CLK_SYS_CFG;
|
||||||
|
hfck_pwr_ctrl = R8_HFCK_PWR_CTRL;
|
||||||
|
x32Mpw = R8_XT32M_TUNE;
|
||||||
|
x32Mpw = (x32Mpw & 0xfc) | 0x03; // 150%额定电流
|
||||||
|
|
||||||
|
sys_safe_access_enable();
|
||||||
|
R8_BAT_DET_CTRL = 0; // 关闭电压监控
|
||||||
|
R8_XT32M_TUNE = x32Mpw;
|
||||||
|
R16_POWER_PLAN &= ~RB_XT_PRE_EN;
|
||||||
|
sys_safe_access_disable();
|
||||||
|
|
||||||
|
PFIC->SCTLR |= (1 << 2); // deep sleep
|
||||||
|
|
||||||
|
power_plan = R16_POWER_PLAN & (RB_PWR_DCDC_EN | RB_PWR_DCDC_PRE);
|
||||||
|
power_plan |= RB_PWR_PLAN_EN | RB_PWR_CORE | rm | (2 << 11);
|
||||||
|
|
||||||
|
sys_safe_access_enable();
|
||||||
|
if (rm & RB_XT_PRE_EN)
|
||||||
|
{
|
||||||
|
R8_SLP_POWER_CTRL |= 0x41;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
R8_SLP_POWER_CTRL |= 0x40;
|
||||||
|
}
|
||||||
|
R16_POWER_PLAN = power_plan;
|
||||||
|
R8_HFCK_PWR_CTRL |= RB_CLK_RC16M_PON; // 睡眠需要打开内部HSI之后睡
|
||||||
|
sys_safe_access_disable();
|
||||||
|
if ((R16_CLK_SYS_CFG & RB_CLK_SYS_MOD) == 0x40)
|
||||||
|
{
|
||||||
|
sys_safe_access_enable();
|
||||||
|
R16_CLK_SYS_CFG = (R16_CLK_SYS_CFG & (~RB_CLK_PLL_DIV)) | 24;
|
||||||
|
sys_safe_access_disable();
|
||||||
|
}
|
||||||
|
// sys_safe_access_enable();
|
||||||
|
// R8_PLL_CONFIG |= (1 << 5);
|
||||||
|
// sys_safe_access_disable();
|
||||||
|
|
||||||
|
__WFE();
|
||||||
|
__nop();
|
||||||
|
__nop();
|
||||||
|
PFIC->SCTLR &= ~(1 << 2);
|
||||||
|
|
||||||
|
sys_safe_access_enable();
|
||||||
|
R16_CLK_SYS_CFG = clk_sys_cfg;
|
||||||
|
R8_HFCK_PWR_CTRL = hfck_pwr_ctrl;
|
||||||
|
sys_safe_access_disable();
|
||||||
|
|
||||||
|
sys_safe_access_enable();
|
||||||
|
R16_POWER_PLAN &= ~(RB_XT_PRE_EN | RB_PWR_PLAN_EN);
|
||||||
|
sys_safe_access_disable();
|
||||||
|
// sys_safe_access_enable();
|
||||||
|
// R8_PLL_CONFIG &= ~(1 << 5);
|
||||||
|
// sys_safe_access_disable();
|
||||||
|
DelayUs(40);
|
||||||
|
}
|
||||||
|
|
||||||
pfnLowPowerGapProcessCB_t LowPowerGapProcess;
|
pfnLowPowerGapProcessCB_t LowPowerGapProcess;
|
||||||
|
|
||||||
|
@ -75,6 +153,7 @@ pfnLowPowerGapProcessCB_t LowPowerGapProcess;
|
||||||
__HIGH_CODE
|
__HIGH_CODE
|
||||||
uint32_t CH58x_LowPower(uint32_t time)
|
uint32_t CH58x_LowPower(uint32_t time)
|
||||||
{
|
{
|
||||||
|
#if 0
|
||||||
// BSP_UART1_TxLowPower();
|
// BSP_UART1_TxLowPower();
|
||||||
if (block_boost_flag == false)
|
if (block_boost_flag == false)
|
||||||
{
|
{
|
||||||
|
@ -93,6 +172,7 @@ uint32_t CH58x_LowPower(uint32_t time)
|
||||||
// logDebug("block_sleep");
|
// logDebug("block_sleep");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
// LDect_Deinit();
|
// LDect_Deinit();
|
||||||
#if (defined(HAL_SLEEP)) && (HAL_SLEEP == TRUE)
|
#if (defined(HAL_SLEEP)) && (HAL_SLEEP == TRUE)
|
||||||
volatile uint32_t i;
|
volatile uint32_t i;
|
||||||
|
@ -109,7 +189,8 @@ uint32_t CH58x_LowPower(uint32_t time)
|
||||||
time_tign = time - WAKE_UP_RTC_MAX_TIME;
|
time_tign = time - WAKE_UP_RTC_MAX_TIME;
|
||||||
}
|
}
|
||||||
|
|
||||||
SYS_DisableAllIrq(&irq_status);
|
// SYS_DisableAllIrq(&irq_status);
|
||||||
|
PFIC_DisableAllIRQ();
|
||||||
time_curr = RTC_GetCycle32k();
|
time_curr = RTC_GetCycle32k();
|
||||||
// 检测睡眠时间
|
// 检测睡眠时间
|
||||||
if (time_tign < time_curr)
|
if (time_tign < time_curr)
|
||||||
|
@ -125,12 +206,14 @@ uint32_t CH58x_LowPower(uint32_t time)
|
||||||
if ((time_sleep < SLEEP_RTC_MIN_TIME) ||
|
if ((time_sleep < SLEEP_RTC_MIN_TIME) ||
|
||||||
(time_sleep > SLEEP_RTC_MAX_TIME))
|
(time_sleep > SLEEP_RTC_MAX_TIME))
|
||||||
{
|
{
|
||||||
SYS_RecoverIrq(irq_status);
|
// SYS_RecoverIrq(irq_status);
|
||||||
|
PFIC_EnableAllIRQ();
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
RTC_SetTignTime(time_tign);
|
RTC_SetTignTime(time_tign);
|
||||||
SYS_RecoverIrq(irq_status);
|
// SYS_RecoverIrq(irq_status);
|
||||||
|
PFIC_EnableAllIRQ();
|
||||||
#if (DEBUG == Debug_UART0) // 使用其他串口输出打印信息需要修改这行代码
|
#if (DEBUG == Debug_UART0) // 使用其他串口输出打印信息需要修改这行代码
|
||||||
while ((R8_UART0_LSR & RB_LSR_TX_ALL_EMP) == 0)
|
while ((R8_UART0_LSR & RB_LSR_TX_ALL_EMP) == 0)
|
||||||
{
|
{
|
||||||
|
@ -143,27 +226,49 @@ uint32_t CH58x_LowPower(uint32_t time)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
BSP_KEY_EnterLowpower();
|
// BSP_KEY_EnterLowpower();
|
||||||
// LOW POWER-sleep模式
|
// LOW POWER-sleep模式
|
||||||
if (!RTCTigFlag)
|
if (block_sleep)
|
||||||
|
{ // 这里是动态控制进入idle 睡眠,还是sleep 睡眠, 其中这里最高位置,定义为完全屏蔽睡眠,
|
||||||
|
if (block_sleep & 0x0000ffff)
|
||||||
{
|
{
|
||||||
LowPower_Sleep(RB_PWR_RAM32K | RB_PWR_RAM96K | RB_PWR_EXTEND);
|
LowPower_Idle_ext();
|
||||||
R8_RTC_FLAG_CTRL = (RB_RTC_TMR_CLR | RB_RTC_TRIG_CLR);
|
if (R8_RTC_FLAG_CTRL & RB_RTC_TRIG_FLAG)
|
||||||
RTC_SetTignTime(time);
|
|
||||||
sys_safe_access_enable();
|
|
||||||
R8_HFCK_PWR_CTRL |= RB_CLK_XT32M_KEEP;
|
|
||||||
sys_safe_access_disable();
|
|
||||||
if(!RTCTigFlag)
|
|
||||||
{
|
{
|
||||||
LowPower_Halt();
|
R8_RTC_FLAG_CTRL = RB_RTC_TRIG_CLR;
|
||||||
}
|
}
|
||||||
R8_RTC_FLAG_CTRL = (RB_RTC_TMR_CLR | RB_RTC_TRIG_CLR);
|
|
||||||
HSECFG_Current(HSE_RCur_100); // 降为额定电流(低功耗函数中提升了HSE偏置电流)
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
return 3;
|
return 3;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LowPower_Sleep_ext(RB_PWR_RAM96K | RB_PWR_EXTEND | RB_XT_PRE_EN);
|
||||||
|
|
||||||
|
HSECFG_Current(HSE_RCur_100); // 降为额定电流(低功耗函数中提升了HSE偏置电流)
|
||||||
|
}
|
||||||
|
if (R8_RTC_FLAG_CTRL & RB_RTC_TRIG_FLAG)
|
||||||
|
{
|
||||||
|
R8_RTC_FLAG_CTRL = RB_RTC_TRIG_CLR;
|
||||||
|
}
|
||||||
|
// if (!RTCTigFlag)
|
||||||
|
// {
|
||||||
|
// LowPower_Sleep(RB_PWR_RAM32K | RB_PWR_RAM96K | RB_PWR_EXTEND);
|
||||||
|
// R8_RTC_FLAG_CTRL = (RB_RTC_TMR_CLR | RB_RTC_TRIG_CLR);
|
||||||
|
// RTC_SetTignTime(time);
|
||||||
|
// sys_safe_access_enable();
|
||||||
|
// R8_HFCK_PWR_CTRL |= RB_CLK_XT32M_KEEP;
|
||||||
|
// sys_safe_access_disable();
|
||||||
|
// if (!RTCTigFlag)
|
||||||
|
// {
|
||||||
|
// LowPower_Halt();
|
||||||
|
// }
|
||||||
|
// R8_RTC_FLAG_CTRL = (RB_RTC_TMR_CLR | RB_RTC_TRIG_CLR);
|
||||||
|
// HSECFG_Current(HSE_RCur_100); // 降为额定电流(低功耗函数中提升了HSE偏置电流)
|
||||||
|
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
|
@ -177,7 +282,7 @@ uint32_t CH58x_LowPower(uint32_t time)
|
||||||
*/
|
*/
|
||||||
void LowPowerGapProcess_Register(pfnLowPowerGapProcessCB_t cb)
|
void LowPowerGapProcess_Register(pfnLowPowerGapProcessCB_t cb)
|
||||||
{
|
{
|
||||||
if((uint32_t)cb & 0x20000000)
|
if ((uint32_t)cb & 0x20000000)
|
||||||
{
|
{
|
||||||
LowPowerGapProcess = cb;
|
LowPowerGapProcess = cb;
|
||||||
}
|
}
|
||||||
|
@ -194,13 +299,13 @@ void LowPowerGapProcess_Register(pfnLowPowerGapProcessCB_t cb)
|
||||||
*/
|
*/
|
||||||
void HAL_SleepInit(void)
|
void HAL_SleepInit(void)
|
||||||
{
|
{
|
||||||
#if(defined(HAL_SLEEP)) && (HAL_SLEEP == TRUE)
|
#if (defined(HAL_SLEEP)) && (HAL_SLEEP == TRUE)
|
||||||
sys_safe_access_enable();
|
sys_safe_access_enable();
|
||||||
R8_SLP_WAKE_CTRL |= RB_SLP_RTC_WAKE; // RTC唤醒
|
R8_SLP_WAKE_CTRL |= RB_SLP_RTC_WAKE; // RTC唤醒
|
||||||
sys_safe_access_disable();
|
sys_safe_access_disable();
|
||||||
sys_safe_access_enable();
|
sys_safe_access_enable();
|
||||||
R8_RTC_MODE_CTRL |= RB_RTC_TRIG_EN; // 触发模式
|
R8_RTC_MODE_CTRL |= RB_RTC_TRIG_EN; // 触发模式
|
||||||
sys_safe_access_disable();
|
sys_safe_access_disable();
|
||||||
PFIC_EnableIRQ(RTC_IRQn);
|
// PFIC_EnableIRQ(RTC_IRQn);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue