Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

UART IO

Altera_Forum
Honored Contributor II
1,416 Views

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 lot
0 Kudos
5 Replies
Altera_Forum
Honored Contributor II
421 Views

With 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, 

 

- slacker
0 Kudos
Altera_Forum
Honored Contributor II
421 Views

Hi: 

 

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,
0 Kudos
Altera_Forum
Honored Contributor II
421 Views

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, 

--Scott
0 Kudos
Altera_Forum
Honored Contributor II
421 Views

Sorry, fat-fingered it ... that would be: 

 

if (fd != -1) fs = fdopen (fd, "rw"); 

 

--Scott
0 Kudos
Altera_Forum
Honored Contributor II
421 Views

Hi 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
0 Kudos
Reply