mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-10-07 00:59:00 +08:00
Merge pull request #4929 from greedyhao/ab32
[bsp][bluetrum] 优化串口驱动和对接新的RTC框架
This commit is contained in:
@@ -29,6 +29,7 @@ CONFIG_RT_TIMER_THREAD_STACK_SIZE=256
|
||||
#
|
||||
# CONFIG_RT_KSERVICE_USING_STDLIB is not set
|
||||
# CONFIG_RT_KSERVICE_USING_TINY_SIZE is not set
|
||||
# CONFIG_RT_USING_ASM_MEMCPY is not set
|
||||
CONFIG_RT_DEBUG=y
|
||||
# CONFIG_RT_DEBUG_COLOR is not set
|
||||
# CONFIG_RT_DEBUG_INIT_CONFIG is not set
|
||||
@@ -74,6 +75,7 @@ CONFIG_RT_USING_DEVICE_OPS=y
|
||||
CONFIG_RT_USING_CONSOLE=y
|
||||
CONFIG_RT_CONSOLEBUF_SIZE=128
|
||||
CONFIG_RT_CONSOLE_DEVICE_NAME="uart0"
|
||||
# CONFIG_RT_PRINTF_LONGLONG is not set
|
||||
CONFIG_RT_VER_NUM=0x40004
|
||||
# CONFIG_RT_USING_CPU_FFS is not set
|
||||
# CONFIG_ARCH_CPU_STACK_GROWS_UPWARD is not set
|
||||
@@ -162,7 +164,7 @@ CONFIG_RT_USING_PIN=y
|
||||
CONFIG_RT_USING_LIBC=y
|
||||
# CONFIG_RT_USING_PTHREADS is not set
|
||||
# CONFIG_RT_USING_MODULE is not set
|
||||
CONFIG_RT_LIBC_FIXED_TIMEZONE=8
|
||||
CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8
|
||||
|
||||
#
|
||||
# Network
|
||||
@@ -568,6 +570,7 @@ CONFIG_RT_LIBC_FIXED_TIMEZONE=8
|
||||
#
|
||||
CONFIG_BSP_USING_UART=y
|
||||
CONFIG_BSP_USING_UART0=y
|
||||
CONFIG_BSP_UART0_FIFO_SIZE=10
|
||||
# CONFIG_BSP_USING_UART1 is not set
|
||||
# CONFIG_BSP_USING_UART2 is not set
|
||||
# CONFIG_BSP_USING_SDIO is not set
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
menu "Hardware Drivers Config"
|
||||
|
||||
config SOC_AB32VG1
|
||||
bool
|
||||
select PKG_USING_BLUETRUM_SDK
|
||||
default y
|
||||
|
||||
menu "Onboard Peripheral Drivers"
|
||||
|
||||
menuconfig BSP_USING_AUDIO
|
||||
@@ -29,20 +34,40 @@ endmenu
|
||||
|
||||
menu "On-chip Peripheral Drivers"
|
||||
menuconfig BSP_USING_UART
|
||||
bool "Enable UART"
|
||||
bool "Enable UART"
|
||||
if BSP_USING_UART
|
||||
config BSP_USING_UART0
|
||||
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 +199,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);
|
||||
|
||||
@@ -29,6 +30,7 @@ static struct rt_mutex mutex_cache = {0};
|
||||
extern volatile rt_uint8_t rt_interrupt_nest;
|
||||
extern uint32_t __heap_start, __heap_end;
|
||||
|
||||
#ifdef RT_USING_CONSOLE
|
||||
void hal_printf(const char *fmt, ...)
|
||||
{
|
||||
rt_device_t console = rt_console_get_device();
|
||||
@@ -64,6 +66,7 @@ void hal_printf(const char *fmt, ...)
|
||||
#endif
|
||||
va_end(args);
|
||||
}
|
||||
#endif
|
||||
|
||||
RT_SECTION(".irq.timer")
|
||||
void timer0_isr(int vector, void *param)
|
||||
@@ -71,6 +74,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();
|
||||
}
|
||||
|
||||
@@ -206,8 +212,10 @@ void exception_isr(void)
|
||||
extern long list_thread(void);
|
||||
sys_error_hook(1);
|
||||
|
||||
#ifdef RT_USING_CONSOLE
|
||||
rt_console_set_device(RT_NULL);
|
||||
rt_kprintf(stack_info, rt_thread_self()->sp, rt_thread_self()->name);
|
||||
#endif
|
||||
|
||||
while(1);
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@
|
||||
/* POSIX layer and C standard library */
|
||||
|
||||
#define RT_USING_LIBC
|
||||
#define RT_LIBC_FIXED_TIMEZONE 8
|
||||
#define RT_LIBC_DEFAULT_TIMEZONE 8
|
||||
|
||||
/* Network */
|
||||
|
||||
@@ -176,6 +176,7 @@
|
||||
|
||||
#define BSP_USING_UART
|
||||
#define BSP_USING_UART0
|
||||
#define BSP_UART0_FIFO_SIZE 10
|
||||
|
||||
/* Board extended module Drivers */
|
||||
|
||||
|
||||
@@ -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__
|
||||
|
||||
@@ -144,151 +144,68 @@ void hal_rtc_init(void)
|
||||
}
|
||||
/************** HAL End *******************/
|
||||
|
||||
static time_t get_rtc_time_stamp(void)
|
||||
static rt_err_t ab32_rtc_get_secs(void *args)
|
||||
{
|
||||
time_t sec = 0;
|
||||
|
||||
sec = irtc_time_read(RTCCNT_CMD);
|
||||
LOG_D("get rtc time.");
|
||||
|
||||
return sec;
|
||||
}
|
||||
|
||||
static rt_err_t set_rtc_time_stamp(time_t time_stamp)
|
||||
{
|
||||
irtc_time_write(RTCCNT_CMD, time_stamp);
|
||||
*(rt_uint32_t *)args = irtc_time_read(RTCCNT_CMD);
|
||||
LOG_D("RTC: get rtc_time %x\n", *(rt_uint32_t *)args);
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static rt_err_t set_rtc_alarm_stamp(time_t alarm_stamp)
|
||||
static rt_err_t ab32_rtc_set_secs(void *args)
|
||||
{
|
||||
irtc_time_write(RTCALM_CMD, alarm_stamp);
|
||||
irtc_time_write(RTCCNT_CMD, *(rt_uint32_t *)args);
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static time_t get_rtc_alarm_stamp(void)
|
||||
static rt_err_t ab32_rtc_get_alarm(void *args)
|
||||
{
|
||||
time_t sec = 0;
|
||||
*(rt_uint32_t *)args = irtc_time_read(RTCALM_CMD);
|
||||
|
||||
sec = irtc_time_read(RTCALM_CMD);
|
||||
|
||||
return sec;
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static void rt_rtc_init(void)
|
||||
static rt_err_t ab32_rtc_set_alarm(void *args)
|
||||
{
|
||||
irtc_time_write(RTCALM_CMD, *(rt_uint32_t *)args);
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static rt_err_t ab32_rtc_init(void)
|
||||
{
|
||||
hal_rtc_init();
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static rt_err_t ab32_rtc_control(rt_device_t dev, int cmd, void *args)
|
||||
{
|
||||
rt_err_t result = RT_EOK;
|
||||
RT_ASSERT(dev != RT_NULL);
|
||||
switch (cmd)
|
||||
{
|
||||
case RT_DEVICE_CTRL_RTC_GET_TIME:
|
||||
*(time_t *)args = get_rtc_time_stamp();
|
||||
LOG_D("RTC: get rtc_time %x", *(time_t *)args);
|
||||
break;
|
||||
|
||||
case RT_DEVICE_CTRL_RTC_SET_TIME:
|
||||
if (set_rtc_time_stamp(*(time_t *)args))
|
||||
{
|
||||
result = -RT_ERROR;
|
||||
}
|
||||
LOG_D("RTC: set rtc_time %x", *(time_t *)args);
|
||||
break;
|
||||
case RT_DEVICE_CTRL_RTC_SET_ALARM:
|
||||
if (set_rtc_alarm_stamp(*(time_t *)args))
|
||||
{
|
||||
result = -RT_ERROR;
|
||||
}
|
||||
LOG_D("RTC: set alarm_stamp %x", *(time_t *)args);
|
||||
break;
|
||||
case RT_DEVICE_CTRL_RTC_GET_ALARM:
|
||||
*(time_t *)args = get_rtc_alarm_stamp();
|
||||
LOG_D("RTC: get alarm_stamp %x", *(time_t *)args);
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifdef RT_USING_DEVICE_OPS
|
||||
const static struct rt_device_ops rtc_ops =
|
||||
static const struct rt_rtc_ops ab32_rtc_ops =
|
||||
{
|
||||
ab32_rtc_init,
|
||||
ab32_rtc_get_secs,
|
||||
ab32_rtc_set_secs,
|
||||
ab32_rtc_get_alarm,
|
||||
ab32_rtc_set_alarm,
|
||||
RT_NULL,
|
||||
RT_NULL,
|
||||
RT_NULL,
|
||||
RT_NULL,
|
||||
RT_NULL,
|
||||
ab32_rtc_control
|
||||
};
|
||||
#endif
|
||||
|
||||
static rt_err_t rt_hw_rtc_register(rt_device_t device, const char *name, rt_uint32_t flag)
|
||||
{
|
||||
RT_ASSERT(device != RT_NULL);
|
||||
static rt_rtc_dev_t ab32_rtc_dev;
|
||||
|
||||
rt_rtc_init();
|
||||
#ifdef RT_USING_DEVICE_OPS
|
||||
device->ops = &rtc_ops;
|
||||
#else
|
||||
device->init = RT_NULL;
|
||||
device->open = RT_NULL;
|
||||
device->close = RT_NULL;
|
||||
device->read = RT_NULL;
|
||||
device->write = RT_NULL;
|
||||
device->control = ab32_rtc_control;
|
||||
#endif
|
||||
device->type = RT_Device_Class_RTC;
|
||||
device->rx_indicate = RT_NULL;
|
||||
device->tx_complete = RT_NULL;
|
||||
device->user_data = RT_NULL;
|
||||
|
||||
/* register a character device */
|
||||
return rt_device_register(device, name, flag);
|
||||
}
|
||||
|
||||
#ifdef RT_USING_ALARM
|
||||
RT_SECTION(".irq.rtc")
|
||||
static void rtc_isr(int vector, void *param)
|
||||
{
|
||||
rt_interrupt_enter();
|
||||
|
||||
if (RTCCON & RTC_CON_ALM_PEND)
|
||||
{
|
||||
RTCCPND |= RTC_CPND_ALM;
|
||||
}
|
||||
|
||||
#ifdef RTC_USING_1S_INT
|
||||
if (RTCCON & RTC_CON_1S_PEND)
|
||||
{
|
||||
RTCCPND |= RTC_CPND_1S;
|
||||
}
|
||||
#endif
|
||||
|
||||
rt_interrupt_leave();
|
||||
}
|
||||
#endif
|
||||
|
||||
int rt_hw_rtc_init(void)
|
||||
static int rt_hw_rtc_init(void)
|
||||
{
|
||||
rt_err_t result;
|
||||
|
||||
result = rt_hw_rtc_register(&rtc, "rtc", RT_DEVICE_FLAG_RDWR);
|
||||
ab32_rtc_dev.ops = &ab32_rtc_ops;
|
||||
result = rt_hw_rtc_register(&ab32_rtc_dev, "rtc", RT_DEVICE_FLAG_RDWR, RT_NULL);
|
||||
if (result != RT_EOK)
|
||||
{
|
||||
LOG_E("rtc register err code: %d", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifdef RT_USING_ALARM
|
||||
rt_hw_interrupt_install(IRQ_RTC_VECTOR, rtc_isr, RT_NULL, "rtc_isr");
|
||||
#endif
|
||||
LOG_D("rtc init success");
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
INIT_DEVICE_EXPORT(rt_hw_rtc_init);
|
||||
|
||||
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
|
||||
|
||||
@@ -48,8 +48,8 @@ ASFLAGS = ""
|
||||
CPPDEFINES = []
|
||||
LOCAL_CPPDEFINES = []
|
||||
|
||||
LIBS = ['hal']
|
||||
LIBPATH = [CWD]
|
||||
LIBS = []
|
||||
LIBPATH = []
|
||||
|
||||
LINKFLAGS = ""
|
||||
|
||||
|
||||
@@ -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