mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-11-09 20:45:41 +08:00
[bsp][bluetrum] Optimizing the uart driver
This commit is contained in:
1 parent
1c61d6e56c
commit
1e7290231e
9 files changed
+252
-88
No files matched your search
@@ -35,14 +35,34 @@ menu "On-chip Peripheral Drivers"
|
||||
bool "Enable UART0"
|
||||
select RT_USING_SERIAL
|
||||
default y
|
||||
if BSP_USING_UART0
|
||||
config BSP_UART0_FIFO_SIZE
|
||||
int "BSP_UART0_FIFO_SIZE"
|
||||
range 5 255
|
||||
default 10
|
||||
endif
|
||||
|
||||
config BSP_USING_UART1
|
||||
bool "Enable UART1"
|
||||
select RT_USING_SERIAL
|
||||
default n
|
||||
if BSP_USING_UART1
|
||||
config BSP_UART1_FIFO_SIZE
|
||||
int "BSP_UART1_FIFO_SIZE"
|
||||
range 5 255
|
||||
default 10
|
||||
endif
|
||||
|
||||
config BSP_USING_UART2
|
||||
bool "Enable UART2"
|
||||
select RT_USING_SERIAL
|
||||
default n
|
||||
if BSP_USING_UART2
|
||||
config BSP_UART2_FIFO_SIZE
|
||||
int "BSP_UART2_FIFO_SIZE"
|
||||
range 5 255
|
||||
default 10
|
||||
endif
|
||||
endif
|
||||
|
||||
config BSP_USING_SDIO
|
||||
@@ -174,12 +194,12 @@ menu "On-chip Peripheral Drivers"
|
||||
default n
|
||||
if BSP_USING_ONCHIP_RTC
|
||||
config RTC_USING_INTERNAL_CLK
|
||||
bool "Using internal clock RTC"
|
||||
default y
|
||||
bool "Using internal clock RTC"
|
||||
default y
|
||||
config RTC_USING_1S_INT
|
||||
bool "Using 1 second interrupt"
|
||||
depends on RT_USING_ALARM
|
||||
default n
|
||||
bool "Using 1 second interrupt"
|
||||
depends on RT_USING_ALARM
|
||||
default n
|
||||
endif
|
||||
|
||||
menuconfig BSP_USING_ADC
|
||||
|
||||
@@ -21,6 +21,7 @@ void set_cpu_irq_comm(void (*irq_hook)(void));
|
||||
void load_cache();
|
||||
void os_cache_init(void);
|
||||
void sys_error_hook(uint8_t err_no);
|
||||
void huart_timer_isr(void);
|
||||
|
||||
typedef void (*spiflash_init_func)(uint8_t sf_read, uint8_t dummy);
|
||||
|
||||
@@ -71,6 +72,9 @@ void timer0_isr(int vector, void *param)
|
||||
rt_interrupt_enter();
|
||||
TMR0CPND = BIT(9);
|
||||
rt_tick_increase();
|
||||
#ifdef RT_USING_SERIAL
|
||||
huart_timer_isr();
|
||||
#endif
|
||||
rt_interrupt_leave();
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ from building import *
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
src = []
|
||||
src += ['drv_common.c']
|
||||
path = [cwd]
|
||||
path += [cwd + '/config']
|
||||
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
#include "drv_common.h"
|
||||
|
||||
#define DRV_THREAD_PRIORITY 18
|
||||
#define DRV_THREAD_STACK_SIZE 512
|
||||
#define DRV_THREAD_TIMESLICE 5
|
||||
|
||||
enum {
|
||||
MSG_UART0_IRQ,
|
||||
MSG_UART1_IRQ,
|
||||
MSG_UART2_IRQ,
|
||||
};
|
||||
|
||||
static rt_thread_t drv_tid = RT_NULL;
|
||||
static rt_mq_t drv_mq = RT_NULL;
|
||||
|
||||
void uart0_irq_process(void);
|
||||
void uart1_irq_process(void);
|
||||
|
||||
RT_SECTION(".irq.uart")
|
||||
void uart0_irq_post(void)
|
||||
{
|
||||
uint8_t mq_msg = MSG_UART0_IRQ;
|
||||
rt_mq_send(drv_mq, &mq_msg, 1);
|
||||
}
|
||||
|
||||
RT_SECTION(".irq.uart")
|
||||
void uart1_irq_post(void)
|
||||
{
|
||||
uint8_t mq_msg = MSG_UART1_IRQ;
|
||||
rt_mq_send(drv_mq, &mq_msg, 1);
|
||||
}
|
||||
|
||||
RT_SECTION(".irq.uart")
|
||||
void uart2_irq_post(void)
|
||||
{
|
||||
uint8_t mq_msg = MSG_UART2_IRQ;
|
||||
rt_mq_send(drv_mq, &mq_msg, 1);
|
||||
}
|
||||
|
||||
static void drv_thread_entry(void *parameter)
|
||||
{
|
||||
uint8_t mq_msg = 0;
|
||||
while (1) {
|
||||
rt_mq_recv(drv_mq, &mq_msg, 1, RT_WAITING_FOREVER);
|
||||
switch (mq_msg) {
|
||||
#ifdef BSP_USING_UART0
|
||||
case MSG_UART0_IRQ:
|
||||
uart0_irq_process();
|
||||
break;
|
||||
#endif
|
||||
#ifdef BSP_USING_UART1
|
||||
case MSG_UART1_IRQ:
|
||||
uart1_irq_process();
|
||||
break;
|
||||
#endif
|
||||
#ifdef BSP_USING_UART2
|
||||
case MSG_UART2_IRQ:
|
||||
uart2_irq_process();
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int drv_thread_init(void)
|
||||
{
|
||||
drv_mq = rt_mq_create("drv", 1, 128, RT_IPC_FLAG_FIFO);
|
||||
drv_tid = rt_thread_create("drv",
|
||||
drv_thread_entry,
|
||||
RT_NULL,
|
||||
DRV_THREAD_STACK_SIZE,
|
||||
DRV_THREAD_PRIORITY,
|
||||
DRV_THREAD_TIMESLICE);
|
||||
|
||||
if (drv_tid != RT_NULL)
|
||||
rt_thread_startup(drv_tid);
|
||||
}
|
||||
INIT_PREV_EXPORT(drv_thread_init);
|
||||
@@ -17,4 +17,8 @@
|
||||
|
||||
#define GET_PIN(PORTx,PIN) (uint8_t)__AB32_GET_PIN_##PORTx(PIN)
|
||||
|
||||
void uart0_irq_post(void);
|
||||
void uart1_irq_post(void);
|
||||
void uart2_irq_post(void);
|
||||
|
||||
#endif // DRV_COMMON_H__
|
||||
File diff suppressed because it is too large.
Load diff
@@ -19,9 +19,10 @@
|
||||
struct ab32_uart_config
|
||||
{
|
||||
const char *name;
|
||||
hal_sfr_t instance;
|
||||
uint8_t mode;
|
||||
uint8_t reserve[3];
|
||||
hal_sfr_t instance;
|
||||
uint8_t mode;
|
||||
uint16_t fifo_size;
|
||||
uint8_t reserve[1];
|
||||
// struct dma_config *dma_rx;
|
||||
// struct dma_config *dma_tx;
|
||||
};
|
||||
@@ -45,6 +46,9 @@ struct ab32_uart
|
||||
#endif
|
||||
rt_uint16_t uart_dma_flag;
|
||||
struct rt_serial_device serial;
|
||||
rt_uint8_t *rx_buf;
|
||||
rt_uint8_t rx_idx;
|
||||
rt_uint8_t rx_idx_prev;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef API_HUART_H__
|
||||
#define API_HUART_H__
|
||||
|
||||
enum {
|
||||
HUART_TR_PA7 = 0,
|
||||
HUART_TR_PB2,
|
||||
HUART_TR_PB3,
|
||||
HUART_TR_PE7,
|
||||
HUART_TR_PA1,
|
||||
HUART_TR_PA6,
|
||||
HUART_TR_PB1,
|
||||
HUART_TR_PB4,
|
||||
HUART_TR_PE6,
|
||||
HUART_TR_PA0,
|
||||
};
|
||||
|
||||
void huart_init_do(uint8_t tx_port, uint8_t rx_port, uint32_t baud_rate, uint8_t *buf, uint16_t buf_size);
|
||||
void huart_setbaudrate(unsigned int baudrate);
|
||||
void huart_putchar(const char ch);
|
||||
void huart_tx(const void *buf, unsigned int len);
|
||||
unsigned int huart_get_rxcnt(void);
|
||||
void huart_rxfifo_clear(void);
|
||||
char huart_getchar(void);
|
||||
void huart_exit(void);
|
||||
|
||||
void huart_if_rx_ovflow(void);
|
||||
|
||||
#endif
|
||||
Binary file not shown.
Reference in new issue
Block a user