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++
12599 Discussions

How to tell there is data from UART?

Altera_Forum
Honored Contributor II
1,097 Views

Hi 

 

Browsing through Altera documentation suggests I should be using the HAL with a UART. 

 

So using the HAL how do I determine if there is data available from the UART before calling getchar()? I need my system to be doing other stuff and can't have it block while waiting for the UART to receive data. I can see I have to use the fast version of the driver so that the UART operates under interrupts but I can't see an equivalent to the old kbhit() function. 

 

Ta, 

 

Mike
0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
393 Views

Just an idea, can you fiddle with the driver to be able to look at the pointers for the receive buffer? Maybe you can work out a function like kbhit then. 

 

Stefaan
0 Kudos
Altera_Forum
Honored Contributor II
393 Views

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 

}
0 Kudos
Altera_Forum
Honored Contributor II
393 Views

Fischer 

 

Thanks for your reply. 

 

I managed to work it out for myself but it is nice to have confirmation from a expert that I am doing the right thing. 

 

Mike
0 Kudos
Reply