Tool/software:
Dear experts
I used a TDA4VEN board, and when I use the select function to poll whether the current serial port is readable, it keeps returning -1.
code snap:
fd = open("/dev/ttyS2", O_RDWR | O_NONBLOCK); ret = pthread_create(&uart_read_thread,NULL,uart_read_thread_fun,&data); void *uart_read_thread_fun (void *data) { int ThreadFd = fd; struct timeval WaitTime; fd_set fds; int ReadResult=0; FD_ZERO(&fds); FD_SET(ThreadFd,&fds); WaitTime.tv_sec = 0; WaitTime.tv_usec = 100000; printf("in read thread\n"); while(1) { if(select(ThreadFd+1,&fds,0,0,&WaitTime) > 0) { ReadResult = read(ThreadFd,BufForRead,sizeof(BufForRead)); if(ReadResult > 0) { readCount++; printf("data=%s,ret=%d,read count=%ld\n",BufForRead,ReadResult,readCount); } } else { printf("read select error\n"); } } }
If don't use the select function and just read, it can read the data.
fd = open("/dev/ttyS2", O_RDWR); ret = pthread_create(&uart_read_thread,NULL,uart_read_thread_fun,&data); void *uart_read_thread_fun (void *data) { int ThreadFd = fd; struct timeval WaitTime; fd_set fds; int ReadResult=0; FD_ZERO(&fds); FD_SET(ThreadFd,&fds); WaitTime.tv_sec = 0; WaitTime.tv_usec = 100000; printf("in read thread\n"); while(1) { //if(select(ThreadFd+1,&fds,0,0,&WaitTime) > 0) //{ ReadResult = read(ThreadFd,BufForRead,sizeof(BufForRead)); if(ReadResult > 0) { readCount++; printf("data=%s,ret=%d,read count=%ld\n",BufForRead,ReadResult,readCount); } // } //else //{ // printf("read select error\n"); //} } }
So the UART port does not support non blocking access.
Is this because the kernel driver does not support it? Is there a way to make corrections.
sdk version:
ti-processor-sdk-linux-adas-j722s-evm-10_00_00_08-Linux-x86-Install.bin
Thanks.