当前位置:网站首页>杰理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
边栏推荐
- SaaS安全认证综合指南
- Pod环境变量和initContainer
- Pytest | skip module interface test automation framework
- leetcode-6133:分组的最大数量
- Static Pod, Pod Creation Process, Container Resource Limits
- Optimal dazzle Oracle database support what kinds of type of the time and date
- 热修复技术可谓是百花齐放
- 优炫数据库支持Oracle哪几种时间及日期类型
- navicat mysql 内存占用过高,被强制关闭
- JVM内存模型之深究模型特征
猜你喜欢
随机推荐
net stop/start mysql80 拒绝访问
GBase 8s 锁分类
SaaS安全认证综合指南
JVM 运行时数据区与JMM 内存模型详解
22 Niu Ke Duo School 1 I. Chiitoitsu (Probability dp)
POJ2421道路建设题解
pytest接口自动化测试框架 | parametrize源码解析
套接字选项
PHP获取时间戳后写数据库的一个问题
Idea 常用插件
毕业论文写作技巧
最新的Cesium和Three的整合方法(附完整代码)
Static Pod, Pod Creation Process, Container Resource Limits
Shell执行SQL发邮件
MySQL query advanced - from the use of functions to table joins, do you remember?
Microsoft Azure & NVIDIA IoT developers season I | Azure IoT & NVIDIA Jetson development foundation
app 自动化 打开app (二)
pytest接口自动化测试框架 | 执行失败跳转pdb
基于MySql,Redis,Mq,ES的高可用方案解析
[Beyond programming] When the fig leaf is lifted, when people begin to accept everything









