diff --git a/APP/peripheral_main.c b/APP/peripheral_main.c index cfae4fd..b186b71 100644 --- a/APP/peripheral_main.c +++ b/APP/peripheral_main.c @@ -31,6 +31,8 @@ #include "bsp_valve.h" +#include "bsp_bat.h" + #undef LOG_ENABLE #define LOG_ENABLE 1 @@ -375,6 +377,8 @@ int main(void) DelayMs(500 * 1); + // BSP_BAT_Init(); + // tmos_set_event(Peripheral_TaskID, SBP_REPLY_CMD_EVT); #if 0 // GPIOA_ModeCfg(GPIO_Pin_2, GPIO_ModeIN_Floating); diff --git a/BSP/inc/bsp_bat.h b/BSP/inc/bsp_bat.h new file mode 100644 index 0000000..bb6e063 --- /dev/null +++ b/BSP/inc/bsp_bat.h @@ -0,0 +1,16 @@ +#ifndef __BSP_BAT_H__ +#define __BSP_BAT_H__ + + +#include "CONFIG.h" + +void BSP_BAT_Init(void); + + + + + + + + +#endif //!@__BSP_BAT_H__ diff --git a/BSP/src/bsp_bat.c b/BSP/src/bsp_bat.c new file mode 100644 index 0000000..11bcbf4 --- /dev/null +++ b/BSP/src/bsp_bat.c @@ -0,0 +1,44 @@ +#include "bsp_bat.h" + +#include "bsp_uart.h" +#include "log.h" + +#undef LOG_ENABLE +#define LOG_ENABLE 1 + +#undef LOG_TAG +#define LOG_TAG "bat" + +void BSP_BAT_Init(void) +{ + // 低精度 + PowerMonitor(ENABLE, LPLevel_2V1); + PFIC_EnableIRQ(WDOG_BAT_IRQn); + + // 高精度 + // PowerMonitor(ENABLE, HALevel_2V5); +} + +__INTERRUPT +__HIGH_CODE +void WDOG_BAT_IRQHandler(void) +{ + logDebug("R8_BAT_STATUS=%x.", R8_BAT_STATUS); + while (R8_BAT_STATUS & RB_BAT_STAT_LOWER) // 等电压恢复 + { + logDebug("BAT low.."); + } + logDebug("BAT normal.."); +} + +__INTERRUPT +__HIGH_CODE +void NMI_IRQHandler(void) +{ + // logDebug("R8_BAT_STATUS=%x.",R8_BAT_STATUS); + // while(R8_BAT_STATUS&RB_BAT_STAT_LOWER) //等电压恢复 + // { + // logDebug("BAT low.. "); + // } + // logDebug("BAT normal.."); +} diff --git a/BSP/src/bsp_key.c b/BSP/src/bsp_key.c index 3d391e7..44c0baf 100644 --- a/BSP/src/bsp_key.c +++ b/BSP/src/bsp_key.c @@ -124,6 +124,8 @@ void BSP_KEY_EnterLowpower(void) // 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_SLP_GPIO_WAKE | RB_SLP_BAT_WAKE, Long_Delay); + BSP_RequestSleep(); #endif } diff --git a/StdPeriphDriver/CH58x_pwr.c b/StdPeriphDriver/CH58x_pwr.c index 25daa80..4df395c 100644 --- a/StdPeriphDriver/CH58x_pwr.c +++ b/StdPeriphDriver/CH58x_pwr.c @@ -6,7 +6,7 @@ * Description : source file(ch585/ch584) ********************************************************************************* * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. - * Attention: This software (modified or not) and binary are used for + * Attention: This software (modified or not) and binary are used for * microcontroller manufactured by Nanjing Qinheng Microelectronics. *******************************************************************************/ @@ -28,7 +28,7 @@ void PWR_DCDCCfg(FunctionalState s) if(s == DISABLE) { - + adj &= ~RB_DCDC_CHARGE; plan &= ~(RB_PWR_DCDC_EN | RB_PWR_DCDC_PRE); // · DC/DC sys_safe_access_enable(); @@ -227,7 +227,7 @@ void PowerMonitor(FunctionalState s, VolM_LevelypeDef vl) } else { - + cfg = vl & 0x03; ctrl = RB_BAT_DET_EN; } @@ -374,7 +374,7 @@ void LowPower_Sleep(uint16_t rm) flash_sck = R8_FLASH_SCK; sys_safe_access_enable(); - R8_BAT_DET_CTRL = 0; // رյѹ + // R8_BAT_DET_CTRL = 0; // رյѹ sys_safe_access_disable(); sys_safe_access_enable(); R8_XT32M_TUNE = x32Mpw;