2026-06-26 00:57:59 +08:00
|
|
|
/**
|
2026-05-10 17:28:14 +08:00
|
|
|
* @file initial.cpp
|
|
|
|
|
* @brief 应用启动初始化实现。
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "sys/initial.h"
|
|
|
|
|
|
|
|
|
|
#include "device/canfd.h"
|
|
|
|
|
#include "device/temp_sensor.h"
|
|
|
|
|
#include "device/usart0.h"
|
2026-06-26 00:57:59 +08:00
|
|
|
#include "device/timer.h"
|
2026-05-10 17:28:14 +08:00
|
|
|
#include "device/adc.h"
|
2026-05-30 00:24:31 +08:00
|
|
|
#include "device/watchdog.h"
|
2026-06-26 00:57:59 +08:00
|
|
|
#include "device/spi/app_spi_command.h"
|
2026-05-10 17:28:14 +08:00
|
|
|
#include "sys/systick.h"
|
2026-05-30 00:24:31 +08:00
|
|
|
#include "sys/ota_boot_request.h"
|
2026-05-10 17:28:14 +08:00
|
|
|
#include "sys/task_manager.h"
|
2026-06-26 00:57:59 +08:00
|
|
|
#include "sys/config.h"
|
|
|
|
|
#include "comm/ethercat_slave.h"
|
|
|
|
|
#include "comm/ethercat_sync.h"
|
2026-05-10 17:28:14 +08:00
|
|
|
|
2026-05-10 21:27:51 +08:00
|
|
|
/**
|
|
|
|
|
* @brief 执行应用级外设与调度初始化。
|
|
|
|
|
* @param[in] 无。
|
|
|
|
|
* @param[out] 无。
|
|
|
|
|
* @retval 无返回值。
|
|
|
|
|
* @note 依次完成 SysTick、USART0、ADC/温度采样、CANFD、任务管理器与调度定时器的启动。
|
|
|
|
|
*/
|
2026-05-10 17:28:14 +08:00
|
|
|
void AppInitializer::init()
|
|
|
|
|
{
|
2026-06-29 01:51:02 +08:00
|
|
|
/* 必须最先设置 NVIC 优先级分组:确保后续 CanFd/SPI0 等外设 init 中
|
|
|
|
|
* 编码抢占/子优先级字节时使用正确的分组(PRE4_SUB0),避免在错误分组
|
|
|
|
|
* 下编码后被重新解释。EtherCAT 实时架构整改 Task3。 */
|
|
|
|
|
nvic_priority_group_set(CONFIG_NVIC_PRIORITY_GROUP);
|
2026-05-30 20:03:31 +08:00
|
|
|
printf("[APP] init: SysTick...\r\n");
|
2026-05-10 17:28:14 +08:00
|
|
|
SysTickTimer::initMs();
|
2026-05-30 20:03:31 +08:00
|
|
|
printf("[APP] init: USART0...\r\n");
|
2026-05-10 17:28:14 +08:00
|
|
|
Usart0::configurePins();
|
|
|
|
|
Usart0::init();
|
2026-05-30 20:03:31 +08:00
|
|
|
printf("[APP] init: TempSensor...\r\n");
|
2026-05-10 17:28:14 +08:00
|
|
|
TempSensor::init();
|
2026-05-30 20:03:31 +08:00
|
|
|
printf("[APP] init: CANFD...\r\n");
|
2026-05-10 17:28:14 +08:00
|
|
|
CanFd::init();
|
2026-05-30 20:03:31 +08:00
|
|
|
printf("[APP] init: OtaBootRequest...\r\n");
|
2026-05-30 00:24:31 +08:00
|
|
|
OtaBootRequest::init();
|
2026-05-30 20:03:31 +08:00
|
|
|
printf("[APP] init: AppSpiCommand...\r\n");
|
2026-06-23 01:49:33 +08:00
|
|
|
AppSpiCommandBus.init();
|
2026-05-30 20:03:31 +08:00
|
|
|
printf("[APP] init: TaskManager...\r\n");
|
2026-05-10 17:28:14 +08:00
|
|
|
TaskManager::init();
|
2026-05-30 20:03:31 +08:00
|
|
|
printf("[APP] init: SchedulerTimer...\r\n");
|
2026-05-10 17:28:14 +08:00
|
|
|
SchedulerTimer::init();
|
2026-06-26 00:57:59 +08:00
|
|
|
printf("[APP] init: EthercatSlave...\r\n");
|
|
|
|
|
EthercatSlave::init();
|
2026-06-29 01:51:02 +08:00
|
|
|
if (EthercatSlave::isEscReady()) {
|
|
|
|
|
printf("[APP] init: EthercatSync...\r\n");
|
|
|
|
|
EthercatSync::init();
|
|
|
|
|
} else {
|
|
|
|
|
printf("[APP] init: EthercatSync SKIPPED (ESC not ready)\r\n");
|
|
|
|
|
}
|
2026-05-30 20:03:31 +08:00
|
|
|
printf("[APP] init: Watchdog...\r\n");
|
2026-05-30 00:24:31 +08:00
|
|
|
Watchdog::init();
|
2026-05-30 20:03:31 +08:00
|
|
|
printf("[APP] init: all done\r\n");
|
2026-05-30 00:24:31 +08:00
|
|
|
}
|