GP Timer
概述
通用定时器( General Purpose Timer , GP Timer 或 GTMR ),当内部计数器计数到指定值时会产生定时中断,指定值由软件配置。
系统中的 GP imer
WQ7036 每个子系统有一组 GP timer ,每组 GP timer 包含 4 个定时器,可以满足系统各种复杂的定时需求。
功能特性
GP Timer 主要支持如下特性:
32bit 的计数数值。
向上计数。
设置溢出阈值。
通过 GPIO 输入将计数器锁存。
软件暂停计数和清零。
四路独立的定时器。
两路定时器级联以实现 64bit 计数。
工作模式
调用 wq_timer_init() 函数时,则 TIMER 有以下工作特征:
timer 默认支持级联模式,前两个计数器( timer0 与 timer1 )可以级联成一个 64bit 的计数器。
timer0 与 timer1 被设置为计数到指定值后,计数器仍继续计数。
剩余 timer 控制器被设置为计数到指定值后,计数器保持当前数值并不再计数。
所有 timer 控制器禁用 div 模式,切换到 1M tick 模式。
开启 timer0 。
资源依赖
GTIMER
用法流程
初始化
wq_timer_init()获取现 timer0 计数值 ( 32bit )
wq_timer_get_time()获取现 timer0 与 timer1 的组合计数值 ( 64bit )
wq_timer_get_time64()利用 timer0 延迟微秒时间
wq_timer_delay_us()利用 timer0 延迟毫秒时间
wq_timer_delay_ms()创建 timer ( 从前两个计数器之后开始申请 )处理句柄
wq_timer_create()开启 timer
wq_timer_start()关闭 timer
wq_timer_stop()删除 timer
wq_timer_delete()
参考示例
/examples/timer_demo/
API 介绍
Typedefs
-
typedef void (*wq_timer_func_t)(uint32_t timer_id, void *arg)
Functions
-
uint32_t wq_timer_create(uint32_t time, wq_timer_func_t func, void *arg, bool repeat)
Create a hardware timer.
- 参数:
time -- [in] timer time in microsecond.
func -- [in] timer handler function.
arg -- [in] timer handler argument.
repeat -- [in] Is timer repeat.
- 返回:
uint32_t 0 for Bad param or no memory,else for timer handle.
-
WQ_RET wq_timer_start(uint32_t timer)
Start a hardware timer.
参见
wq_timer_create
- 参数:
timer -- [in] timer handle create by
- 返回:
WQ_RET_OK Success.
WQ_RET_INVAL Bad param.
-
WQ_RET wq_timer_stop(uint32_t timer)
Stop a hardware timer.
参见
wq_timer_create
- 参数:
timer -- [in] timer handle create by
- 返回:
WQ_RET_OK Success.
WQ_RET_INVAL Bad param.
WQ_RET_NOT_EXIST No timer to stop.
-
WQ_RET wq_timer_delete(uint32_t timer)
Delete a hardware timer.
参见
wq_timer_create
- 参数:
timer -- [in] timer handle create by
- 返回:
WQ_RET_OK Success.
WQ_RET_INVAL Bad param.
-
void wq_timer_init(void)
Init timer hardware.
备注
Need to be called before the timer related function can be invoked.
-
uint32_t wq_timer_get_time(void)
Get current timer count, unit us.
- 返回:
uint32_t is current time.
-
uint64_t wq_timer_get_time64(void)
Get current timer count with 64bit value, unit us.
- 返回:
uint64_t is current time.
-
void wq_timer_delay_us(uint32_t delay_us)
This function is to circular wait for delay time using timer in us.
备注
Busy delay
- 参数:
delay_us -- is delay target(us).
-
void wq_timer_delay_ms(uint32_t ms)
This function is to circular wait for delay time using timer in ms.
备注
Busy delay
- 参数:
ms -- is delay target(ms).