- 启用CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE和CONFIG_APP_ROLLBACK_ENABLE配置选项 - 在main.cpp中添加esp_ota_mark_app_valid_cancel_rollback()调用,防止意外回滚 - 实现SHA-256固件完整性校验,包括计算、存储和验证功能 - 添加ota_mutex.h头文件用于ESP32 OTA全局互斥锁管理 feat(health_monitor): 实现线程安全的健康状态管理 - 将HealthMonitor类的健康状态改为私有成员并通过mutex保护 - 添加getState()和setState()方法提供线程安全的状态访问 - 修复多任务并发访问健康状态时的竞争条件问题 feat(ota_relay): 增强中继模块的线程安全性和可靠性 - 为OtaRelay类添加静态mutex保护状态变量访问 - 实现StateLockGuard RAII锁管理器确保异常安全 - 添加全局超时机制防止OTA过程无限等待 - 改进flash写入逻辑支持非4字节对齐数据处理 refactor(app_config): 更新版本信息和配置常量 - 更新BUILD_TIME至最新编译时间 - 更新GIT_HASH至最新提交 - 添加BLE_OTA_CTRL_VERIFY_SHA256命令常量定义
37 lines
1.2 KiB
C++
37 lines
1.2 KiB
C++
/*
|
|
* ota_mutex.h - ESP32 OTA 全局互斥(BLE / WiFi 通道共享)
|
|
*
|
|
* 同一时刻只允许一个 OTA 源(BLE 或 WiFi)操作 ESP32 OTA 分区。
|
|
* 变量定义 + Mutex 创建在 main.cpp app_main()。
|
|
*/
|
|
#pragma once
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/semphr.h"
|
|
#include <cstdint>
|
|
|
|
extern SemaphoreHandle_t g_esp32OtaMutex;
|
|
extern volatile bool g_esp32OtaOccupied;
|
|
|
|
// 获取全局 OTA 占用标志(带超时),成功返回 true
|
|
// 内部: Take Mutex → 检查标志 → 若空闲则置 true → Give Mutex
|
|
static inline bool esp32_ota_mutex_acquire(uint32_t timeout_ms) {
|
|
if (!g_esp32OtaMutex) return false;
|
|
if (xSemaphoreTake(g_esp32OtaMutex, pdMS_TO_TICKS(timeout_ms)) != pdTRUE) return false;
|
|
if (g_esp32OtaOccupied) {
|
|
xSemaphoreGive(g_esp32OtaMutex);
|
|
return false;
|
|
}
|
|
g_esp32OtaOccupied = true;
|
|
xSemaphoreGive(g_esp32OtaMutex);
|
|
return true;
|
|
}
|
|
|
|
// 释放全局 OTA 占用标志
|
|
// 内部: Take Mutex → 清除标志 → Give Mutex
|
|
static inline void esp32_ota_mutex_release(void) {
|
|
if (!g_esp32OtaMutex) return;
|
|
xSemaphoreTake(g_esp32OtaMutex, portMAX_DELAY);
|
|
g_esp32OtaOccupied = false;
|
|
xSemaphoreGive(g_esp32OtaMutex);
|
|
}
|