- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Does anyone know how to implement a nonblocking input function on the jtag uart on NiosII ?
On Nios I used nr_rxchar(), which returns even if there is no character waiting. The suggested replacement on NiosII is getchar(), which waits until a character is written. HavardLink Copied
7 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Should be able to read/write directly, but without the functionality that altera threw in, how would you know when your data has gone across?
Find the HAL register for the input and use it. But you're going to need some way of detecting whether you're input is valid or not. I guess you can check the recieve reg (I haven't looked at it so I have no idea if there is one or not), and pad you're data if it's not valid to something like -1 just like the RS232 did. Goodluck- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Just found a way:
// Open the device as nonblocking console_io_fi=open("/dev/uart_0",O_RDWR|O_NONBLOCK|O_NOCTTY|O_SYNC); // i returns the number of characters read i=read(console_io_fi,&ch,1); I spent some time before I realized that the terminal window integrated in the IDE does not send anything until you hit CR. -So I had to use RS232 instead.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi NiosII users,
I also need a nonblocking uart read, but I am having some trouble with the defined switches. // if I open a stream in this way: fp = fopen("/dev/uart1","r+"); //then fread(buff,sizeof(char),1,fp); // it works OK but blocks until a character is available. // but if I use the defined switch (from fcntl.h) fp = fopen("/dev/uart1","O_RDWR"); // it dosnt read or write! I wish to use: fp = fopen("/dev/uart1","O_RDWR|O_NONBLOCK"); By the way, the second argument to fopen should be of type 'const char*' (eg. "O_RDWR|O_NONBLOCK"), no t an integer produced by: O_RDWR|O_NONBLOCK fp = fopen("/dev/uart1",O_RDWR); The above line will compile with a (implicit cast) warning, but should not give correct operation. Any ideas?- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
use the "open" function and not "fopen"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So how are you compiling when you use open() ?
What are your# includes ? I don't see it defined anywhere in the NioII source tree. Likewise for fnctl.h. thanks- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I use these:
# include <unistd.h># include <stddef.h># include <fcntl.h># include <stdio.h> I believe open to be in fcntl.h- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Works great, thanks.

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