This commit is contained in:
stark1898y 2025-04-13 23:18:47 +08:00
parent abc5ced7cb
commit c138885fdc
5 changed files with 61 additions and 20 deletions

View File

@ -131,7 +131,7 @@ void app_task_handler(TeAppEvtType app_evt_type)
{ {
BSP_BlockSleep(); BSP_BlockSleep();
// BSP_BlockSleep(); // BSP_BlockSleep();
BSP_RequestBoost(); // BSP_RequestBoost();
switch(app_evt_type) switch(app_evt_type)
{ {
@ -144,8 +144,8 @@ void app_task_handler(TeAppEvtType app_evt_type)
logDebug("LED显示状态"); logDebug("LED显示状态");
// tmos_set_event(led_task_id, LED_SHOW_START_EVT); // tmos_set_event(led_task_id, LED_SHOW_START_EVT);
BSP_BlockSleep(); BSP_BlockSleep();
BSP_RequestBoost(); // BSP_RequestBoost();
DelayMs(1); DelayMs(3);
ShowLed(); ShowLed();
// tmos_stop_task(led_task_id, LED_SHOW_ONCE_EVT); // tmos_stop_task(led_task_id, LED_SHOW_ONCE_EVT);
// tmos_start_task(led_task_id, LED_SHOW_ONCE_EVT, 1000); // tmos_start_task(led_task_id, LED_SHOW_ONCE_EVT, 1000);
@ -158,8 +158,8 @@ void app_task_handler(TeAppEvtType app_evt_type)
// tmos_set_event(led_task_id, LED_SHOW_START_EVT); // tmos_set_event(led_task_id, LED_SHOW_START_EVT);
gValveData.switch_status = kOpened; gValveData.switch_status = kOpened;
BSP_BlockSleep(); BSP_BlockSleep();
BSP_RequestBoost(); // BSP_RequestBoost();
DelayMs(1); DelayMs(3);
ShowLed(); ShowLed();
// tmos_stop_task(led_task_id, LED_SHOW_ONCE_EVT); // tmos_stop_task(led_task_id, LED_SHOW_ONCE_EVT);
// tmos_start_task(led_task_id, LED_SHOW_ONCE_EVT, 1000); // tmos_start_task(led_task_id, LED_SHOW_ONCE_EVT, 1000);
@ -172,8 +172,8 @@ void app_task_handler(TeAppEvtType app_evt_type)
// tmos_set_event(led_task_id, LED_SHOW_START_EVT); // tmos_set_event(led_task_id, LED_SHOW_START_EVT);
BSP_BlockSleep(); BSP_BlockSleep();
BSP_RequestBoost(); // BSP_RequestBoost();
DelayMs(1); DelayMs(3);
ShowLed(); ShowLed();
// tmos_stop_task(led_task_id, LED_SHOW_ONCE_EVT); // tmos_stop_task(led_task_id, LED_SHOW_ONCE_EVT);
// tmos_start_task(led_task_id, LED_SHOW_ONCE_EVT, 1000); // tmos_start_task(led_task_id, LED_SHOW_ONCE_EVT, 1000);
@ -221,6 +221,7 @@ __attribute__((noinline)) void Main_Circulation()
TMOS_SystemProcess(); TMOS_SystemProcess();
KEY_ProcessLoop(); KEY_ProcessLoop();
BSP_UART1_TxLoop(); BSP_UART1_TxLoop();
FEED_IWDG();
} }
} }
@ -261,9 +262,16 @@ int main(void)
// 改成 1500000 波特率了 // 改成 1500000 波特率了
BSP_UART1_Init(2500000); BSP_UART1_Init(2500000);
#endif #endif
DelayMs(1000 * 3); ShowRestartReason();
CH58x_BLEInit(); CH58x_BLEInit();
HAL_Init();
GAPRole_PeripheralInit();
Peripheral_Init();
DelayMs(1000 * 3);
// HAL_Init(); // HAL_Init();
// GAPRole_PeripheralInit(); // GAPRole_PeripheralInit();
// Peripheral_Init(); // Peripheral_Init();
@ -303,12 +311,9 @@ int main(void)
BSP_VAVLE_Init(); BSP_VAVLE_Init();
HAL_Init();
GAPRole_PeripheralInit();
Peripheral_Init();
BSP_BlockSleep(); BSP_BlockSleep();
BSP_RequestBoost(); BSP_RequestBoost();
DelayMs(10);
#if 0 #if 0
DelayMs(1); DelayMs(1);
EMV_CHARGE_EN; EMV_CHARGE_EN;
@ -368,7 +373,7 @@ int main(void)
ShowLed(); ShowLed();
BEEP_ON; BEEP_ON;
DelayMs(1000 * 1); DelayMs(500 * 1);
// tmos_set_event(Peripheral_TaskID, SBP_REPLY_CMD_EVT); // tmos_set_event(Peripheral_TaskID, SBP_REPLY_CMD_EVT);
#if 0 #if 0
@ -414,6 +419,8 @@ int main(void)
BSP_NoNeedBoost(); BSP_NoNeedBoost();
BSP_RequestSleep(); BSP_RequestSleep();
// IWDG_Init(IWDG_MS);
// 在连接间隔和广播间隔到来时,会进入回调中喂狗 // 在连接间隔和广播间隔到来时,会进入回调中喂狗
// LL_AdvertiseEventRegister(BLE_AdvertiseEventCB); // LL_AdvertiseEventRegister(BLE_AdvertiseEventCB);
// LL_ConnectEventRegister(BLE_ConnectEventCB); // LL_ConnectEventRegister(BLE_ConnectEventCB);

View File

@ -2,8 +2,8 @@
* @Author : stark1898y 1658608470@qq.com * @Author : stark1898y 1658608470@qq.com
* @Date : 2024-12-15 16:13:37 * @Date : 2024-12-15 16:13:37
* @LastEditors : stark1898y 1658608470@qq.com * @LastEditors : stark1898y 1658608470@qq.com
* @LastEditTime : 2024-12-15 16:13:37 * @LastEditTime : 2025-04-13 22:48:38
* @FilePath : \BLE_TYQ_CH584M - \BSP\inc\bsp_iwdg.h * @FilePath : \BLE_TYQ_CH584M\BSP\inc\bsp_iwdg.h
* @Description : * @Description :
* *
* Copyright (c) 2024 by yzy, All Rights Reserved. * Copyright (c) 2024 by yzy, All Rights Reserved.
@ -31,6 +31,10 @@
#define RB_WR_PROTECT 0x40000000 // RO, write protect #define RB_WR_PROTECT 0x40000000 // RO, write protect
#define RB_IWDG_EN 0x80000000 // RO, watch-dog enable #define RB_IWDG_EN 0x80000000 // RO, watch-dog enable
#define IWDG_MS (6000)
#define IWIG_FEED_EVENT (0x01 << 0)
void IWDG_Init(uint16_t ms); void IWDG_Init(uint16_t ms);
// 需要定时调用喂狗 // 需要定时调用喂狗

View File

@ -31,6 +31,8 @@ uint8_t BSP_ReadVbat(void)
uint8_t i; uint8_t i;
// VBAT // VBAT
uint32_t CountBat = 0; uint32_t CountBat = 0;
DelayUs(50);
ADC_InterBATSampInit(); ADC_InterBATSampInit();
DelayUs(50); DelayUs(50);
ADC_ExcutSingleConver(); ADC_ExcutSingleConver();
@ -38,10 +40,12 @@ uint8_t BSP_ReadVbat(void)
for (i = 0; i < 20; i++) for (i = 0; i < 20; i++)
{ {
adcBuff[i] = ADC_ExcutSingleConver(); // 连续采样20次 adcBuff[i] = ADC_ExcutSingleConver(); // 连续采样20次
// logDebug("%d", adcBuff[i]);
} }
for (i = 0; i < 20; i++) for (i = 0; i < 20; i++)
{ {
CountBat += adcBuff[i]; CountBat += adcBuff[i];
// logDebug("%d, %d", adcBuff[i], CountBat);
if (i == 0) if (i == 0)
{ {
min_number = adcBuff[i]; min_number = adcBuff[i];
@ -52,9 +56,11 @@ uint8_t BSP_ReadVbat(void)
} }
logDebug("min_number = %d, max_number = %d", min_number, max_number); logDebug("min_number = %d, max_number = %d", min_number, max_number);
CountBat = (CountBat - min_number - max_number) / 18; // 删除最小与最大值 CountBat = (CountBat - min_number - max_number) / 18; // 删除最小与最大值
// logDebug("CountBat = %d", CountBat);
// PGA=-12db // PGA=-12db
// CountBat = CountBat * 1050 / 512 - (3 * 1050); CountBat = CountBat * 1050 / 512 - (3 * 1050);
CountBat = CountBat * 2.05078125 - 3150; // CountBat = CountBat * 2.05078125 - 3150; // 有问题
// logDebug("CountBat = %d", CountBat);
uint8_t vbat = (uint8_t)((CountBat + 50) / 100); uint8_t vbat = (uint8_t)((CountBat + 50) / 100);
logDebug("AverageCountBat = %dmV, vbat = %d(100mV)", CountBat, vbat); logDebug("AverageCountBat = %dmV, vbat = %d(100mV)", CountBat, vbat);

View File

@ -24,6 +24,7 @@ tmosTaskID led_task_id = INVALID_TASK_ID;
void ShowLed() void ShowLed()
{ {
gValveData.bat = BSP_ReadVbat(); gValveData.bat = BSP_ReadVbat();
BSP_RequestBoost();
// 电压过低就关阀 // 电压过低就关阀
if (gValveData.bat <= LOW_VABAT_ALARM_VALUE) if (gValveData.bat <= LOW_VABAT_ALARM_VALUE)
@ -59,7 +60,7 @@ static tmosEvents LED_Task_ProcessEvent(tmosTaskID taskID, tmosEvents event)
logDebug("LED_SHOW_START_EVT"); logDebug("LED_SHOW_START_EVT");
BSP_BlockSleep(); BSP_BlockSleep();
BSP_RequestBoost(); BSP_RequestBoost();
DelayMs(1); DelayMs(3);
ShowLed(); ShowLed();
tmos_stop_task(led_task_id, LED_SHOW_ONCE_EVT); tmos_stop_task(led_task_id, LED_SHOW_ONCE_EVT);
tmos_start_task(led_task_id, LED_SHOW_ONCE_EVT, 1000); tmos_start_task(led_task_id, LED_SHOW_ONCE_EVT, 1000);

View File

@ -2,7 +2,7 @@
* @Author : stark1898y 1658608470@qq.com * @Author : stark1898y 1658608470@qq.com
* @Date : 2024-12-15 16:13:41 * @Date : 2024-12-15 16:13:41
* @LastEditors : stark1898y 1658608470@qq.com * @LastEditors : stark1898y 1658608470@qq.com
* @LastEditTime : 2025-02-22 17:28:20 * @LastEditTime : 2025-04-13 22:57:23
* @FilePath : \BLE_TYQ_CH584M\BSP\src\bsp_iwdg.c * @FilePath : \BLE_TYQ_CH584M\BSP\src\bsp_iwdg.c
* @Description : * @Description :
* *
@ -22,12 +22,27 @@
#undef LOG_TAG #undef LOG_TAG
#define LOG_TAG "idwg" #define LOG_TAG "idwg"
uint8_t IWDGTaskId;
uint16_t IWDG_ProcessEvent(uint8_t task_id, uint16_t events)
{
if (events & IWIG_FEED_EVENT)
{
FEED_IWDG();
tmos_start_task(task_id, IWIG_FEED_EVENT, 5000);
return (events ^ IWIG_FEED_EVENT);
}
return 0;
}
// 32k rc // 32k rc
// div 0:4 | 1:8 | 2:16 | 3:32 | // div 0:4 | 1:8 | 2:16 | 3:32 |
// 4:64 | 5:128 | 6:256 | 7:512(32K分频512时钟62.5Hz) | // 4:64 | 5:128 | 6:256 | 7:512(32K分频512时钟62.5Hz) |
// reload max 4095 // reload max 4095
// 独立看门狗IWDG由专用的内部低速时钟LSI驱动能够在低功耗模式下正常工作。 // 独立看门狗IWDG由专用的内部低速时钟LSI驱动能够在低功耗模式下正常工作。
// 根据寄存器描述IWDG最大时间可以是(0xFFF/(32K/512))=65.52s
void IWDG_Init(uint16_t ms) void IWDG_Init(uint16_t ms)
{ {
uint16_t div = 512; uint16_t div = 512;
@ -38,11 +53,18 @@ void IWDG_Init(uint16_t ms)
// 解除IWDG保护 // 解除IWDG保护
R32_IWDG_KR = 0x5555; R32_IWDG_KR = 0x5555;
R32_IWDG_CFG = (RB_PR & (div << 12)) | (RB_STOP_EN) | (reload & RB_RLR); // R32_IWDG_CFG = (RB_PR & (div << 12)) | (RB_STOP_EN) | (reload & RB_RLR);
R32_IWDG_CFG |= (7 << 12); // 32K分频512时钟62.5Hz
R32_IWDG_CFG &= 0xFFFFF000;
R32_IWDG_CFG |= 0x7D * 3; // 看门狗时间约256ms0x10/(32K/512))
// 开启IWDG保护 // 开启IWDG保护
R32_IWDG_KR = 0xCCCC; R32_IWDG_KR = 0xCCCC;
logDebug("R32_IWDG_CFG = %X", R32_IWDG_CFG); logDebug("R32_IWDG_CFG = %X", R32_IWDG_CFG);
IWDGTaskId = TMOS_ProcessEventRegister(IWDG_ProcessEvent);
tmos_set_event(IWDGTaskId, IWIG_FEED_EVENT);
} }
// #define RB_RESET_FLAG 0x07 // RO: recent reset flag // #define RB_RESET_FLAG 0x07 // RO: recent reset flag
@ -107,3 +129,4 @@ void ShowRestartReason(void)