[hwtimer] add disable interrupt protection for hwtimer_isr function
This commit is contained in:
parent
76a6f7f6dc
commit
d5eeec2872
|
@ -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)
|
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_uint32_t t;
|
||||||
rt_hwtimer_mode_t opm = HWTIMER_MODE_PERIOD;
|
rt_hwtimer_mode_t opm = HWTIMER_MODE_PERIOD;
|
||||||
rt_hwtimer_t *timer;
|
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;
|
return 0;
|
||||||
|
|
||||||
timer->ops->stop(timer);
|
timer->ops->stop(timer);
|
||||||
|
|
||||||
|
level = rt_hw_interrupt_disable();
|
||||||
timer->overflow = 0;
|
timer->overflow = 0;
|
||||||
|
rt_hw_interrupt_enable(level);
|
||||||
|
|
||||||
t = timeout_calc(timer, (rt_hwtimerval_t*)buffer);
|
t = timeout_calc(timer, (rt_hwtimerval_t*)buffer);
|
||||||
if ((timer->cycles <= 1) && (timer->mode == HWTIMER_MODE_ONESHOT))
|
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)
|
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_err_t result = RT_EOK;
|
||||||
rt_hwtimer_t *timer;
|
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);
|
result = timer->ops->control(timer, cmd, args);
|
||||||
if (result == RT_EOK)
|
if (result == RT_EOK)
|
||||||
{
|
{
|
||||||
|
level = rt_hw_interrupt_disable();
|
||||||
timer->freq = *f;
|
timer->freq = *f;
|
||||||
|
rt_hw_interrupt_enable(level);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -284,8 +291,9 @@ static rt_err_t rt_hwtimer_control(struct rt_device *dev, int cmd, void *args)
|
||||||
result = -RT_ERROR;
|
result = -RT_ERROR;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
level = rt_hw_interrupt_disable();
|
||||||
timer->mode = *m;
|
timer->mode = *m;
|
||||||
|
rt_hw_interrupt_enable(level);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
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)
|
void rt_device_hwtimer_isr(rt_hwtimer_t *timer)
|
||||||
{
|
{
|
||||||
|
rt_base_t level;
|
||||||
|
|
||||||
RT_ASSERT(timer != RT_NULL);
|
RT_ASSERT(timer != RT_NULL);
|
||||||
|
|
||||||
|
level = rt_hw_interrupt_disable();
|
||||||
|
|
||||||
timer->overflow ++;
|
timer->overflow ++;
|
||||||
|
|
||||||
if (timer->cycles != 0)
|
if (timer->cycles != 0)
|
||||||
|
@ -313,6 +325,8 @@ void rt_device_hwtimer_isr(rt_hwtimer_t *timer)
|
||||||
{
|
{
|
||||||
timer->cycles = timer->reload;
|
timer->cycles = timer->reload;
|
||||||
|
|
||||||
|
rt_hw_interrupt_enable(level);
|
||||||
|
|
||||||
if (timer->mode == HWTIMER_MODE_ONESHOT)
|
if (timer->mode == HWTIMER_MODE_ONESHOT)
|
||||||
{
|
{
|
||||||
if (timer->ops->stop != RT_NULL)
|
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));
|
timer->parent.rx_indicate(&timer->parent, sizeof(struct rt_hwtimerval));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rt_hw_interrupt_enable(level);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef RT_USING_DEVICE_OPS
|
#ifdef RT_USING_DEVICE_OPS
|
||||||
|
|
Loading…
Reference in New Issue