summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorMan, Jianting (Meco) <[email protected]>2022-05-09 10:59:27 -0400
committerGitHub <[email protected]>2022-05-09 22:59:27 +0800
commit0d2b96d7cc8c1cf52a6a86a4004777baada6794f (patch)
tree49492e0d1e817a174066021102ef8c92acc91ba5 /components
parent96dd783f37d44556c8d470a13b45b6bd4e28ac2c (diff)
[stm32][l4] add tim7 support | 设备框架以及驱动错误码处理逻辑存在问题 (#5901)
Diffstat (limited to 'components')
-rw-r--r--components/drivers/hwtimer/README_CN.md97
-rw-r--r--components/drivers/hwtimer/hwtimer.c8
-rw-r--r--components/drivers/misc/dac.c1
3 files changed, 6 insertions, 100 deletions
diff --git a/components/drivers/hwtimer/README_CN.md b/components/drivers/hwtimer/README_CN.md
deleted file mode 100644
index 810b1b1d80..0000000000
--- a/components/drivers/hwtimer/README_CN.md
+++ /dev/null
@@ -1,97 +0,0 @@
-# 定时器设备
-
-## 功能
-
-* 时间测量
-* 周期或单次执行回调函数
-
-## 编译
-
-1. 在rtconfig.h添加 `#define RT_USING_HWTIMER`
-
-## 使用流程
-
-1. 以读写方式打开设备
-2. 设置超时回调函数(如果需要)
-3. 根据需要设置定时模式(单次/周期)
-4. 设置计数频率(可选)
-5. 写入超时值,定时器随即启动
-6. 停止定时器(可选)
-7. 关闭设备(如果需要)
-
-应用参考 [hwtimer_test] (/examples/test/hwtimer\_test.c)
-
-## 驱动编写指南
-
-### 操作接口
-
-```
-struct rt_hwtimer_ops
-{
- void (*init)(struct rt_hwtimer_device *timer, rt_uint32_t state);
- rt_err_t (*start)(struct rt_hwtimer_device *timer, rt_uint32_t cnt, rt_hwtimer_mode_t mode);
- void (*stop)(struct rt_hwtimer_device *timer);
- rt_uint32_t (*count_get)(struct rt_hwtimer_device *timer);
- rt_err_t (*control)(struct rt_hwtimer_device *timer, rt_uint32_t cmd, void *args);
-};
-```
-
-* init - state <1 打开设备 0 关闭设备>
-* start - cnt <超时值> - mode <单次/周期>
-* stop - <停止计数>
-* count_get - <读取计数器值>
-* control - <设置计数频率 >
-
-### 定时器特征信息
-
-```
-struct rt_hwtimer_info
-{
- rt_int32_t maxfreq;
- rt_int32_t minfreq;
- rt_uint32_t maxcnt;
- rt_uint8_t cntmode;
- };
-```
-
-* maxfreq <设备支持的最大计数频率>
-* minfreq <设备支持的最小计数频率>
-* maxcnt <计数器最大计数值>
-* cntmode <递增计数/递减计数>
-
-### 注册设备
-
-```
-static rt_hwtimer_t _timer0;
-int stm32_hwtimer_init(void)
-{
- _timer0.info = &_info;
- _timer0.ops = &_ops;
-
- rt_device_hwtimer_register(&_timer0, "timer0", TIM2);
-
- return 0;
-}
-```
-
-### 定时器中断
-
-```
-void timer_irq_handler(void)
-{
- //其它操作
-
- rt_device_hwtimer_isr(&_timer0);
-}
-```
-
-## 注意事项
-
-**可能出现定时误差**
-
-误差原因:
-
-假设计数器最大值0xFFFF,计数频率1Mhz,定时时间1秒又1微秒。
-
-由于定时器一次最多只能计时到65535us,对于1000001us的定时要求。
-可以50000us定时20次完成,此时将会出现计算误差1us。
diff --git a/components/drivers/hwtimer/hwtimer.c b/components/drivers/hwtimer/hwtimer.c
index c1a7b75ecc..73a467fabb 100644
--- a/components/drivers/hwtimer/hwtimer.c
+++ b/components/drivers/hwtimer/hwtimer.c
@@ -8,10 +8,13 @@
* 2015-08-31 heyuanjie87 first version
*/
-#include <rtthread.h>
#include <rtdevice.h>
#include <rthw.h>
+#define DBG_TAG "hwtimer"
+#define DBG_LVL DBG_INFO
+#include <rtdbg.h>
+
rt_inline rt_uint32_t timeout_calc(rt_hwtimer_t *timer, rt_hwtimerval_t *tv)
{
float overflow;
@@ -234,7 +237,8 @@ static rt_err_t rt_hwtimer_control(struct rt_device *dev, int cmd, void *args)
f = (rt_uint32_t*)args;
if ((*f > timer->info->maxfreq) || (*f < timer->info->minfreq))
{
- result = -RT_ERROR;
+ LOG_W("frequency setting out of range! It will maintain at %d Hz", timer->freq);
+ result = -RT_EINVAL;
break;
}
diff --git a/components/drivers/misc/dac.c b/components/drivers/misc/dac.c
index ecbadfd502..c1176cc36c 100644
--- a/components/drivers/misc/dac.c
+++ b/components/drivers/misc/dac.c
@@ -8,7 +8,6 @@
* 2020-06-19 thread-liu the first version
*/
-#include <rtthread.h>
#include <rtdevice.h>
#include <string.h>