RTOS的SDK串口历程注册出错

Viewed 52

使用SDK中的历程

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/mman.h>
#include <pthread.h>
#include <fcntl.h>
#include <rtthread.h>
#include <rtdevice.h>
#include <poll.h>


#define IOC_SET_BAUDRATE            _IOW('U', 0x40, int)

struct uart_configure
{
    rt_uint32_t baud_rate;

    rt_uint32_t data_bits               :4;
    rt_uint32_t stop_bits               :2;
    rt_uint32_t parity                  :2;
    rt_uint32_t fifo_lenth              :2;
    rt_uint32_t auto_flow               :1;
    rt_uint32_t reserved                :21;
};

typedef enum _uart_parity
{
    UART_PARITY_NONE,
    UART_PARITY_ODD,
    UART_PARITY_EVEN
} uart_parity_t;

typedef enum _uart_receive_trigger
{
    UART_RECEIVE_FIFO_1,
    UART_RECEIVE_FIFO_8,
    UART_RECEIVE_FIFO_16,
    UART_RECEIVE_FIFO_30,
} uart_receive_trigger_t;
#define SEND_START_STR "uart test start !\n"
int main(int argc,char *argv[])
{
    int fd;
    int ret = 0;

    fd = open("/dev/uart3", O_RDWR); //打开串口
    if (fd < 0){
        printf("open dev  failed!\n");
        return 1;
    }

    struct uart_configure config = {
        .baud_rate = 9600,
        .data_bits = 8,
        .stop_bits = 1,
        .parity = UART_PARITY_NONE,
        .fifo_lenth = UART_RECEIVE_FIFO_16,
        .auto_flow = 0,
    };
    if (ioctl(fd, IOC_SET_BAUDRATE, &config)) { //设置参数为9600
        printf("ioctl failed!\n");
        close(fd);
        return 1;
    }
    write(fd, SEND_START_STR, strlen(SEND_START_STR)); //发送字符串口
    while(1) {
        fd_set rfds;
        int retval;

        FD_ZERO(&rfds);
        FD_SET(fd, &rfds); // 监视标准输入流

        retval = select(fd+1, &rfds, NULL, NULL, NULL);  //等待数据
        if (retval < 0) {
            printf("select failed");
            break;
        }
        if(FD_ISSET(fd, &rfds)){
            char buf[256];
            memset(buf, 0, sizeof(buf));
            ret = read(fd, buf, sizeof(buf)); //读取串口数据
            printf("ret =%x read :%s\n",ret, buf);
            if(strchr(buf,'q'))
                break;
        }
    }

    close(fd);//关闭串口
    return 0;
}

注册不成功,报错[E/uart] Invalid cmd 0x40045540
求教

1 Answers

更新了的,你是拉的rtos only的sdk吗,testcase在sec/rtsmart/libs/testcase

我想知道为啥例程会报[E/uart] Invalid cmd 0x40045540这个错误,求教大佬

历程过时了,底层驱动更新了