summaryrefslogtreecommitdiff
path: root/components/drivers
diff options
context:
space:
mode:
authorMeco Man <[email protected]>2020-12-30 03:44:37 -0600
committerGitHub <[email protected]>2020-12-30 03:44:37 -0600
commit4a4f00de6bf553a7b047acb2f43b38693c0afaa2 (patch)
treea7db2443e8409bf1304291c583498340364ba6e8 /components/drivers
parent3bca2cfb418f03c529fc8563b62c19d391caf90b (diff)
parent4c399f88bb15416e833e9b86ad9de46807ca12e0 (diff)
Merge pull request #8 from RT-Thread/master
pr
Diffstat (limited to 'components/drivers')
-rw-r--r--components/drivers/hwtimer/hwtimer.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/components/drivers/hwtimer/hwtimer.c b/components/drivers/hwtimer/hwtimer.c
index 3953919fae..976d8bbf32 100644
--- a/components/drivers/hwtimer/hwtimer.c
+++ b/components/drivers/hwtimer/hwtimer.c
@@ -10,6 +10,7 @@
#include <rtthread.h>
#include <rtdevice.h>
+#include <rthw.h>
rt_inline rt_uint32_t timeout_calc(rt_hwtimer_t *timer, rt_hwtimerval_t *tv)
{
@@ -144,19 +145,25 @@ static rt_size_t rt_hwtimer_read(struct rt_device *dev, rt_off_t pos, void *buff
rt_hwtimer_t *timer;
rt_hwtimerval_t tv;
rt_uint32_t cnt;
+ rt_base_t level;
+ rt_int32_t overflow;
float t;
timer = (rt_hwtimer_t *)dev;
if (timer->ops->count_get == RT_NULL)
return 0;
+ level = rt_hw_interrupt_disable();
cnt = timer->ops->count_get(timer);
+ overflow = timer->overflow;
+ rt_hw_interrupt_enable(level);
+
if (timer->info->cntmode == HWTIMER_CNTMODE_DW)
{
cnt = (timer->freq * timer->period_sec) - cnt;
}
- t = timer->overflow * timer->period_sec + cnt/(float)timer->freq;
+ t = overflow * timer->period_sec + cnt/(float)timer->freq;
tv.sec = t;
tv.usec = (t - tv.sec) * 1000000;
size = size > sizeof(tv)? sizeof(tv) : size;