[hwtimer] add disable interrupt protection for hwtimer_isr function

This commit is contained in:
Meco Man 2022-05-08 00:18:48 -04:00 committed by guo
parent 76a6f7f6dc
commit d5eeec2872
1 changed files with 19 additions and 1 deletions

View File

@ -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