123456789101112131415161718192021222324252627282930313233343536373839404142 |
- /*
- * Copyright (c) 2006-2023, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2022-09-13 xjy198903 first implementation
- */
- #include <rtthread.h>
- #include "clock_config.h"
- 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;
- }
- }
- }
- }
|