Forum Discussion

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

Reading and writing pio(nios) in uclinux

hi,

I have uclinux on nios,

the memory is sdram,

but now i do not know how to read or write the pio(built in sopc) in uclinux.

can anybody help me?:)

thanks a lot!

my regards,

wangyipin

4 Replies

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

    I'm not sure how it works in the latest versions of uClinux, but in the (old) version I use the build system generates a nios2_system.h header file from my .ptf that defines all my PIO addresses as a "np_pio" struct. It automatically names them na_<pio name>. You can then write/read to them directly from your application (assuming you aren't using an MMU). So, e.g., if you have a PIO named my_pio in SOPC builder then you can read/write it as follows:

    #include "nios2_system.h"
      ...
      // Reads the PIO value.
      int currvalue = na_my_pio->np_piodata;
      // Writes a new value.
      na_my_pio->np_piodata = newvalue;
      ...
    

    See the definition of the np_pio struct for info on more advanced features (e.g., bidirectional data, edge detection).
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    thanks Tristan,

    i will try, and i know the header file is the point
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    but now i do not know how to read or write the pio(built in sopc) in uclinux.

    --- Quote End ---

    In a device driver or in a user land program ?

    Using NIOS with our without MMU ?

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

    In a user program without MMU.

    What's the easiest way?

    --- Quote Start ---

    In a device driver or in a user land program ?

    Using NIOS with our without MMU ?

    -Michael

    --- Quote End ---