Refactor and clean up codebase

- 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.
This commit is contained in:
cbb
2026-07-15 02:49:37 +08:00
parent a52d94687b
commit 76da7a3dd6
37 changed files with 1401 additions and 1955 deletions
+4 -4
View File
@@ -1,4 +1,4 @@
/**
/**
* @file config.h
* @brief 应用级集中配置项定义。
* @note 用于统一管理当前项目中可调的外设、时序、通信与算法常量。
@@ -16,9 +16,9 @@ constexpr const char *APP_BANNER_TEXT = "GD32E508 DCU task scheduler start";
* APP 固件版本号
* ============================================================ */
constexpr uint32_t APP_FW_VERSION_MAJOR = 1U;
constexpr uint32_t APP_FW_VERSION_MINOR = 2U;
constexpr uint32_t APP_FW_VERSION_PATCH = 3U;
constexpr uint32_t APP_FW_VERSION_BUILD = 2U;
constexpr uint32_t APP_FW_VERSION_MINOR = 3U;
constexpr uint32_t APP_FW_VERSION_PATCH = 0U;
constexpr uint32_t APP_FW_VERSION_BUILD = 0U;
/** @brief USART0 默认波特率。 */
+2 -1
View File
@@ -92,7 +92,6 @@ static uint32_t detectApb2Clock(void) {
}
extern "C" void HardFault_Handler_C(uint32_t *stack_frame, uint32_t lr_value) {
(void)lr_value;
/* 确保 USART0 时钟可用 */
volatile uint32_t *rcu_apb2en = (volatile uint32_t *)0x40021018U;
@@ -116,6 +115,8 @@ extern "C" void HardFault_Handler_C(uint32_t *stack_frame, uint32_t lr_value) {
*usart_ctl0 = (1U << 3) | (1U << 13); /* TE | USARTEN */
rawPuts("\r\n!!! HardFault !!!\r\n");
rawPuts("EXC_RETURN="); rawHex32(lr_value); rawPuts("\r\n");
/* EXC_RETURN 解析:bit3=0(MSP)/1(PSP), bit2=0(handler mode)/1(thread mode) */
if (stack_frame) {
uint32_t pc = stack_frame[6];
-6
View File
@@ -1,6 +0,0 @@
#ifndef HARDFAULT_H
#define HARDFAULT_H
void HardFault_Diagnostic(void);
#endif
@@ -217,6 +217,7 @@ void OtaBootRequest::process()
* BOOT 起机后再由 HELLO role=boot 确认。 */
/* SysTick 中断仍开,delayMs 可用;SPI 相关 IRQ 已关。 */
SysTickTimer::delayMs(kRebootDelayMs);
/* 复位前最终关中断:必须用 PRIMASK 全屏蔽(非 BASEPRI),确保 NVIC_SystemReset 过程中无任何中断嵌套 */
__disable_irq();
NVIC_SystemReset();
while(1) {
+1 -1
View File
@@ -42,7 +42,7 @@ public:
* @param[in] taskMask 待置位的任务位图掩码。
* @param[out] 无。
* @retval 无返回值。
* @note 内部通过保持当前 PRIMASK 状态的临界区保证可由主循环与 ISR 共享调用。
* @note 内部通过 BASEPRI 临界区(RT_CRITICAL_SAVE/RESTORE)保证可由主循环与 ISR 共享调用。
*/
static void set(uint32_t taskMask);
+2 -12
View File
@@ -59,7 +59,7 @@ static float medianFilter(const float *buffer)
} // namespace
struct TaskRunner::Runtime {
temp_sensor_data_t sample{};
Adc::Sample sample{};
float temperature_samples[kAdcFilterWindow] = {0.0f};
float vdda_samples[kAdcFilterWindow] = {0.0f};
float vin_adc_samples[kAdcFilterWindow] = {0.0f};
@@ -134,15 +134,6 @@ void TaskRunner::taskAdcProcess()
s.valid = sampleValid ? 1U : 0U;
}
/**
* @brief 执行兼容保留的 CAN 接收轮询任务。
* @param[in] 无。
* @param[out] 无。
* @retval 无返回值。
* @note 当前三路 CANFD 接收已由 RX0 中断驱动,该任务仅保留接口兼容性。
*/
void TaskRunner::taskCanRxPoll() { CanFd::poll(); }
/**
* @brief 执行 CAN 周期发送任务:每 1ms 在每个使能通道上发送一帧 CANFD 测试帧。
* @param[in] 无。
@@ -231,7 +222,7 @@ void TaskRunner::taskStatusLed() { /* 预留 */ }
* @param[in] 无。
* @param[out] 无。
* @retval 无返回值。
* @note 当前仅保留任务入口。
* @note 当前任务:推进 OTA Boot 请求、刷新 CAN 反馈快照、启动反馈推送轮次。
*/
void TaskRunner::taskHeartbeat() { OtaBootRequest::process(); CanFd::refreshFeedbackSnapshot(); canFeedbackStartRound(); }
@@ -382,7 +373,6 @@ void TaskRunner::runPending()
if(pending & (1UL << TASK_ADC_VREF_SAMPLE)) taskAdcVrefSample();
if(pending & (1UL << TASK_ADC_TEMP_SAMPLE)) taskAdcTempSample();
if(pending & (1UL << TASK_ADC_PROCESS)) taskAdcProcess();
if(pending & (1UL << TASK_CAN_RX_POLL)) taskCanRxPoll();
if(pending & (1UL << TASK_CAN_RX_PARSE)) taskCanRxParse();
if(pending & (1UL << TASK_CAN_TX_SEND)) taskCanTxSend();
if(pending & (1UL << TASK_STATUS_LED)) taskStatusLed();
-2
View File
@@ -35,8 +35,6 @@ private:
static void taskAdcTempSample();
/** @brief 根据采样值计算工程量。 */
static void taskAdcProcess();
/** @brief 兼容保留的 CAN 轮询任务。 */
static void taskCanRxPoll();
/** @brief 解析并消费接收帧。 */
static void taskCanRxParse();
/** @brief CAN 周期发送任务;每 1ms 每通道发送一帧测试报文。 */