- 添加CANFD发送完成中断处理函数,确保只有MTFNERR置位时才计数发送成功 - 新增通道健康检查功能,防止病态通道被持续重发的测试帧反复推回BUS_OFF - 重构CANFD配置结构体,添加TX中断配置项并修正GPIO映射设置 - 移除原有的软件发送队列机制,改为直接硬件发送模式 - 更新项目配置文件中的CANFD源文件路径命名 fix(canfd): 修复CANFD发送计数和错误处理逻辑 - 修正发送计数只在硬件MTFNERR确认后增加,而非请求进入邮箱时 - 改进错误日志输出,添加详细的错误类型和通道状态信息 - 优化总线恢复机制,通过收发器静默-唤醒协助硬件自动恢复 - 添加条件编译开关控制启动时自检和回环测试功能
68 lines
2.3 KiB
C++
68 lines
2.3 KiB
C++
/**
|
|
* @file initial.cpp
|
|
* @brief 应用启动初始化实现。
|
|
*/
|
|
|
|
#include "sys/initial.h"
|
|
|
|
#include "device/canfd.h"
|
|
#include "device/temp_sensor.h"
|
|
#include "device/usart0.h"
|
|
#include "device/timer.h"
|
|
#include "device/adc.h"
|
|
#include "device/watchdog.h"
|
|
#include "device/spi/app_spi_command.h"
|
|
#include "sys/systick.h"
|
|
#include "sys/ota_boot_request.h"
|
|
#include "sys/task_manager.h"
|
|
#include "sys/config.h"
|
|
#include "comm/ethercat_slave.h"
|
|
#include "comm/ethercat_sync.h"
|
|
|
|
/**
|
|
* @brief 执行应用级外设与调度初始化。
|
|
* @param[in] 无。
|
|
* @param[out] 无。
|
|
* @retval 无返回值。
|
|
* @note 依次完成 SysTick、USART0、ADC/温度采样、CANFD、任务管理器与调度定时器的启动。
|
|
*/
|
|
void AppInitializer::init()
|
|
{
|
|
/* 必须最先设置 NVIC 优先级分组:确保后续 CanFd/SPI0 等外设 init 中
|
|
* 编码抢占/子优先级字节时使用正确的分组(PRE4_SUB0),避免在错误分组
|
|
* 下编码后被重新解释。EtherCAT 实时架构整改 Task3。 */
|
|
nvic_priority_group_set(CONFIG_NVIC_PRIORITY_GROUP);
|
|
printf("[APP] init: SysTick...\r\n");
|
|
SysTickTimer::initMs();
|
|
/* ESP32 EN/RESET (PC9) 直接配置为推挽输出高电平,保持 ESP32 正常运行 */
|
|
rcu_periph_clock_enable(RCU_GPIOC);
|
|
gpio_bit_set(CONFIG_ESP32_RESET_PORT, CONFIG_ESP32_RESET_PIN);
|
|
gpio_init(CONFIG_ESP32_RESET_PORT, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, CONFIG_ESP32_RESET_PIN);
|
|
printf("[APP] init: USART0...\r\n");
|
|
Usart0::configurePins();
|
|
Usart0::init();
|
|
printf("[APP] init: TempSensor...\r\n");
|
|
TempSensor::init();
|
|
printf("[APP] init: CANFD...\r\n");
|
|
CanFd::init();
|
|
printf("[APP] init: OtaBootRequest...\r\n");
|
|
OtaBootRequest::init();
|
|
printf("[APP] init: AppSpiCommand...\r\n");
|
|
AppSpiCommandBus.init();
|
|
printf("[APP] init: TaskManager...\r\n");
|
|
TaskManager::init();
|
|
printf("[APP] init: SchedulerTimer...\r\n");
|
|
SchedulerTimer::init();
|
|
printf("[APP] init: EthercatSlave...\r\n");
|
|
EthercatSlave::init();
|
|
if (EthercatSlave::isEscReady()) {
|
|
printf("[APP] init: EthercatSync...\r\n");
|
|
EthercatSync::init();
|
|
} else {
|
|
printf("[APP] init: EthercatSync SKIPPED (ESC not ready)\r\n");
|
|
}
|
|
printf("[APP] init: Watchdog...\r\n");
|
|
Watchdog::init();
|
|
printf("[APP] init: all done\r\n");
|
|
}
|