summaryrefslogtreecommitdiff
path: root/components/drivers
diff options
context:
space:
mode:
authorMeco Man <[email protected]>2022-05-08 00:18:48 -0400
committerguo <[email protected]>2022-05-11 15:28:50 +0800
commitd5eeec28724b426ed0f37250e5a07205e1dbcaaa (patch)
tree679efd864a7b0256ec0bedc372c1f6a8386b87fc /components/drivers
parent76a6f7f6dc636036ced4c97e4157c3a32f8719e6 (diff)
[hwtimer] add disable interrupt protection for hwtimer_isr function
Diffstat (limited to 'components/drivers')
-rw-r--r--components/drivers/hwtimer/hwtimer.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/components/drivers/hwtimer/hwtimer.c b/components/drivers/hwtimer/hwtimer.c
index 73a467fabb..774792c409 100644
--- a/components/drivers/hwtimer/hwtimer.c
+++ b/components/drivers/hwtimer/hwtimer.c
@@ -177,6 +177,7 @@ static rt_size_t rt_hwtimer_read(struct rt_device *dev, rt_off_t pos, void *buff
static rt_size_t rt_hwtimer_write(struct rt_device *dev, rt_off_t pos, const void *buffer, rt_size_t size)
{
+ rt_base_t level;
rt_uint32_t t;
rt_hwtimer_mode_t opm = HWTIMER_MODE_PERIOD;
rt_hwtimer_t *timer;
@@ -189,7 +190,10 @@ static rt_size_t rt_hwtimer_write(struct rt_device *dev, rt_off_t pos, const voi
return 0;
timer->ops->stop(timer);
+
+ level = rt_hw_interrupt_disable();
timer->overflow = 0;
+ rt_hw_interrupt_enable(level);
t = timeout_calc(timer, (rt_hwtimerval_t*)buffer);
if ((timer->cycles <= 1) && (timer->mode == HWTIMER_MODE_ONESHOT))
@@ -205,6 +209,7 @@ static rt_size_t rt_hwtimer_write(struct rt_device *dev, rt_off_t pos, const voi
static rt_err_t rt_hwtimer_control(struct rt_device *dev, int cmd, void *args)
{
+ rt_base_t level;
rt_err_t result = RT_EOK;
rt_hwtimer_t *timer;
@@ -247,7 +252,9 @@ static rt_err_t rt_hwtimer_control(struct rt_device *dev, int cmd, void *args)
result = timer->ops->control(timer, cmd, args);
if (result == RT_EOK)
{
+ level = rt_hw_interrupt_disable();
timer->freq = *f;
+ rt_hw_interrupt_enable(level);
}
}
else
@@ -284,8 +291,9 @@ static rt_err_t rt_hwtimer_control(struct rt_device *dev, int cmd, void *args)
result = -RT_ERROR;
break;
}
-
+ level = rt_hw_interrupt_disable();
timer->mode = *m;
+ rt_hw_interrupt_enable(level);
}
break;
default:
@@ -300,8 +308,12 @@ static rt_err_t rt_hwtimer_control(struct rt_device *dev, int cmd, void *args)
void rt_device_hwtimer_isr(rt_hwtimer_t *timer)
{
+ rt_base_t level;
+
RT_ASSERT(timer != RT_NULL);
+ level = rt_hw_interrupt_disable();
+
timer->overflow ++;
if (timer->cycles != 0)
@@ -313,6 +325,8 @@ void rt_device_hwtimer_isr(rt_hwtimer_t *timer)
{
timer->cycles = timer->reload;
+ rt_hw_interrupt_enable(level);
+
if (timer->mode == HWTIMER_MODE_ONESHOT)
{
if (timer->ops->stop != RT_NULL)
@@ -326,6 +340,10 @@ void rt_device_hwtimer_isr(rt_hwtimer_t *timer)
timer->parent.rx_indicate(&timer->parent, sizeof(struct rt_hwtimerval));
}
}
+ else
+ {
+ rt_hw_interrupt_enable(level);
+ }
}
#ifdef RT_USING_DEVICE_OPS