Nios® II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Announcements
Intel Support hours are Monday-Fridays, 8am-5pm PST, except Holidays. Thanks to our community members who provide support during our down time or before we get to your questions. We appreciate you!

Need Forum Guidance? Click here
Search our FPGA Knowledge Articles here.

Nios II UART Troubles

Altera_Forum
Honored Contributor I
995 Views

OK, I am porting some code from Nios 1 to Nios 2 and I am stuck on the UART code. Here is the original code: 

char poll_uart_rx( void ) {     int i;     i = nr_uart_rxchar( na_uart_0 );     if( i == -1 )  return( 0 );     else  return( (char) i ); } 

 

The new Nios 2 documentation says to use getchar() or getc(). These both seem to be blocking reads. I need a non-blocking read. Looking through "altera_avalon_uart.c" I found that 'alt_avalon_uart_read' supports non-blocking reads, but what newlib call do I make to get a non-blocking read? Thanks
0 Kudos
1 Reply
Altera_Forum
Honored Contributor I
59 Views

I open device uart in non blocking mode: 

 

static int fdterm; // FILEDESCRIPTOR RETURNED BY OPEN 

.. 

fdterm = open("/dev/uart1", O_RDWR | O_NONBLOCK | O_NOCTTY);  

.. 

 

 

reading is done by 

 

.. 

res=read(fdterm,uart1_tempbuff,sizeof(uart1_tempbuff)-1); 

if(res>0) { 

... we have received some bytes 

}
Reply