Files
ESP32_COMM/main/core/main.cpp
T
小龙虾 df27ef3a98 docs(readme): 更新项目文档并移除过时文件
- 添加详细的项目介绍,包括硬件平台、功能模块和目录结构
- 移除旧的 docs/README.md 和 docs/tasks.md 文件
- 更新 .gitignore 添加 .cache/ 目录
- 调整 CMakeLists.txt 依赖项顺序,添加 mbedtls
- 简化头文件包含,移除不必要的 esp_log.h 和 esp_netif_types.h 引用
2026-04-27 03:00:48 +08:00

101 lines
2.7 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.
/*
* ESP32-C3FH4 OTA 中继 - 程序入口
* 四个 FreeRTOS 任务:System Monitor / OTA Relay / WiFi Server / BLE GATT
*/
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_chip_info.h"
#include "monitor/health_monitor.h"
#include "relay/ota_relay.h"
#include "transport/spi_master.h"
#include "server/wifi_ota.h"
#include "server/ble_ota.h"
#include "transport/protocol.h"
#include "monitor/debug_log.h"
extern "C" void app_main(void)
{
esp_chip_info_t chip_info;
esp_chip_info(&chip_info);
// 初始化调试日志(UDP 输出到上位机)
debug_log_init();
DEBUG_INFO("MAIN", "========================================");
DEBUG_INFO("MAIN", "ESP32-C3 OTA Relay v1.0 启动");
DEBUG_INFO("MAIN", "Chip: %s, Rev %d", CONFIG_IDF_TARGET, chip_info.revision);
DEBUG_INFO("MAIN", "Free heap: %lu bytes", esp_get_free_heap_size());
DEBUG_INFO("MAIN", "========================================");
// 健康监控任务(温度 + 电压 + WiFi RSSI)
xTaskCreatePinnedToCore(
health_monitor_task,
"health_mon",
4096,
NULL,
configMAX_PRIORITIES - 4,
NULL,
0
);
// 初始化协议层(CRC、AES)
protocol_init();
DEBUG_INFO("MAIN", "协议层初始化完成");
// 初始化 SPI 总线
esp_err_t ret = spi_master_init();
if (ret != ESP_OK) {
DEBUG_ERR("MAIN", "SPI 总线初始化失败: %d", ret);
} else {
DEBUG_INFO("MAIN", "SPI 总线初始化完成");
}
// 创建 FreeRTOS 任务
BaseType_t xRet;
// OTA 中继任务(中高优先级)
xRet = xTaskCreatePinnedToCore(
ota_relay_task,
"ota_relay",
8192,
NULL,
configMAX_PRIORITIES - 2,
NULL,
0 // 核0
);
if (xRet != pdPASS) {
DEBUG_ERR("MAIN", "创建 ota_relay_task 失败");
}
// WiFi OTA 服务器任务
xRet = xTaskCreatePinnedToCore(
wifi_ota_task,
"wifi_ota",
8192,
NULL,
configMAX_PRIORITIES - 3,
NULL,
0
);
if (xRet != pdPASS) {
DEBUG_ERR("MAIN", "创建 wifi_ota_task 失败");
}
// BLE OTA 任务
xRet = xTaskCreatePinnedToCore(
ble_ota_task,
"ble_ota",
8192,
NULL,
configMAX_PRIORITIES - 3,
NULL,
0 // ESP32-C3 单核,固定核0
);
if (xRet != pdPASS) {
DEBUG_ERR("MAIN", "创建 ble_ota_task 失败");
}
DEBUG_INFO("MAIN", "所有任务创建完成,OTA Relay 运行中");
DEBUG_INFO("MAIN", "调试日志输出到上位机: %s:%d", DEBUG_LOG_IP, DEBUG_LOG_PORT);
}