- 新增SPI 0xC8命令用于切换CAN通道收发器Silent模式(只听不发) - 在canFdSetTxSilent函数中实现静默模式控制逻辑 - 在HTTP API中添加POST /can/silent端点 - 更新CAN协议文档,记录新命令和错误码E6 - 修改bus_state位图,添加bit5表示静默状态 fix(can): 优化CAN反馈任务内存使用和链路离线处理 - 将任务栈上的临时缓冲区改为静态分配,防止栈溢出 - 添加链路在线检测,在离线状态下进入休眠退避 - 修复queryMotorStatePages和queryAdcFeedback函数返回值类型 - 优化UDP日志发送的冷却退避机制 chore(config): 更新调试日志配置和版本信息 - 在VSCode设置中添加ESP-IDF串口配置 - 添加SPI调试日志级别编译期开关CONFIG_SPI_DEBUG_LOG_LEVEL - 更新固件版本至0.5.2,记录相关变更内容 - 调整SPI和CAN反馈任务的栈大小配置
87 lines
2.9 KiB
C++
87 lines
2.9 KiB
C++
/*
|
|
* task_stack.cpp - 任务栈水位收集 + FreeRTOS 栈溢出钩子
|
|
*
|
|
* 水位表:health_mon 巡检 + /system/status 共用。
|
|
* 溢出钩子:CONFIG_FREERTOS_CHECK_STACKOVERFLOW_CANARY 下内核回调;
|
|
* 被踩栈上下文禁止 mutex/网络/格式化,仅 UART0 硬写 + abort。
|
|
*/
|
|
#include "task_stack.h"
|
|
|
|
#include <cstring>
|
|
#include "app_config.h"
|
|
#include "health_monitor.h"
|
|
#include "cpu_stats.h"
|
|
#include "ota_relay.h"
|
|
#include "wifi_ota.h"
|
|
#include "ble_ota.h"
|
|
#include "spi_master.h"
|
|
#include "can_feedback_task.h"
|
|
#include "driver/uart.h"
|
|
#include "esp_system.h"
|
|
|
|
// ============================================================
|
|
// 栈溢出钩子
|
|
// ============================================================
|
|
volatile bool g_stackOverflowDetected = false;
|
|
|
|
extern "C" void vApplicationStackOverflowHook(TaskHandle_t xTask, char *pcTaskName)
|
|
{
|
|
(void)xTask;
|
|
g_stackOverflowDetected = true;
|
|
|
|
static const char prefix[] = "\r\n!!! STACK OVERFLOW in task: ";
|
|
uart_write_bytes(UART_NUM_0, prefix, sizeof(prefix) - 1);
|
|
uart_write_bytes(UART_NUM_0, pcTaskName, strnlen(pcTaskName, configMAX_TASK_NAME_LEN));
|
|
static const char suffix[] = " !!!\r\n";
|
|
uart_write_bytes(UART_NUM_0, suffix, sizeof(suffix) - 1);
|
|
|
|
/* OTA 末尾若 httpd 栈溢出却不 abort,前端会一直停在 100%。 */
|
|
esp_system_abort("stack overflow");
|
|
}
|
|
|
|
// ============================================================
|
|
// 任务栈水位表
|
|
// ============================================================
|
|
size_t collectTaskStackMetrics(TaskStackMetric* out, size_t max)
|
|
{
|
|
if (!out || max == 0) {
|
|
return 0;
|
|
}
|
|
|
|
size_t n = 0;
|
|
|
|
// httpd 无公开句柄;未 httpd_start 时 xTaskGetHandle 为 NULL
|
|
if (n < max) {
|
|
out[n++] = { "http_server", xTaskGetHandle("httpd"), HTTP_SERVER_STACK_SIZE };
|
|
}
|
|
if (n < max) {
|
|
out[n++] = { "health_mon", HealthMonitor::instance().getTaskHandle(), TASK_STACK_HEALTH_MON };
|
|
}
|
|
if (n < max) {
|
|
out[n++] = { "cpu_stats", CpuStats::instance().getTaskHandle(), TASK_STACK_CPU_STATS };
|
|
}
|
|
if (n < max) {
|
|
out[n++] = { "ota_relay", OtaRelay::getTaskHandle(), TASK_STACK_OTA_RELAY };
|
|
}
|
|
if (n < max) {
|
|
out[n++] = { "spi_worker", SpiMaster::instance().getWorkerTaskHandle(), TASK_STACK_SPI_WORKER };
|
|
}
|
|
if (n < max) {
|
|
out[n++] = { "wifi_ota", WifiOta::instance().getTaskHandle(), TASK_STACK_WIFI_OTA };
|
|
}
|
|
if (n < max) {
|
|
out[n++] = { "wifi_reconnect", WifiOta::instance().m_reconnectTask, TASK_STACK_WIFI_RECONNECT };
|
|
}
|
|
if (n < max) {
|
|
out[n++] = { "ble_ota", BleOta::instance().getTaskHandle(), TASK_STACK_BLE_OTA };
|
|
}
|
|
if (n < max) {
|
|
out[n++] = { "ble_ota_worker", BleOta::instance().getWorkerTaskHandle(), TASK_STACK_BLE_WORKER };
|
|
}
|
|
if (n < max) {
|
|
out[n++] = { "can_fb", getCanFeedbackTaskHandle(), TASK_STACK_CAN_FB };
|
|
}
|
|
|
|
return n;
|
|
}
|