Skip to content

Commit 1104b80

Browse files
[ch32][risc-v][bsp] update drv_common for wch risc-v bsp
1 parent 7d8f485 commit 1104b80

File tree

2 files changed

+60
-53
lines changed

2 files changed

+60
-53
lines changed
Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,35 @@
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-
}
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+
#define DBG_TAG "drv.common"
15+
#define DBG_LVL DBG_INFO
16+
#include <rtdbg.h>
17+
18+
void rt_hw_us_delay(rt_uint32_t us)
19+
{
20+
rt_uint64_t total_delay_ticks, us_ticks, start, now, delta, reload;
21+
22+
start = SysTick->CNT;
23+
reload = SysTick->CMP;
24+
us_ticks = SystemCoreClock / 8000000UL;
25+
total_delay_ticks = us * us_ticks;
26+
if (total_delay_ticks >= reload)
27+
{
28+
LOW_E("rt_hw_us_delay: the us parameter exceeds the maximum limit!");
29+
}
30+
31+
do {
32+
now = SysTick->CNT;
33+
delta = start > now ? start - now : reload + start - now;
34+
} while(delta < total_delay_ticks);
35+
}
Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +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
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)