尝试bat监控

This commit is contained in:
stark1898y 2025-05-06 09:17:24 +08:00
parent c745aca701
commit 54cd61e37f
5 changed files with 70 additions and 4 deletions

View File

@ -31,6 +31,8 @@
#include "bsp_valve.h" #include "bsp_valve.h"
#include "bsp_bat.h"
#undef LOG_ENABLE #undef LOG_ENABLE
#define LOG_ENABLE 1 #define LOG_ENABLE 1
@ -375,6 +377,8 @@ int main(void)
DelayMs(500 * 1); DelayMs(500 * 1);
// BSP_BAT_Init();
// tmos_set_event(Peripheral_TaskID, SBP_REPLY_CMD_EVT); // tmos_set_event(Peripheral_TaskID, SBP_REPLY_CMD_EVT);
#if 0 #if 0
// GPIOA_ModeCfg(GPIO_Pin_2, GPIO_ModeIN_Floating); // GPIOA_ModeCfg(GPIO_Pin_2, GPIO_ModeIN_Floating);

16
BSP/inc/bsp_bat.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef __BSP_BAT_H__
#define __BSP_BAT_H__
#include "CONFIG.h"
void BSP_BAT_Init(void);
#endif //!@__BSP_BAT_H__

44
BSP/src/bsp_bat.c Normal file
View File

@ -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..");
}

View File

@ -124,6 +124,8 @@ 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);
BSP_RequestSleep(); BSP_RequestSleep();
#endif #endif
} }

View File

@ -6,7 +6,7 @@
* Description : source file(ch585/ch584) * Description : source file(ch585/ch584)
********************************************************************************* *********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. * 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. * microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/ *******************************************************************************/
@ -28,7 +28,7 @@ void PWR_DCDCCfg(FunctionalState s)
if(s == DISABLE) if(s == DISABLE)
{ {
adj &= ~RB_DCDC_CHARGE; adj &= ~RB_DCDC_CHARGE;
plan &= ~(RB_PWR_DCDC_EN | RB_PWR_DCDC_PRE); // ÅÔ· DC/DC plan &= ~(RB_PWR_DCDC_EN | RB_PWR_DCDC_PRE); // ÅÔ· DC/DC
sys_safe_access_enable(); sys_safe_access_enable();
@ -227,7 +227,7 @@ void PowerMonitor(FunctionalState s, VolM_LevelypeDef vl)
} }
else else
{ {
cfg = vl & 0x03; cfg = vl & 0x03;
ctrl = RB_BAT_DET_EN; ctrl = RB_BAT_DET_EN;
} }
@ -374,7 +374,7 @@ void LowPower_Sleep(uint16_t rm)
flash_sck = R8_FLASH_SCK; flash_sck = R8_FLASH_SCK;
sys_safe_access_enable(); sys_safe_access_enable();
R8_BAT_DET_CTRL = 0; // 关闭电压监控 // R8_BAT_DET_CTRL = 0; // 关闭电压监控
sys_safe_access_disable(); sys_safe_access_disable();
sys_safe_access_enable(); sys_safe_access_enable();
R8_XT32M_TUNE = x32Mpw; R8_XT32M_TUNE = x32Mpw;