Update drv_common.c

This commit is contained in:
杨连钊 2019-03-25 10:35:32 +08:00 committed by GitHub
parent 1b0f7db7c3
commit b3cea3f5a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 26 deletions

View File

@ -93,32 +93,14 @@ 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 ticks; rt_uint32_t start, now, delta, reload, us_tick;
rt_uint32_t told, tnow, tcnt = 0; start = SysTick->VAL;
rt_uint32_t reload = SysTick->LOAD; reload = SysTick->LOAD;
us_tick = SystemCoreClock / 1000000UL;
ticks = us * reload / (1000000 / RT_TICK_PER_SECOND); do {
told = SysTick->VAL; now = SysTick->VAL;
while (1) delta = start > now ? start - now : reload + start - now;
{ } while(delta < us_tick * us);
tnow = SysTick->VAL;
if (tnow != told)
{
if (tnow < told)
{
tcnt += told - tnow;
}
else
{
tcnt += reload - tnow + told;
}
told = tnow;
if (tcnt >= ticks)
{
break;
}
}
}
} }
/** /**