AliOS-Things--EMW3060 (9)uart

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_28877125/article/details/83310088

串口文件: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;
}

猜你喜欢

转载自blog.csdn.net/qq_28877125/article/details/83310088