由于AD15的SDK中,uart_dev.c文件中没有串口中断的demo,所以之前的项目一直用read的方式去读串口数据,但是这种读的方式是阻塞的方式,所以不太好用,今天做了个项目,也要用到串口,于是又研究了以下AD15的串口中断问题,摸索了下调通了代码如下:
#include "app_config.h"
#include "includes.h"
#include "asm/power_interface.h"
#include "asm/power/p33.h"
#include "cpu.h"
#include "uart_dev.h"
#define LOG_TAG_CONST NORM
#define LOG_TAG "[uart]"
#include "debug.h"
#if 1
#include "typedef.h"
#define DMA_BUF_LEN2 64
static u8 tmp_buf[DMA_BUF_LEN2] = {0};
static u8 usr_uart_buf[DMA_BUF_LEN2] __attribute__((aligned(4)));
static const uart_bus_t *ut0 = NULL;
extern const uart_bus_t *uart_dev_open(const struct uart_platform_data_t *arg);
void usr_uart_recieve(u8*data,u16 len);
static void usr_uart_isr_hook(void *arg, u32 status)
{
const uart_bus_t *ubus = arg;
if (status == UT_RX_OT) {
u32 len = ubus->read(tmp_buf, 64, 0);
if (len != 0) {
usr_uart_recieve(tmp_buf,len);
// log_info("uart_rx_ot len : %d", len);
// log_info_hexdump(tmp_buf, len);
}
}
}
static int uart_dev_init(const uart_bus_t *ut)
{
memset((void *)usr_uart_buf, 0, sizeof(usr_uart_buf));
struct uart_platform_data_t arg;
arg.tx_pin = IO_PORTA_06;
arg.rx_pin = IO_PORTA_07;
arg.rx_cbuf = usr_uart_buf;
arg.rx_cbuf_size = 64;//
arg.frame_length = 64;//
arg.rx_timeout = 20;
arg.isr_cbfun = usr_uart_isr_hook;
arg.argv = JL_UT0;
arg.is_9bit = 0;
arg.baud = 115200;
ut = uart_dev_open(&arg);
if (NULL != ut) {
return 0;
} else {
return -1;
}
}
void usr_uart_init(void)
{
if (0 != uart_dev_init(ut0)) {
log_info("######uart_usr init fail!\n");
return;
}
}
static void UT0_putbyte(char a)
{
if (JL_UT0->CON & BIT(0)) {
JL_UT0->BUF = a;
__asm__ volatile("csync");
if ((JL_UT0->CON & BIT(2)) == 0) {
while ((JL_UT0->CON & BIT(15)) == 0);
JL_UT0->CON |= BIT(13);
}
}
}
void usr_uart_send(u8* data,u16 len)///串口1发送函数
{
u16 i=0;
for (i = 0; i < len; i ++) {
UT0_putbyte(*(data + i));
}
}
void usr_uart_recieve(u8*data,u16 len)///串口1接收回调函数
{
log_info("uart_recieve_len: %d\n",len);
log_info_hexdump(data, len);
}
#endif
工程中需要包含uart_dev.c
另外要注意串口0不支持DMA,串口1可支持DMA.
方案开发,技术交流可联系微信:life5270