- Removed unused constants and type aliases in app_spi_command_defs.h and temp_sensor.h. - Simplified ISpiCommandHandler destructor to default. - Eliminated redundant methods and comments in temp_sensor and usart0 files. - Consolidated writeU32Le function to app_spi_command_defs.h for reuse. - Updated comments for clarity and accuracy in task_manager.h and task_runner.cpp. - Removed hardfault.h as it contained no declarations. - Cleaned up CANFD and watchdog implementations by removing dead code and unnecessary comments. - Updated version numbers in config.h to reflect recent changes. - Enhanced error handling and diagnostics in hardfault handling.
89 lines
3.3 KiB
C++
89 lines
3.3 KiB
C++
#ifndef MAIN_H
|
|
#define MAIN_H
|
|
|
|
#include "RTE_Components.h"
|
|
#include CMSIS_device_header
|
|
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
|
|
/**
|
|
* @brief 系统任务枚举定义。
|
|
* @note 每个枚举值对应任务调度器中的一个任务位,用于驱动主循环中的任务分发。
|
|
*/
|
|
enum system_task_t {
|
|
TASK_ADC_VREF_SAMPLE = 0, /**< 采样 VIN/VREF 原始值任务。 */
|
|
TASK_ADC_TEMP_SAMPLE, /**< 采样内部温度通道原始值任务。 */
|
|
TASK_ADC_PROCESS, /**< 对 ADC 原始值进行电压与温度计算任务。 */
|
|
TASK_CAN_RX_PARSE, /**< 解析并消费已接收 CANFD 帧任务。 */
|
|
TASK_CAN_TX_SEND, /**< CANFD 周期发送任务,每 1ms 每通道发送一帧。 */
|
|
TASK_STATUS_LED, /**< 状态灯维护任务。 */
|
|
TASK_HEARTBEAT, /**< 系统心跳维护任务。 */
|
|
TASK_DIAGNOSTIC_PRINT, /**< 诊断信息打印任务。 */
|
|
TASK_SPI_LOG, /**< SPI 延迟日志打印任务。 */
|
|
TASK_ETHERCAT_PROCESS, /**< EtherCAT 周期/事件处理任务(非实时应用层 PDO 映射)。 */
|
|
TASK_COUNT /**< 任务总数,用于边界或统计场景。 */
|
|
};
|
|
|
|
/**
|
|
* @brief 任务调度器状态结构体。
|
|
* @note 保存各类节拍计数器与待执行任务标志位,由中断与主循环共享访问。
|
|
*/
|
|
struct task_scheduler_t {
|
|
volatile uint32_t task_flags; /**< 待执行任务位图,每一位对应一个任务。 */
|
|
volatile uint32_t tick_100us; /**< 100us 基准节拍累计计数。 */
|
|
volatile uint32_t tick_1ms; /**< 1ms 节拍累计计数。 */
|
|
volatile uint32_t tick_10ms; /**< 10ms 节拍累计计数。 */
|
|
volatile uint32_t tick_100ms; /**< 100ms 节拍累计计数。 */
|
|
/** @brief 1s 节拍累计计数。 */
|
|
volatile uint32_t tick_1s;
|
|
/** @brief 调度分频计数:ADC VREF 采样。 */
|
|
volatile uint16_t div_vref_sample;
|
|
/** @brief 调度分频计数:ADC 温度采样/处理。 */
|
|
volatile uint16_t div_temp_sample;
|
|
/** @brief 调度分频计数:CAN 接收处理。 */
|
|
volatile uint16_t div_can_rx;
|
|
/** @brief 调度分频计数:CAN 周期发送(1ms)。 */
|
|
volatile uint16_t div_can_tx;
|
|
/** @brief 调度分频计数:状态灯(100ms)。 */
|
|
volatile uint16_t div_status_led;
|
|
/** @brief 调度分频计数:心跳(1s)。 */
|
|
volatile uint16_t div_heartbeat;
|
|
/** @brief 调度分频计数:APP 状态/诊断打印(5s)。 */
|
|
volatile uint16_t div_diag_print;
|
|
};
|
|
|
|
/**
|
|
* @brief 全局任务调度器状态实例。
|
|
* @note 由 TaskManager 管理,由中断与调试逻辑共享观察。
|
|
*/
|
|
extern task_scheduler_t g_scheduler;
|
|
|
|
/** @brief APP 运行秒数计数器,由 TaskManager::tick100us 在每秒节拍递增。 */
|
|
extern volatile uint32_t g_app_uptime_sec;
|
|
|
|
/**
|
|
* @brief 应用顶层对象。
|
|
* @note 负责组织初始化、横幅输出与主循环执行。
|
|
*/
|
|
class App {
|
|
public:
|
|
/**
|
|
* @brief 运行应用主循环。
|
|
* @param[in] 无。
|
|
* @param[out] 无。
|
|
* @retval int 固定返回 0;在嵌入式常驻循环场景下通常不会真正返回。
|
|
*/
|
|
int run();
|
|
|
|
private:
|
|
/**
|
|
* @brief 打印应用启动横幅与系统时钟信息。
|
|
* @param[in] 无。
|
|
* @param[out] 无。
|
|
* @retval 无返回值。
|
|
*/
|
|
void printBanner() const;
|
|
};
|
|
|
|
#endif /* MAIN_H */ |