提交 796c8aff 编写于 作者: chenyizhong10's avatar chenyizhong10

rt_hw_us_delay的实现有问题,针对这一问题进行了修改

上级 2961b371
...@@ -113,16 +113,32 @@ void _Error_Handler(char *s, int num) ...@@ -113,16 +113,32 @@ void _Error_Handler(char *s, int num)
*/ */
void rt_hw_us_delay(rt_uint32_t us) void rt_hw_us_delay(rt_uint32_t us)
{ {
rt_uint32_t start, now, delta, reload, us_tick; rt_uint32_t ticks;
start = SysTick->VAL; rt_uint32_t told, tnow, tcnt = 0;
reload = SysTick->LOAD; rt_uint32_t reload = SysTick->LOAD;
us_tick = SystemCoreClock / 1000000UL;
do ticks = us * reload / (1000000 / RT_TICK_PER_SECOND);
told = SysTick->VAL;
while (1)
{
tnow = SysTick->VAL;
if (tnow != told)
{ {
now = SysTick->VAL; if (tnow < told)
delta = start >= now ? start - now : reload + start - now; {
tcnt += told - tnow;
}
else
{
tcnt += reload - tnow + told;
}
told = tnow;
if (tcnt >= ticks)
{
break;
}
}
} }
while (delta < us_tick * us);
} }
/** /**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册