编译RT-Smart工程下的helloworld例程成功后,直接修改的hellworld例程下的main.c代码内容,改为RT-Smart文档的UART例程,编译后出现错误,请问还要修改哪些文件,或者有什么解决方法吗
这是例程代码:
#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;
}
直接编译,出现如下错误:
[CC] main.c
In file included from /home/kaif/work/k230_rtos/src/rtsmart/rtsmart/userapps/sdk/rt-thread/include/rtlibc.h:21,
from /home/kaif/work/k230_rtos/src/rtsmart/rtsmart/userapps/sdk/rt-thread/include/rtdef.h:1130,
from /home/kaif/work/k230_rtos/src/rtsmart/rtsmart/userapps/sdk/rt-thread/include/rtthread.h:24,
from main.c:8:
/home/kaif/work/k230_rtos/src/rtsmart/rtsmart/userapps/sdk/rt-thread/include/libc/libc_signal.h:31:7: error: redefinition of 'union sigval'
31 | union sigval
| ^~~~~~
In file included from /home/kaif/work/k230_rtos/src/rtsmart/rtsmart/userapps/sdk/rt-thread/include/libc/libc_signal.h:23:
/root/.kendryte/k230_toolchains/riscv64-linux-musleabi_for_x86_64-pc-linux-gnu/riscv64-unknown-linux-musl/include/signal.h:92:7: note: originally defined here
92 | union sigval {
| ^~~~~~
/home/kaif/work/k230_rtos/src/rtsmart/rtsmart/userapps/sdk/rt-thread/include/libc/libc_signal.h:39:8: error: redefinition of 'struct sigevent'
39 | struct sigevent
| ^~~~~~~~
/root/.kendryte/k230_toolchains/riscv64-linux-musleabi_for_x86_64-pc-linux-gnu/riscv64-unknown-linux-musl/include/signal.h:179:8: note: originally defined here
179 | struct sigevent {
| ^~~~~~~~
/home/kaif/work/k230_rtos/src/rtsmart/rtsmart/userapps/sdk/rt-thread/include/libc/libc_signal.h:56:18: error: expected ':', ',', ';', '}' or '__attribute__' before '.' token
56 | union sigval si_value;
| ^~~~~~~~
/home/kaif/work/k230_rtos/src/rtsmart/rtsmart/userapps/sdk/rt-thread/include/libc/libc_signal.h:58:24: error: conflicting types for 'siginfo_t'; have 'struct siginfo'
58 | typedef struct siginfo siginfo_t;
| ^~~~~~~~~
/root/.kendryte/k230_toolchains/riscv64-linux-musleabi_for_x86_64-pc-linux-gnu/riscv64-unknown-linux-musl/include/signal.h:145:3: note: previous declaration of 'siginfo_t' with type 'siginfo_t'
145 | } siginfo_t;
| ^~~~~~~~~
make: *** [Makefile:74:/home/kaif/work/k230_rtos/output/k230d_canmv_bpi_zero_defconfig/applications/helloworld//main.o] 错误 1
请问,如何解决这个报错