Merge pull request #4329 from liruncong/delay_until_3

修正rt_thread_delay_until时间不准问题
This commit is contained in:
Bernard Xiong 2021-03-11 15:26:06 +08:00 committed by GitHub
commit ca8056072d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 6 deletions

View File

@ -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;
struct rt_thread *thread;
rt_tick_t cur_tick;
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 */
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 */
rt_thread_suspend(thread);
/* 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));
/* enable interrupt */
@ -608,12 +613,10 @@ rt_err_t rt_thread_delay_until(rt_tick_t *tick, rt_tick_t inc_tick)
}
else
{
*tick = cur_tick;
rt_hw_interrupt_enable(level);
}
/* get the wakeup tick */
*tick = rt_tick_get();
return RT_EOK;
}
RTM_EXPORT(rt_thread_delay_until);