From bf4594870e9f8a533450d34a1ea2b4f035e89c96 Mon Sep 17 00:00:00 2001 From: self-confident neko <45762837+muaxiaohei@users.noreply.github.com> Date: Wed, 14 Jun 2023 19:34:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=91=20wch-riscv-bsp=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=20drv=5Fcommon.c/.h=20=E6=96=87=E4=BB=B6=20(#7671)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Libraries/ch32_drivers/drv_common.c | 28 +++++++++++++++++++ .../Libraries/ch32_drivers/drv_common.h | 25 +++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 bsp/wch/risc-v/Libraries/ch32_drivers/drv_common.c create mode 100644 bsp/wch/risc-v/Libraries/ch32_drivers/drv_common.h diff --git a/bsp/wch/risc-v/Libraries/ch32_drivers/drv_common.c b/bsp/wch/risc-v/Libraries/ch32_drivers/drv_common.c new file mode 100644 index 0000000000..79145ea939 --- /dev/null +++ b/bsp/wch/risc-v/Libraries/ch32_drivers/drv_common.c @@ -0,0 +1,28 @@ +/* + * 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); +} diff --git a/bsp/wch/risc-v/Libraries/ch32_drivers/drv_common.h b/bsp/wch/risc-v/Libraries/ch32_drivers/drv_common.h new file mode 100644 index 0000000000..df9bed2794 --- /dev/null +++ b/bsp/wch/risc-v/Libraries/ch32_drivers/drv_common.h @@ -0,0 +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