Skip to content

Commit 1e72902

Browse files
committed
[bsp][bluetrum] Optimizing the uart driver
1 parent 1c61d6e commit 1e72902

File tree

9 files changed

+251
-87
lines changed

9 files changed

+251
-87
lines changed

bsp/bluetrum/ab32vg1-ab-prougen/board/Kconfig

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,34 @@ menu "On-chip Peripheral Drivers"
3535
bool "Enable UART0"
3636
select RT_USING_SERIAL
3737
default y
38+
if BSP_USING_UART0
39+
config BSP_UART0_FIFO_SIZE
40+
int "BSP_UART0_FIFO_SIZE"
41+
range 5 255
42+
default 10
43+
endif
44+
3845
config BSP_USING_UART1
3946
bool "Enable UART1"
4047
select RT_USING_SERIAL
4148
default n
49+
if BSP_USING_UART1
50+
config BSP_UART1_FIFO_SIZE
51+
int "BSP_UART1_FIFO_SIZE"
52+
range 5 255
53+
default 10
54+
endif
55+
4256
config BSP_USING_UART2
4357
bool "Enable UART2"
4458
select RT_USING_SERIAL
4559
default n
60+
if BSP_USING_UART2
61+
config BSP_UART2_FIFO_SIZE
62+
int "BSP_UART2_FIFO_SIZE"
63+
range 5 255
64+
default 10
65+
endif
4666
endif
4767

4868
config BSP_USING_SDIO
@@ -174,12 +194,12 @@ menu "On-chip Peripheral Drivers"
174194
default n
175195
if BSP_USING_ONCHIP_RTC
176196
config RTC_USING_INTERNAL_CLK
177-
bool "Using internal clock RTC"
178-
default y
197+
bool "Using internal clock RTC"
198+
default y
179199
config RTC_USING_1S_INT
180-
bool "Using 1 second interrupt"
181-
depends on RT_USING_ALARM
182-
default n
200+
bool "Using 1 second interrupt"
201+
depends on RT_USING_ALARM
202+
default n
183203
endif
184204

185205
menuconfig BSP_USING_ADC

bsp/bluetrum/ab32vg1-ab-prougen/board/board.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ void set_cpu_irq_comm(void (*irq_hook)(void));
2121
void load_cache();
2222
void os_cache_init(void);
2323
void sys_error_hook(uint8_t err_no);
24+
void huart_timer_isr(void);
2425

2526
typedef void (*spiflash_init_func)(uint8_t sf_read, uint8_t dummy);
2627

@@ -71,6 +72,9 @@ void timer0_isr(int vector, void *param)
7172
rt_interrupt_enter();
7273
TMR0CPND = BIT(9);
7374
rt_tick_increase();
75+
#ifdef RT_USING_SERIAL
76+
huart_timer_isr();
77+
#endif
7478
rt_interrupt_leave();
7579
}
7680

bsp/bluetrum/libraries/hal_drivers/SConscript

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ from building import *
44

55
cwd = GetCurrentDir()
66
src = []
7+
src += ['drv_common.c']
78
path = [cwd]
89
path += [cwd + '/config']
910

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#include "drv_common.h"
2+
3+
#define DRV_THREAD_PRIORITY 18
4+
#define DRV_THREAD_STACK_SIZE 512
5+
#define DRV_THREAD_TIMESLICE 5
6+
7+
enum {
8+
MSG_UART0_IRQ,
9+
MSG_UART1_IRQ,
10+
MSG_UART2_IRQ,
11+
};
12+
13+
static rt_thread_t drv_tid = RT_NULL;
14+
static rt_mq_t drv_mq = RT_NULL;
15+
16+
void uart0_irq_process(void);
17+
void uart1_irq_process(void);
18+
19+
RT_SECTION(".irq.uart")
20+
void uart0_irq_post(void)
21+
{
22+
uint8_t mq_msg = MSG_UART0_IRQ;
23+
rt_mq_send(drv_mq, &mq_msg, 1);
24+
}
25+
26+
RT_SECTION(".irq.uart")
27+
void uart1_irq_post(void)
28+
{
29+
uint8_t mq_msg = MSG_UART1_IRQ;
30+
rt_mq_send(drv_mq, &mq_msg, 1);
31+
}
32+
33+
RT_SECTION(".irq.uart")
34+
void uart2_irq_post(void)
35+
{
36+
uint8_t mq_msg = MSG_UART2_IRQ;
37+
rt_mq_send(drv_mq, &mq_msg, 1);
38+
}
39+
40+
static void drv_thread_entry(void *parameter)
41+
{
42+
uint8_t mq_msg = 0;
43+
while (1) {
44+
rt_mq_recv(drv_mq, &mq_msg, 1, RT_WAITING_FOREVER);
45+
switch (mq_msg) {
46+
#ifdef BSP_USING_UART0
47+
case MSG_UART0_IRQ:
48+
uart0_irq_process();
49+
break;
50+
#endif
51+
#ifdef BSP_USING_UART1
52+
case MSG_UART1_IRQ:
53+
uart1_irq_process();
54+
break;
55+
#endif
56+
#ifdef BSP_USING_UART2
57+
case MSG_UART2_IRQ:
58+
uart2_irq_process();
59+
break;
60+
#endif
61+
default:
62+
break;
63+
}
64+
}
65+
}
66+
67+
static int drv_thread_init(void)
68+
{
69+
drv_mq = rt_mq_create("drv", 1, 128, RT_IPC_FLAG_FIFO);
70+
drv_tid = rt_thread_create("drv",
71+
drv_thread_entry,
72+
RT_NULL,
73+
DRV_THREAD_STACK_SIZE,
74+
DRV_THREAD_PRIORITY,
75+
DRV_THREAD_TIMESLICE);
76+
77+
if (drv_tid != RT_NULL)
78+
rt_thread_startup(drv_tid);
79+
}
80+
INIT_PREV_EXPORT(drv_thread_init);

bsp/bluetrum/libraries/hal_drivers/drv_common.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,8 @@
1717

1818
#define GET_PIN(PORTx,PIN) (uint8_t)__AB32_GET_PIN_##PORTx(PIN)
1919

20+
void uart0_irq_post(void);
21+
void uart1_irq_post(void);
22+
void uart2_irq_post(void);
23+
2024
#endif // DRV_COMMON_H__

0 commit comments

Comments
 (0)