Files
ESP32_COMM/main/include/ota_mutex.h
T
小龙虾 00ce8dbbb5 feat(ota): 实现 GD32 Flash 存储抽象层和 OTA 协调器接口解耦
- 新增 storage/gd32_flash_store.cpp 组件,提供 GD32 Flash 存储抽象层
- 修改 ota_coordinator.cpp/h 使其继承 IRelayListener 接口,实现与
  OtaRelay 的解耦设计
- 将 GD32 相关存储操作统一通过协调器访问,解决 H3 绕过协调器的问题
- 添加完整的 Doxygen 注释到所有公共接口和关键函数
- 更新 CMakeLists.txt 构建配置,添加 storage 组件依赖
- 重构元数据加载/清除操作使用 Gd32FlashStore 实例而非 OtaRelay 直接访问
- 添加中继事件回调接口实现,使 OtaRelay 可通知协调器状态变化
2026-06-21 23:48:31 +08:00

42 lines
1.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* 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; ///< ESP32 OTA 全局互斥锁句柄(main.cpp 中创建)
extern volatile bool g_esp32OtaOccupied; ///< ESP32 OTA 分区占用标志(true=正在OTA)
/**
* @brief 获取全局 OTA 占用标志(带超时)。
* @param timeout_ms 等待互斥锁的超时时间(毫秒)。
* @return true 成功获取并置占用标志,false 已占用或超时。
*/
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;
}
/**
* @brief 释放全局 OTA 占用标志。
* @note 内部: 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);
}