Merge pull request #2480 from HubertXie/master

【修复】修复ms转tick时计算溢出问题
This commit is contained in:
Bernard Xiong 2019-03-23 06:25:27 +08:00 committed by GitHub
commit efd8b404a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 5 deletions

View File

@ -75,7 +75,7 @@ void rt_system_tick_init(void);
rt_tick_t rt_tick_get(void);
void rt_tick_set(rt_tick_t tick);
void rt_tick_increase(void);
int rt_tick_from_millisecond(rt_int32_t ms);
rt_tick_t rt_tick_from_millisecond(rt_int32_t ms);
void rt_system_timer_init(void);
void rt_system_timer_thread_init(void);

View File

@ -107,15 +107,20 @@ void rt_tick_increase(void)
*
* @return the calculated tick
*/
int rt_tick_from_millisecond(rt_int32_t ms)
rt_tick_t rt_tick_from_millisecond(rt_int32_t ms)
{
int tick;
rt_tick_t tick;
if (ms < 0)
{
tick = RT_WAITING_FOREVER;
}
else
tick = (RT_TICK_PER_SECOND * ms + 999) / 1000;
{
tick = RT_TICK_PER_SECOND * (ms / 1000);
tick += (RT_TICK_PER_SECOND * (ms%1000) + 999) / 1000;
}
/* return the calculated tick */
return tick;
}