- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How can I do nonblocking io with uart
I have a singlethread enviroment and need nonblocking io for uart I tried the following code, but it does not work correctly int fd; fd = open("/dev/uart_0", O_RDWR | O_NONBLOCK); while(1) { res=read(fd,test,25); // res=fgets(test,25,fd); // res=fread(test,1,25,fd); if(res>0) { for(i=0;i<res;i++) { if(test=='\r') {*prxbuff=0;
printf("rx:count:%d:<%s>\r\n",rxcount,rxbuff);
rxcount=0;
prxbuff=rxbuff;
}
else {
*prxbuff++=test; rxcount++; } } } Sorry I´ve forgot to append the output of the code. the output of the above code is sometimes missing some characters, however the uart works correct, echo of uart is ok. output in terminal: TestRS232 RX:COUNT:8:<TesRS232> TestRS232 RX:COUNT:9:<TestRS232> TestRS232 RX:COUNT:7:<estRS32> TestRS232 RX:COUNT:8:<TestR232> TestRS232 RX:COUNT:8:<TestS232> TestRS232 RX:COUNT:9:<TestRS232> TestRS232 RX:COUNT:8:<TestRS22> TestRS232 RX:COUNT:8:<TestR232> TestRS232 RX:COUNT:7:<TstRS22> TestRS232 RX:COUNT:7:<TstRS22> TestRS232 RX:COUNT:8:<TesRS232> TestRS232 RX:COUNT:8:<TesRS232>
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ummm.... I see where you're opening your file handle, but I don't see that you use it anywhere, unless I'm missing something.
I'm no C expert, but I believe that *only* your "fd" file descriptor will have the non-blocking option set. Also, do you happen to have the "Reduced device drivers" box checked on the system library project associated with this code? If so, the following comment from the uart device driver could be exactly what you're seeing: * This implementation polls the device waiting for characters. At most it can
* only return one character, regardless of how many are requested. If the
* device is being accessed in non-blocking mode then it is possible for this
* function to return without reading any characters. In this case errno is
* set to EWOULDBLOCK.
*/
FYI: You can find the source code for this driver in the Nios II Device Drivers project from within the IDE... Nios II Device Drivers/altera_avalon_uart/HAL/src/altera_avalon_uart.c Cheers, - slacker
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The filedescriptor is used in the "read" function and the read function returns
immediatly with res=0, if no characters are available. I don't want to use the reduced drivers. I found no example and no register description in the altera documentation. I' have read the "linux serial programming howto", but there must be some differences in programming with NIOSII ???.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
!!! I tested the code on a NIOSII cyclone dev.kit board and it works. !!!
It seems that I have a hardware problem with my "testboard EP1C6" Thanks
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page