Files
stc32g128k/Drivers/timer.h
edisondeng a7a2cc9465 暂存
2026-07-31 13:57:06 +08:00

32 lines
1.1 KiB
C
Raw 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.

#ifndef __TIMER_H__
#define __TIMER_H__
#include "../App/config.h"
/* ====== Timer0自由运行硬件时间戳基准 ====== */
/**
* @brief 初始化 Timer0 为常驻自由运行计数器
* @details 配置为 Mode 0 (STC 上为 16 位不停表计数)12T 模式下 24MHz 晶振对应 1 tick = 0.5us。
* 开机启动后永不停止,配合溢出中断 (Timer0_Isr) 把 16 位硬件计数扩展为 32 位软件时间戳,
* 供 RF 边沿中断解码等需要高精度时间差测量的场景使用。
*/
void Timer0_Init(void);
/**
* @brief 获取以 Timer0 为基准的 32 位自由运行时间戳 (单位: 0.5us tick)
* @details 内部处理了读取瞬间恰逢硬件计数器溢出的读数撕裂问题。
*/
u32 Timer0_GetTimestamp(void);
/* ====== Timer1系统 1ms 基准滴答 ====== */
/**
* @brief 初始化 Timer1 定时器,生成系统基准时钟 (1ms 中断)
* @details 配置定时器 1 为 16 位自动重装载模式,设定中断周期为 1.0 毫秒,
* 开启 Timer1 中断并启动计数,同时在此统一开启全局中断允许 (EA = 1)。
*/
void Timer1_Init(void);
#endif // __TIMER_H__