내부 60초 주기 배터리 저전압/고온 점검

- 배터리 저전압(3500이하) 5회 이상 연속인 경우 전원 OFF
- IMU 온도 고온(40도 이상) 5회 이상 연속인 경우 전원 OFF
This commit is contained in:
2026-06-15 15:56:04 +09:00
parent 78c46c07ea
commit cfae61eff4
+38 -2
View File
@@ -21,6 +21,7 @@
#include "battery_adc.h" #include "battery_adc.h"
#include "debug_print.h" #include "debug_print.h"
#include "imu_i2c.h"
#include "main.h" #include "main.h"
/*============================================================================== /*==============================================================================
@@ -42,6 +43,10 @@ volatile uint16_t info_batt = 0;
static struct k_timer battery_timer; static struct k_timer battery_timer;
static struct k_work battery_work; static struct k_work battery_work;
static uint8_t low_battery_cnt = 0; static uint8_t low_battery_cnt = 0;
static uint8_t high_temperature_cnt = 0;
#define BATTERY_MONITOR_LIMIT_COUNT 5U
#define HIGH_TEMPERATURE_CDEG 4000 /* 40.00 C */
#define BATTERY_MONITOR_INTERVAL_MS 60000 /* 60초 주기 */ #define BATTERY_MONITOR_INTERVAL_MS 60000 /* 60초 주기 */
@@ -159,17 +164,48 @@ static void battery_work_handler(struct k_work *work)
low_battery_cnt++; low_battery_cnt++;
DBG_PRINTF("[BATT] LOW! cnt=%d mv=%d\r\n", low_battery_cnt, batt); DBG_PRINTF("[BATT] LOW! cnt=%d mv=%d\r\n", low_battery_cnt, batt);
if (low_battery_cnt >= 10) if (low_battery_cnt >= BATTERY_MONITOR_LIMIT_COUNT)
{ {
low_battery_cnt = 0; low_battery_cnt = 0;
DBG_PRINTF("[BATT] 10x low -> Power OFF\r\n"); DBG_PRINTF("[BATT] %ux low -> Power OFF\r\n", BATTERY_MONITOR_LIMIT_COUNT);
sleep_mode_enter(); sleep_mode_enter();
return;
} }
} }
else else
{ {
low_battery_cnt = 0; low_battery_cnt = 0;
} }
int16_t temp_cdeg = 0;
int temp_ret = imu_read_temperature_cdeg(&temp_cdeg);
if (temp_ret != 0)
{
DBG_PRINTF("[TEMP] IMU read failed ret=%d\r\n", temp_ret);
return;
}
if (temp_cdeg > HIGH_TEMPERATURE_CDEG)
{
high_temperature_cnt++;
DBG_PRINTF("[TEMP] HIGH! cnt=%d temp=%d.%02d C\r\n",
high_temperature_cnt,
temp_cdeg / 100,
(temp_cdeg < 0 ? -temp_cdeg : temp_cdeg) % 100);
if (high_temperature_cnt >= BATTERY_MONITOR_LIMIT_COUNT)
{
high_temperature_cnt = 0;
DBG_PRINTF("[TEMP] %ux high -> Power OFF\r\n", BATTERY_MONITOR_LIMIT_COUNT);
sleep_mode_enter();
return;
}
}
else
{
high_temperature_cnt = 0;
}
} }
/* 타이머 ISR → k_work 예약 */ /* 타이머 ISR → k_work 예약 */