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.
12409 Discussions

Non blocking getchar() with Fifoed UART

Altera_Forum
Honored Contributor II
1,217 Views

Hello, 

 

I am using a Fifoed UART for reading characters from the serial interface. 

I found that getchar() is blocking when no characters are present in the fifo which I cannot use. 

Is there a way to determine if there are characters present in the read fifo. 

I can use this signal then for reading them then with getchar(). 

 

Thank you all for your responses. 

 

Regards, 

 

Wamor
0 Kudos
2 Replies
Altera_Forum
Honored Contributor II
149 Views

Hello, 

 

When I run the below code and type some characters the first line its reports the number of characters in the fifo and than reports that there are zero characters in the buffer. 

This seems strange to me because I am not reading any characters from the buffer. 

 

while ( true ) { IOWR_ALTERA_AVALON_TIMER_SNAPH(TIMER_0_BASE, 0); if ( IORD_ALTERA_AVALON_TIMER_SNAPH(TIMER_0_BASE) == 0 ) // timer overflow { words_in_fifo = IORD_FIFOED_AVALON_UART_RX_FIFO_USED( FIFOED_AVALON_UART_0_BASE ); printf("\r\n%i words in fifo, getting character\r\n", words_in_fifo ); IOWR_ALTERA_AVALON_TIMER_PERIODL(TIMER_0_BASE, 0); IOWR_ALTERA_AVALON_TIMER_PERIODH(TIMER_0_BASE, 5000); IOWR_ALTERA_AVALON_TIMER_CONTROL(TIMER_0_BASE, 0x04); putchar( XMODEM_RWC ); // send "C" count++; IOWR_ALTERA_AVALON_PIO_DATA(PIO_OUTPUT_BASE, IORD_ALTERA_AVALON_PIO_DATA(PIO_OUTPUT_BASE) ^ DEBUG_LED1); // toggle LED } } 

 

Anybody with some ideas what is wrong here.  

I want to break out of the while-loop when a certain character is received without a blocking getchar(). 

 

Thank you, 

 

Wamor
Altera_Forum
Honored Contributor II
149 Views

Hello, 

 

I have just solved my problem. I have upgraded to FIFOed-UART version 13.1 which works fine for me now. 

 

Regards, 

 

Wamor
Reply