当前位置:网站首页>杰理AD14N/AD15N---串口中断问题
杰理AD14N/AD15N---串口中断问题
2022-08-01 08:29:00 【JaLLs】
由于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
边栏推荐
- 三维坐标系距离
- LabVIEW中局部变量和全局变量的分配
- 22牛客多校1 I. Chiitoitsu (概率dp)
- leetcode 42. 接雨水
- [Beyond programming] When the fig leaf is lifted, when people begin to accept everything
- Pod环境变量和initContainer
- HoloView--Customization
- leetcode 42. Catch the rain
- PHP获取时间戳后写数据库的一个问题
- pytest interface automation testing framework | single/multiple parameters
猜你喜欢

类似 MS Project 的项目管理工具有哪些

【STM32】入门(二):跑马灯-GPIO端口输出控制
![[Dataset] Dataset summary of various insulators, bird's nests and anti-vibration hammers](/img/02/927f4e228eb3abbd76cade5be00352.png)
[Dataset] Dataset summary of various insulators, bird's nests and anti-vibration hammers

自定义IP在PCIE中使用

Idea common plugins
![[Beyond programming] When the fig leaf is lifted, when people begin to accept everything](/img/e1/ff8d416c99e1f370d73b9520654ddf.jpg)
[Beyond programming] When the fig leaf is lifted, when people begin to accept everything

云原生FAQ

华为深度学习课程第六、七章

【STM32】入门(一):环境搭建、编译、下载、运行

net stop/start mysql80 拒绝访问
随机推荐
灵魂发问:MySQL是如何解决幻读的?
PHP获取时间戳后写数据库的一个问题
Pytest | skip module interface test automation framework
VoLTE Basic Learning Series | Enterprise Voice Network Brief
pytest接口自动化测试框架 | parametrize中ids的用法
【编程之外】当遮羞布被掀开,当人们开始接受一切
What do the values 1, 2, and 3 in nodetype mean?
22牛客多校1 I. Chiitoitsu (概率dp)
GBase 8s 锁分类
Centos install php7.4, build hyperf, forward RDS
巧妙利用unbuffer实时写入
SAP ABAP ALV+SMARTFORS 表分页 报表打印程序
Idea 常用插件
Idea common plugins
leetcode-6132: Make all elements in array equal to zero
基于tika实现对文件类型进行判断
navicat mysql 内存占用过高,被强制关闭
【HDLBits 刷题】Circuits(1)Combinational Logic
leetcode-6133:分组的最大数量
[Tear AHB-APB Bridge by hand]~ Why aren't the lower two bits of the AHB address bus used to represent the address?