- 新增s_channelHwOk数组跟踪各通道硬件初始化状态 - 修改CANFD初始化流程,在GPIO上电后延时200ms再进入Normal模式 - 实现selfTestL0()轻量自检函数,检查硬件初始化、退出init模式、收发器状态等 - 更新CANFD初始化逻辑,只有自检通过才标记为成功 refactor(spi): 调整SPI DMA和EXTI配置顺序避免通信失步 - 将armSpiDmasForNextCs()调用移至configureExti()之前 - 添加注释说明DMA预装和EXTI开启的时序要求 - 避免OTA跳转后ESP32立即发送HELLO导致的SPI从机失步问题 fix(app_spi): 修复HELLO_ACK响应中credit初始化问题 - 在HELLO_ACK构建前将g_localCredit设置为1 - 与requestEsp32Read()保持一致避免TX占用时credit=0的问题 - 防止主机因remoteCredit=0而拒绝发送PING帧 refactor(initial): 重构应用初始化流程添加模块状态跟踪 - 引入ModuleBit枚举和掩码机制跟踪各模块初始化状态 - 实现mark()和report()方法统一管理模块启动结果 - 按NVIC→SysTick→ESP32_EN→USART0→AppSpi→ADC→CANFD→OTA→TaskManager→Scheduler→EtherCAT→Watchdog顺序启动 - 将CANFD模块成功条件改为selfTestL0()通过才标记成功
152 lines
4.1 KiB
C++
152 lines
4.1 KiB
C++
/**
|
|
* @file initial.cpp
|
|
* @brief 应用启动初始化:模块成功置位,结束统一报告结果。
|
|
*
|
|
* 顺序:
|
|
* NVIC → SysTick → ESP32_EN 保持 → USART0 → AppSpi(尽早 HELLO 探活)→
|
|
* ADC → CANFD → OtaBootRequest → TaskManager → Scheduler →
|
|
* EtherCAT(+Sync 可选) → Watchdog → report
|
|
*/
|
|
|
|
#include "sys/initial.h"
|
|
|
|
#include "device/canfd.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"
|
|
|
|
uint32_t AppInitializer::s_mask = 0U;
|
|
|
|
namespace {
|
|
|
|
struct InitEntry {
|
|
uint32_t bit;
|
|
const char *name;
|
|
bool critical;
|
|
};
|
|
|
|
static const InitEntry kEntries[] = {
|
|
{ AppInitializer::kNvic, "nvic", true },
|
|
{ AppInitializer::kSysTick, "systick", true },
|
|
{ AppInitializer::kEsp32Hold, "esp32_hold", true },
|
|
{ AppInitializer::kUsart0, "usart0", true },
|
|
{ AppInitializer::kAppSpi, "app_spi", true },
|
|
{ AppInitializer::kAdc, "adc", true },
|
|
{ AppInitializer::kCanFd, "canfd", true },
|
|
{ AppInitializer::kOtaBootReq, "ota_boot_req", true },
|
|
{ AppInitializer::kTaskManager, "task_manager", true },
|
|
{ AppInitializer::kScheduler, "scheduler", true },
|
|
{ AppInitializer::kEthercat, "ethercat", false },
|
|
{ AppInitializer::kEthercatSync, "ethercat_sync", false },
|
|
{ AppInitializer::kWatchdog, "watchdog", true },
|
|
};
|
|
|
|
} // namespace
|
|
|
|
void AppInitializer::mark(ModuleBit b)
|
|
{
|
|
s_mask |= static_cast<uint32_t>(b);
|
|
}
|
|
|
|
void AppInitializer::report()
|
|
{
|
|
bool critical_ok = true;
|
|
bool all_ok = true;
|
|
char fail_list[160] = {0};
|
|
size_t fail_len = 0U;
|
|
|
|
for (size_t i = 0; i < sizeof(kEntries) / sizeof(kEntries[0]); ++i) {
|
|
const InitEntry &e = kEntries[i];
|
|
const bool ok = (s_mask & e.bit) != 0U;
|
|
if (ok) {
|
|
continue;
|
|
}
|
|
all_ok = false;
|
|
if (e.critical) {
|
|
critical_ok = false;
|
|
}
|
|
if (fail_len + 2U < sizeof(fail_list)) {
|
|
if (fail_len > 0U) {
|
|
fail_list[fail_len++] = ',';
|
|
}
|
|
const char *p = e.name;
|
|
while (*p != '\0' && fail_len + 1U < sizeof(fail_list)) {
|
|
fail_list[fail_len++] = *p++;
|
|
}
|
|
fail_list[fail_len] = '\0';
|
|
}
|
|
}
|
|
|
|
if (critical_ok && all_ok) {
|
|
printf("[APP] init: OK (all modules)\r\n");
|
|
} else if (critical_ok) {
|
|
printf("[APP] init: OK (critical), skipped/failed: %s\r\n",
|
|
fail_list[0] != '\0' ? fail_list : "?");
|
|
} else {
|
|
printf("[APP] init: FAIL, modules: %s\r\n",
|
|
fail_list[0] != '\0' ? fail_list : "?");
|
|
}
|
|
}
|
|
|
|
void AppInitializer::init()
|
|
{
|
|
s_mask = 0U;
|
|
|
|
nvic_priority_group_set(CONFIG_NVIC_PRIORITY_GROUP);
|
|
mark(kNvic);
|
|
|
|
SysTickTimer::initMs();
|
|
mark(kSysTick);
|
|
|
|
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);
|
|
mark(kEsp32Hold);
|
|
|
|
Usart0::configurePins();
|
|
Usart0::init();
|
|
mark(kUsart0);
|
|
|
|
/* SPI 尽早就绪:OTA FINISH 跳转后 ESP32 用 HELLO 探活,不能等 CAN 上电延时 */
|
|
AppSpiCommandBus.init();
|
|
mark(kAppSpi);
|
|
|
|
Adc::init();
|
|
mark(kAdc);
|
|
|
|
CanFd::init();
|
|
/* L0 通过才置 canfd 位 */
|
|
if (CanFd::selfTestL0()) {
|
|
mark(kCanFd);
|
|
}
|
|
|
|
OtaBootRequest::init();
|
|
mark(kOtaBootReq);
|
|
|
|
TaskManager::init();
|
|
mark(kTaskManager);
|
|
|
|
SchedulerTimer::init();
|
|
mark(kScheduler);
|
|
|
|
EthercatSlave::init();
|
|
if (EthercatSlave::isEscReady()) {
|
|
mark(kEthercat);
|
|
EthercatSync::init();
|
|
mark(kEthercatSync);
|
|
}
|
|
|
|
Watchdog::init();
|
|
mark(kWatchdog);
|
|
|
|
report();
|
|
}
|