mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-03-02 09:35:28 +08:00
[components][drivers]fix hardware timer
This commit is contained in:
parent
4fd6f2ef53
commit
f497b17111
@ -1,17 +1,16 @@
|
||||
定时器设备
|
||||
===
|
||||
# 定时器设备
|
||||
|
||||
## 功能
|
||||
|
||||
##功能
|
||||
---
|
||||
* 时间测量
|
||||
* 周期或单次执行回调函数
|
||||
|
||||
##编译
|
||||
---
|
||||
## 编译
|
||||
|
||||
1. 在rtconfig.h添加 `#define RT_USING_HWTIMER`
|
||||
|
||||
##使用流程
|
||||
---
|
||||
## 使用流程
|
||||
|
||||
1. 以读写方式打开设备
|
||||
2. 设置超时回调函数(如果需要)
|
||||
3. 根据需要设置定时模式(单次/周期)
|
||||
@ -22,9 +21,9 @@
|
||||
|
||||
应用参考 [hwtimer_test] (/examples/test/hwtimer\_test.c)
|
||||
|
||||
##驱动编写指南
|
||||
---
|
||||
###操作接口
|
||||
## 驱动编写指南
|
||||
|
||||
### 操作接口
|
||||
|
||||
```
|
||||
struct rt_hwtimer_ops
|
||||
@ -43,7 +42,7 @@ struct rt_hwtimer_ops
|
||||
* count_get - <读取计数器值>
|
||||
* control - <设置计数频率 >
|
||||
|
||||
###定时器特征信息
|
||||
### 定时器特征信息
|
||||
|
||||
```
|
||||
struct rt_hwtimer_info
|
||||
@ -60,7 +59,8 @@ struct rt_hwtimer_info
|
||||
* maxcnt <计数器最大计数值>
|
||||
* cntmode <递增计数/递减计数>
|
||||
|
||||
###注册设备
|
||||
### 注册设备
|
||||
|
||||
```
|
||||
static rt_hwtimer_t _timer0;
|
||||
int stm32_hwtimer_init(void)
|
||||
@ -74,7 +74,8 @@ int stm32_hwtimer_init(void)
|
||||
}
|
||||
```
|
||||
|
||||
###定时器中断
|
||||
### 定时器中断
|
||||
|
||||
```
|
||||
void timer_irq_handler(void)
|
||||
{
|
||||
@ -84,11 +85,9 @@ void timer_irq_handler(void)
|
||||
}
|
||||
```
|
||||
|
||||
##注意事项
|
||||
---
|
||||
|
||||
<font color="#FF0000">可能出现定时误差</font>
|
||||
## 注意事项
|
||||
|
||||
**可能出现定时误差**
|
||||
|
||||
误差原因:
|
||||
|
||||
|
@ -37,7 +37,7 @@ rt_inline rt_uint32_t timeout_calc(rt_hwtimer_t *timer, rt_hwtimerval_t *tv)
|
||||
{
|
||||
timeout = tv_sec/i;
|
||||
|
||||
if (timeout <= overflow)
|
||||
if (timeout <= overflow && timeout * timer->freq <= timer->info->maxcnt)
|
||||
{
|
||||
counter = timeout*timer->freq;
|
||||
devi = tv_sec - (counter/(float)timer->freq)*i;
|
||||
|
Loading…
x
Reference in New Issue
Block a user