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

How to set stdin to nonblocking

Altera_Forum
Honored Contributor II
1,300 Views

How do I set nonblocking mode for stdin (a standard uart) using the HAL? After wading through hunderds of pages of useless Altera info and library sources, I still can't find that simple piece of information.  

 

<rant> 

It could be me, but I find this whole HAL/Posix compliance thing one big pile of useless, horribly documented useless junk that frustates the hell out of me, that instead of saving me time, only cost me more time. 

</rant> 

 

Thanks, 

 

Jeroen
0 Kudos
4 Replies
Altera_Forum
Honored Contributor II
597 Views

int fdterm; // FILEDESCRIPTOR RETURNED BY OPEN 

FILE * fpterm; // FILE pointer returned by fdopen 

 

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

fpterm=fdopen(fdterm,"rw+"); 

 

... 

uart1_rxcount=read(fdterm,uart1_rxbuffer,UART1_RXBUFFERSIZE-1); 

if(uart1_rxcount>0) { 

...something received 

fprintf(fpterm,"received:%s\r\n",uart1_rxbuffer); 

...
0 Kudos
Altera_Forum
Honored Contributor II
597 Views

<div class='quotetop'>QUOTE </div> 

--- Quote Start ---  

How do I set nonblocking mode for stdin (a standard uart) using the HAL? After wading through hunderds of pages of useless Altera info and library sources, I still can&#39;t find that simple piece of information.  

 

<rant> 

It could be me, but I find this whole HAL/Posix compliance thing one big pile of useless, horribly documented useless junk that frustates the hell out of me, that instead of saving me time, only cost me more time. 

</rant>[/b] 

--- Quote End ---  

 

The information you sought was in chapter 10 page 60 of the Nios II Software Devlopers Handbook n2sw_nii5v2.pdf. This is the description of the open() function call. It was the first thing that a search of this manual found when searching for NONBLOCK. 

 

"You may also bitwise-OR flags with O_NONBLOCK, which causes the file to be 

opened in non-blocking mode. Neither open() nor any subsequent operations 

on the returned file descriptor causes the calling process to wait." 

 

As for your rant, it would be much more beneficial to all if you could post problems you have encountered, that way we can try to fix them.
0 Kudos
Altera_Forum
Honored Contributor II
597 Views

Ideally, one could change the blocking status of STDIN instead of making another file descriptor and updating all of the calls to printf with the new file descriptor. 

 

I have heard that support for the fcntl call will be added in a future release. That functionality would be very helpful. 

 

As far as the original post, there isn&#39;t a way that I can see of changing STDIN to non blocking. Only a way to create a new file descriptor which is non blocking. 

 

However, I am still impressed with the depth of the HAL and I am looking forward to the refinements that Altera is providing. 

 

regards,
0 Kudos
Altera_Forum
Honored Contributor II
597 Views

Apparently you have a newer version of the handbook, as page 60 describes lseek and open is not described; searching for NONBLOCK gives no hits. I should have checked for updates http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/tongue.gif  

 

I got it more or less working now; I have to combine the data from/to the UART with an EPP port http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/blink.gif  

 

About the rant, it just was one of those days nothing seems to work. For the rest, I&#39;m a happy Altera customer. 

 

Thanks, 

 

Jeroen
0 Kudos
Reply