Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions bsp/wch/risc-v/Libraries/ch32_drivers/drv_common.c
Original file line number Diff line number Diff line change
@@ -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 <rtthread.h>
#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);
}
25 changes: 25 additions & 0 deletions bsp/wch/risc-v/Libraries/ch32_drivers/drv_common.h
Original file line number Diff line number Diff line change
@@ -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