summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author杨连钊 <[email protected]>2019-01-16 16:38:16 +0800
committerGitHub <[email protected]>2019-01-16 16:38:16 +0800
commita5a4c6a5035bfd359c12b4d673e1fedffba40d8d (patch)
tree1567e6c459eeb3bb374ae49a9db0699b820ba50d
parent4006129dcecea9d987d7efa3804808219ffa8803 (diff)
Update board.c
优化void rt_hw_us_delay(rt_uint32_t us)
-rw-r--r--bsp/stm32f10x-HAL/drivers/board.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/bsp/stm32f10x-HAL/drivers/board.c b/bsp/stm32f10x-HAL/drivers/board.c
index 5c7e44c4f8..6df16a2127 100644
--- a/bsp/stm32f10x-HAL/drivers/board.c
+++ b/bsp/stm32f10x-HAL/drivers/board.c
@@ -186,15 +186,12 @@ void rt_hw_board_init(void)
*/
void rt_hw_us_delay(rt_uint32_t us)
{
- rt_uint32_t delta;
- us = us * (SysTick->LOAD / (1000000 / RT_TICK_PER_SECOND));
- delta = SysTick->VAL;
- if (delta < us)
- {
- /* wait current OSTick left time gone */
- while (SysTick->VAL < us);
- us -= delta;
- delta = SysTick->LOAD;
- }
- while (delta - SysTick->VAL < us);
+ unsigned int 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);
}