2023-06-18 06:27:57 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2006-2023, RT-Thread Development Team
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2023-06-14 muaxiaohei first version
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <rtthread.h>
|
|
|
|
#include "drv_common.h"
|
2023-06-27 08:22:16 +08:00
|
|
|
#include <board.h> /* for rt_hw_us_delay */
|
2023-06-18 06:27:57 +08:00
|
|
|
|
|
|
|
#define DBG_TAG "drv.common"
|
|
|
|
#define DBG_LVL DBG_INFO
|
|
|
|
#include <rtdbg.h>
|
|
|
|
|
|
|
|
void rt_hw_us_delay(rt_uint32_t us)
|
|
|
|
{
|
|
|
|
rt_uint64_t total_delay_ticks, us_ticks, start, now, delta, reload;
|
|
|
|
|
|
|
|
start = SysTick->CNT;
|
|
|
|
reload = SysTick->CMP;
|
|
|
|
us_ticks = SystemCoreClock / 8000000UL;
|
|
|
|
total_delay_ticks = us * us_ticks;
|
|
|
|
if (total_delay_ticks >= reload)
|
|
|
|
{
|
2023-06-18 06:33:50 +08:00
|
|
|
LOG_E("rt_hw_us_delay: the us parameter exceeds the maximum limit!");
|
2023-06-18 06:27:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
now = SysTick->CNT;
|
|
|
|
delta = start > now ? start - now : reload + start - now;
|
|
|
|
} while(delta < total_delay_ticks);
|
|
|
|
}
|