From 1104b80a4db4f308a21f80a9c6c0f7a692de1785 Mon Sep 17 00:00:00 2001 From: self-confident neko <45762837+muaxiaohei@users.noreply.github.com> Date: Sun, 18 Jun 2023 06:27:57 +0800 Subject: [ch32][risc-v][bsp] update drv_common for wch risc-v bsp --- bsp/wch/risc-v/Libraries/ch32_drivers/drv_common.c | 63 ++++++++++++---------- bsp/wch/risc-v/Libraries/ch32_drivers/drv_common.h | 50 ++++++++--------- 2 files changed, 60 insertions(+), 53 deletions(-) (limited to 'bsp') diff --git a/bsp/wch/risc-v/Libraries/ch32_drivers/drv_common.c b/bsp/wch/risc-v/Libraries/ch32_drivers/drv_common.c index 79145ea939..8b98915ff0 100644 --- a/bsp/wch/risc-v/Libraries/ch32_drivers/drv_common.c +++ b/bsp/wch/risc-v/Libraries/ch32_drivers/drv_common.c @@ -1,28 +1,35 @@ -/* - * 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 -#include "drv_common.h" - -void rt_hw_us_delay(rt_uint32_t us) -{ - uint64_t total_delay_ticks, us_ticks, start, now, delta, reload; - - start = SysTick->CNT; - reload = SysTick->CMP; - us_ticks = SystemCoreClock / 8000000UL; - total_delay_ticks = (uint32_t)us * us_ticks; - RT_ASSERT(total_delay_ticks < reload); - - do{ - now = SysTick->CNT; - delta = start > now ? start - now : reload + start - now; - }while(delta < total_delay_ticks); -} +/* + * 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 +#include "drv_common.h" + +#define DBG_TAG "drv.common" +#define DBG_LVL DBG_INFO +#include + +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) + { + LOW_E("rt_hw_us_delay: the us parameter exceeds the maximum limit!"); + } + + do { + now = SysTick->CNT; + delta = start > now ? start - now : reload + start - now; + } while(delta < total_delay_ticks); +} diff --git a/bsp/wch/risc-v/Libraries/ch32_drivers/drv_common.h b/bsp/wch/risc-v/Libraries/ch32_drivers/drv_common.h index df9bed2794..1df9af8783 100644 --- a/bsp/wch/risc-v/Libraries/ch32_drivers/drv_common.h +++ b/bsp/wch/risc-v/Libraries/ch32_drivers/drv_common.h @@ -1,25 +1,25 @@ -/* - * 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 - */ - -#ifndef __DRV_COMMON_H__ -#define __DRV_COMMON_H__ - - -#ifdef __cplusplus -extern "C" { -#endif - -void rt_hw_us_delay(rt_uint32_t us); - -#ifdef __cplusplus -} -#endif - -#endif +/* + * 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 + */ + +#ifndef __DRV_COMMON_H__ +#define __DRV_COMMON_H__ + + +#ifdef __cplusplus +extern "C" { +#endif + +void rt_hw_us_delay(rt_uint32_t us); + +#ifdef __cplusplus +} +#endif + +#endif -- cgit v1.3.1