2026-05-10 17:28:14 +08:00
|
|
|
#ifndef SYS_SYSTICK_H
|
|
|
|
|
#define SYS_SYSTICK_H
|
|
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief SysTick 时基模块。
|
|
|
|
|
* @note 负责 1ms 系统节拍维护与阻塞式毫秒延时。
|
|
|
|
|
*/
|
|
|
|
|
class SysTickTimer {
|
|
|
|
|
public:
|
2026-05-10 21:27:51 +08:00
|
|
|
/**
|
|
|
|
|
* @brief 初始化 SysTick 为 1ms 系统节拍。
|
|
|
|
|
* @param[in] 无。
|
|
|
|
|
* @param[out] 无。
|
2026-09-02 02:38:35 +08:00
|
|
|
* @retval bool true=配置成功且中断真实触发;false=配置失败或节拍未前进。
|
|
|
|
|
* @note 失败时系统失去时基(后续 delayMs 不可用),调用方应按致命错误处理。
|
2026-05-10 21:27:51 +08:00
|
|
|
*/
|
2026-09-02 02:38:35 +08:00
|
|
|
static bool initMs();
|
2026-05-10 21:27:51 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 执行阻塞式毫秒延时。
|
|
|
|
|
* @param[in] ms 需要延时的毫秒数。
|
|
|
|
|
* @param[out] 无。
|
|
|
|
|
* @retval 无返回值。
|
|
|
|
|
* @note 基于 1ms 中断递增的节拍计数器实现轮询延时。
|
|
|
|
|
*/
|
2026-05-10 17:28:14 +08:00
|
|
|
static void delayMs(uint32_t ms);
|
2026-05-10 21:27:51 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief SysTick 中断处理入口。
|
|
|
|
|
* @param[in] 无。
|
|
|
|
|
* @param[out] 无。
|
|
|
|
|
* @retval 无返回值。
|
|
|
|
|
* @note 每毫秒递增内部节拍计数器。
|
|
|
|
|
*/
|
2026-05-10 17:28:14 +08:00
|
|
|
static void onInterrupt();
|
|
|
|
|
|
2026-07-08 02:51:24 +08:00
|
|
|
/**
|
|
|
|
|
* @brief 获取当前系统毫秒节拍数。
|
|
|
|
|
* @return 自启动以来的毫秒数(32 位回绕)。
|
|
|
|
|
* @note 用于超时判定(如 SPI 按铃看护)。读取 volatile 原子。
|
|
|
|
|
*/
|
|
|
|
|
static uint32_t getMs() { return s_ms; }
|
|
|
|
|
|
2026-05-10 17:28:14 +08:00
|
|
|
private:
|
|
|
|
|
static volatile uint32_t s_ms;
|
|
|
|
|
};
|
|
|
|
|
|
2026-05-10 21:27:51 +08:00
|
|
|
#endif /* SYS_SYSTICK_H */
|