Skip to content

Commit bf45948

Browse files
向 wch-riscv-bsp 添加 drv_common.c/.h 文件 (#7671)
1 parent d256d74 commit bf45948

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (c) 2006-2023, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2023-06-14 muaxiaohei first version
9+
*/
10+
11+
#include <rtthread.h>
12+
#include "drv_common.h"
13+
14+
void rt_hw_us_delay(rt_uint32_t us)
15+
{
16+
uint64_t total_delay_ticks, us_ticks, start, now, delta, reload;
17+
18+
start = SysTick->CNT;
19+
reload = SysTick->CMP;
20+
us_ticks = SystemCoreClock / 8000000UL;
21+
total_delay_ticks = (uint32_t)us * us_ticks;
22+
RT_ASSERT(total_delay_ticks < reload);
23+
24+
do{
25+
now = SysTick->CNT;
26+
delta = start > now ? start - now : reload + start - now;
27+
}while(delta < total_delay_ticks);
28+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (c) 2006-2023, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2023-06-14 muaxiaohei first version
9+
*/
10+
11+
#ifndef __DRV_COMMON_H__
12+
#define __DRV_COMMON_H__
13+
14+
15+
#ifdef __cplusplus
16+
extern "C" {
17+
#endif
18+
19+
void rt_hw_us_delay(rt_uint32_t us);
20+
21+
#ifdef __cplusplus
22+
}
23+
#endif
24+
25+
#endif

0 commit comments

Comments
 (0)