Merge pull request #4329 from liruncong/delay_until_3
修正rt_thread_delay_until时间不准问题
This commit is contained in:
commit
ca8056072d
15
src/thread.c
15
src/thread.c
@ -573,6 +573,7 @@ rt_err_t rt_thread_delay_until(rt_tick_t *tick, rt_tick_t inc_tick)
|
|||||||
{
|
{
|
||||||
register rt_base_t level;
|
register rt_base_t level;
|
||||||
struct rt_thread *thread;
|
struct rt_thread *thread;
|
||||||
|
rt_tick_t cur_tick;
|
||||||
|
|
||||||
RT_ASSERT(tick != RT_NULL);
|
RT_ASSERT(tick != RT_NULL);
|
||||||
|
|
||||||
@ -584,15 +585,19 @@ rt_err_t rt_thread_delay_until(rt_tick_t *tick, rt_tick_t inc_tick)
|
|||||||
/* disable interrupt */
|
/* disable interrupt */
|
||||||
level = rt_hw_interrupt_disable();
|
level = rt_hw_interrupt_disable();
|
||||||
|
|
||||||
if (rt_tick_get() - *tick < inc_tick)
|
cur_tick = rt_tick_get();
|
||||||
|
if (cur_tick - *tick < inc_tick)
|
||||||
{
|
{
|
||||||
*tick = *tick + inc_tick - rt_tick_get();
|
rt_tick_t left_tick;
|
||||||
|
|
||||||
|
*tick += inc_tick;
|
||||||
|
left_tick = *tick - cur_tick;
|
||||||
|
|
||||||
/* suspend thread */
|
/* suspend thread */
|
||||||
rt_thread_suspend(thread);
|
rt_thread_suspend(thread);
|
||||||
|
|
||||||
/* reset the timeout of thread timer and start it */
|
/* reset the timeout of thread timer and start it */
|
||||||
rt_timer_control(&(thread->thread_timer), RT_TIMER_CTRL_SET_TIME, tick);
|
rt_timer_control(&(thread->thread_timer), RT_TIMER_CTRL_SET_TIME, &left_tick);
|
||||||
rt_timer_start(&(thread->thread_timer));
|
rt_timer_start(&(thread->thread_timer));
|
||||||
|
|
||||||
/* enable interrupt */
|
/* enable interrupt */
|
||||||
@ -608,12 +613,10 @@ rt_err_t rt_thread_delay_until(rt_tick_t *tick, rt_tick_t inc_tick)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
*tick = cur_tick;
|
||||||
rt_hw_interrupt_enable(level);
|
rt_hw_interrupt_enable(level);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get the wakeup tick */
|
|
||||||
*tick = rt_tick_get();
|
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
RTM_EXPORT(rt_thread_delay_until);
|
RTM_EXPORT(rt_thread_delay_until);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user