feat(bootloader): 实现APP延迟启动模式支持OTA请求检测

当APP可用但未激活时,系统现在会进入延迟启动模式,在指定时间内
监听CAN总线上的OTA请求。如果在此期间收到OTA请求,则进入OTA模式;
否则超时后自动跳转到APP。

新增配置参数APP_DELAY_BOOT_TIME用于设置延迟启动时间,默认为10秒。
在延迟期间,系统持续进行CAN通信检查和OTA心跳消息发送,确保能够
及时响应OTA更新请求。

此功能增强了系统的OTA更新灵活性,允许在启动过程中动态决定
是否进行固件更新而不是强制进入OTA模式。
This commit is contained in:
cbb
2026-04-26 03:36:45 +08:00
parent d019b41ed6
commit 46d4bfe8ef
11 changed files with 908 additions and 912 deletions
+35 -4
View File
@@ -34,14 +34,45 @@ void BootloaderSystem::run() {
// 正常模式:跳转到APP
ota.jumpToApplication();
} else if (app_check == OTA_AVAL and
app_enable == OTA_NOT_AVAL) { // 手动禁用APP,进入OTA模式
app_enable == OTA_NOT_AVAL) { // APP可用但未激活,延迟进入APP
#if DEBUG_OTA
printf("OTA Mode1\r\n");
printf("Delay Boot Mode: APP available but not enabled, jumping in %d ms...\r\n", APP_DELAY_BOOT_TIME);
#endif
// OTA模式
while (1) {
// 延迟启动模式:倒计时期间监听CAN,收到OTA请求则进入OTA模式
u32 delay_count = 0;
bool ota_requested = false;
while (delay_count < APP_DELAY_BOOT_TIME) {
// 检查CAN通信并处理接收到的消息
CAN0_transmiter.communication_check();
// 调用ota.process()发送心跳消息(IDAEL状态下会发送CANFD_OTA_WAIT_ID)
ota.process();
// 检查是否收到OTA请求
if (ota.isActive()) {
ota_requested = true;
break;
}
delay_count+=10;
}
if (ota_requested) {
#if DEBUG_OTA
printf("OTA request received during delay, entering OTA mode...\r\n");
#endif
// 收到OTA请求,进入OTA模式
while (1) {
CAN0_transmiter.communication_check();
ota.process();
}
} else {
#if DEBUG_OTA
printf("Delay timeout, jumping to APP...\r\n");
#endif
// 超时未收到OTA请求,跳转APP
ota.jumpToApplication();
}
} else { // APP无效,确认backup
volatile u32 *flash_ptr = (volatile u32 *)n_APP_BACKUP_AVAL_ADDR;