Altera_Forum
Honored Contributor
20 years agoUART IO
Hi:
How could I open/set flags to an Altera UART device for being used in a non-blocking manner, e.g. a call to fgetc() or fread() returns inmediately if no characters are available? Thanks a lotHi:
How could I open/set flags to an Altera UART device for being used in a non-blocking manner, e.g. a call to fgetc() or fread() returns inmediately if no characters are available? Thanks a lotWith fcntl, I believe. It wasn't implemented in versions prior to 5.0, but it should be there now. When using it, keep in mind that your file descriptors for stdin, stdout, stderr are STDIN_FILENO, etc.
Cheers, - slackerHi:
At this very moment we are still using NIOS-II with Quartus II-4.2. When looking at the UART HAL driver source code we see that a check for the flag bit O_NONBLOCK is made, so the question is how could I set this flag on. For opening the device I use fopen(). It seems to be around a unix style open() function with parameters for mode and flags. But it didnt work for me. Thanks,Hi VLorenzo,
> For opening the device I use fopen(). I rarely, if ever, use streams ... so I've never have the need for fdopen() ... but you might give it a try:int fd;
FILE *fs;
fd = open("/dev/uart1", O_RDWR | O_NONBLOCK | O_NOCTTY);
if (fd != -1) fs = dopen(fd, "rw"); And please let us know how/if it works. Regards, --ScottSorry, fat-fingered it ... that would be:
if (fd != -1) fs = fdopen (fd, "rw"); --ScottHi smcnutt,
It works fine now using the unix style open, read and write functions from "unistd.h". for opening the device: comm_uartfd = open( uart_name, O_RDWR | O_NONBLOCK | O_NOCTTY ); for writing: write( comm_uartfd, src, size ) for reading: res = read( comm_uartfd, &curr_rxd, 1 ); Thanks