- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
this may be a very beginner question, but I cannot get ahead. I have a loop wich should be performed until the user presses 'q'. I tried with getchar() but it seems that getchar() waits for a return and my loop is not performed anymore. So I'm looking for a command which is not waiting for a return, or maybe a command who tells me if the uart buffer is empty or not. Thank you for each suggestion, Ralfdo
{
printf( "do something" );
} while( getchar() != 'q' );
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This happens because the default STDIN is blocking; it waits for an input before returning a value. To make the system do what you want you must make it a non-blocking call. If you are using the 5.0 release of Nios II you can use the fcntl call and change STDIN to non blocking (O_NONBLOCK flag). If you are using an earlier release, you can change the flags directly or create a new file handle for the serial line and create to be non-blocking.
Hope this helps. Michael- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you very much, works fine now.
My code:int32 KeyPressed( void )
{
int32 key = -1;
int32 flags;
/* save flags */
flags = fcntl( fileno(stdin), F_GETFL );
/* set non blocking */
if( ! fcntl( fileno(stdin), F_SETFL, flags | O_NONBLOCK ) );
{
key = getchar();
}
/* restore flags */
fcntl( fileno(stdin), F_SETFL, flags );
return( key );
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
This code works with Quartus II 9.0 using the JTAG uart but failed when I use an UART core. Have you an idea to allow non-blocking with the UART corre from ALTERA ??
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page