Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
21 years ago

Nios II, nonblocking i/o, anyone

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.

Havard

7 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I use these:

    # include <unistd.h># include <stddef.h># include <fcntl.h># include <stdio.h>

    I believe open to be in fcntl.h