杰理AD14N/AD15N---串口中断问题

由于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

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

JaLLs

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值