diff options
| author | 杨连钊 <[email protected]> | 2019-03-25 10:35:32 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2019-03-25 10:35:32 +0800 |
| commit | b3cea3f5a8b7e9de50c5a6f79933077b11448f33 (patch) | |
| tree | 9bb7db6ba705a26d819538438d19cb22ee12bac5 /bsp/stm32/libraries | |
| parent | 1b0f7db7c36c142dddb417c1cf1deaa5baf9add5 (diff) | |
Update drv_common.c
Diffstat (limited to 'bsp/stm32/libraries')
| -rw-r--r-- | bsp/stm32/libraries/HAL_Drivers/drv_common.c | 34 |
1 files changed, 8 insertions, 26 deletions
diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_common.c b/bsp/stm32/libraries/HAL_Drivers/drv_common.c index 350c3fab40..9bffc026e4 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_common.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_common.c @@ -93,32 +93,14 @@ void _Error_Handler(char *s, int num) */ void rt_hw_us_delay(rt_uint32_t us) { - rt_uint32_t ticks; - rt_uint32_t told, tnow, tcnt = 0; - rt_uint32_t reload = SysTick->LOAD; - - ticks = us * reload / (1000000 / RT_TICK_PER_SECOND); - told = SysTick->VAL; - while (1) - { - tnow = SysTick->VAL; - if (tnow != told) - { - if (tnow < told) - { - tcnt += told - tnow; - } - else - { - tcnt += reload - tnow + told; - } - told = tnow; - if (tcnt >= ticks) - { - break; - } - } - } + rt_uint32_t start, now, delta, reload, us_tick; + start = SysTick->VAL; + reload = SysTick->LOAD; + us_tick = SystemCoreClock / 1000000UL; + do { + now = SysTick->VAL; + delta = start > now ? start - now : reload + start - now; + } while(delta < us_tick * us); } /** |
