Files
CHJ/user/MCU/lhl_systick.c
2026-03-20 21:19:53 +08:00

50 lines
1.5 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "../main/SystemInclude.h"
/**------------------------------------------------------------------------
* @brief 初始化系统滴答定时器 (SysTick)
* @note 配置 SysTick 以最低优先级运行,用于提供系统时钟节拍(通常为 1ms
* 该函数应在系统初始化时调用一次。
* @param 无
* @example SysTickInit();
**/
void SysTickInit(void)
{
LHL_SysTick_Init(LHL_TICK_PRIO_LOWEST); // 设置Systick优先级最低
}
/**------------------------------------------------------------------------
* @brief 获取系统运行的毫秒数
* @return 从系统启动或上次复位至今的毫秒计数值32位无符号整数
* @note 该值由 SysTick 中断每 1ms 递增一次,可用于实现软件定时或延时。
* @example u32 current_ms = GetSystemMs();
**/
u32 GetSystemMs(void)
{
return LHL_GetTick();
}
/**------------------------------------------------------------------------
* @brief SysTick 中断服务函数(每 1ms 触发一次)
* @note 内部调用 LHL_IncTick() 递增系统时钟节拍计数器。
* 该计数器用于支撑 LHL_Delay()、LHL_GetTick() 等延时和计时功能。
* @param 无
**/
void SysTick_Handler(void)
{
/* 开启Systick毫秒计时 */
LHL_IncTick();
}
/**------------------------------------------------------------------------
* @brief 毫秒级阻塞延时函数
* @param ms: 要延时的毫秒数
* @note 此函数为 LHL_Delay(ms) 的简单封装,如需使用可取消注释。
* 阻塞延时期间 CPU 无法执行其他任务,请谨慎用于长时间延时。
* @example systick_delay_ms(1000); // 延时 1 秒
**/
//void systick_delay_ms(u32 ms)
//{
// LHL_Delay(ms);
//}