AliOS-Things--EMW3060 (9)uart

串口文件:platform\mcu\moc108\hal\uart.c
串口头文件:kernel\rhino\hal\soc\uart.h

串口例程:

#include <stdio.h>
#include <aos/aos.h>
#include <../../../kernel/rhino/hal/soc/uart.h> 

#define DEMO_TASK_STACKSIZE  2048
#define DEMO_TASK_PRIORITY   20
#define UART_DATA_BYTES      10
char  readbuf[UART_DATA_BYTES] = {0};

static uart_dev_t qc_uart;
static uart_dev_t qc_uart1; 

static void uart_poll_func(void *arg)
{
    uint32_t recBytes = 0;
    int ret = -1;

    ret = hal_uart_recv_II(&qc_uart1, readbuf, 1, &recBytes, 10);

    if ((ret == 0) && (recBytes > 0))
    {
        hal_uart_send(&qc_uart1, readbuf, recBytes, 10);
    }

    aos_post_delayed_action(0, uart_poll_func, NULL);
}

void uart_task(void* p)
{
    aos_schedule_call(uart_poll_func, NULL);
}

int application_start(int argc, char *argv[])
{
    qc_uart.port                     = 0;
    qc_uart.config.baud_rate         = 9600;
    qc_uart.config.data_width        = DATA_WIDTH_8BIT;
    qc_uart.config.parity            = NO_PARITY;
    qc_uart.config.stop_bits         = STOP_BITS_1;
    qc_uart.config.flow_control      = FLOW_CONTROL_DISABLED;
    hal_uart_init(&qc_uart);

    qc_uart1.port                     = 1;
    qc_uart1.config.baud_rate         = 9600;
    qc_uart1.config.data_width        = DATA_WIDTH_8BIT;
    qc_uart1.config.parity            = NO_PARITY;
    qc_uart1.config.stop_bits         = STOP_BITS_1;
    qc_uart1.config.flow_control      = FLOW_CONTROL_DISABLED;
    hal_uart_init(&qc_uart1);

    aos_task_new("uart_test", uart_task, NULL, 4096);

    aos_loop_run();

    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值