2026-05-10 21:27:51 +08:00
|
|
|
/**
|
|
|
|
|
* @file main.cpp
|
|
|
|
|
* @brief 应用主入口与顶层流程实现。
|
|
|
|
|
*/
|
|
|
|
|
|
2026-05-10 17:28:14 +08:00
|
|
|
#include "main.h"
|
|
|
|
|
#include "sys/initial.h"
|
2026-05-10 21:27:51 +08:00
|
|
|
#include "sys/task_manager.h"
|
2026-05-10 17:28:14 +08:00
|
|
|
#include "sys/task_runner.h"
|
|
|
|
|
#include "sys/config.h"
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 打印应用启动横幅与系统时钟信息。
|
2026-05-10 21:27:51 +08:00
|
|
|
* @param[in] 无。
|
|
|
|
|
* @param[out] 无。
|
|
|
|
|
* @retval 无返回值。
|
|
|
|
|
* @note 该函数仅负责串口输出启动提示,不修改系统控制状态。
|
2026-05-10 17:28:14 +08:00
|
|
|
*/
|
|
|
|
|
void App::printBanner() const
|
|
|
|
|
{
|
|
|
|
|
printf("\r\n%s\r\n", APP_BANNER_TEXT);
|
|
|
|
|
printf("SystemCoreClock=%u Hz\r\n", SystemCoreClock);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 运行应用主循环。
|
2026-05-10 21:27:51 +08:00
|
|
|
* @param[in] 无。
|
|
|
|
|
* @param[out] 无。
|
2026-05-10 17:28:14 +08:00
|
|
|
* @retval int 固定返回 0;在嵌入式常驻循环场景下通常不会真正返回。
|
2026-05-10 21:27:51 +08:00
|
|
|
* @note 完成系统初始化、任务运行时初始化和启动横幅输出后,持续执行任务分发循环。
|
2026-05-10 17:28:14 +08:00
|
|
|
*/
|
|
|
|
|
int App::run()
|
|
|
|
|
{
|
|
|
|
|
AppInitializer::init();
|
|
|
|
|
TaskRunner::init();
|
|
|
|
|
printBanner();
|
|
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
|
TaskRunner::runPending();
|
2026-05-10 21:27:51 +08:00
|
|
|
if(TaskManager::state().task_flags == 0U) {
|
|
|
|
|
__WFI();
|
|
|
|
|
}
|
2026-05-10 17:28:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-10 21:27:51 +08:00
|
|
|
/**
|
|
|
|
|
* @brief 程序入口函数。
|
|
|
|
|
* @param[in] 无。
|
|
|
|
|
* @param[out] 无。
|
|
|
|
|
* @retval int 返回应用主循环执行结果;在嵌入式常驻场景下通常不会返回。
|
|
|
|
|
* @note 创建应用顶层对象并转入 `App::run()`。
|
|
|
|
|
*/
|
2026-05-10 17:28:14 +08:00
|
|
|
int main(void)
|
|
|
|
|
{
|
|
|
|
|
App app;
|
|
|
|
|
return app.run();
|
|
|
|
|
}
|