Forum Discussion

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

using open() C command in the Nios II

Hi,

can we used open() and printf() C commands to save stream of data in the Nios II?

when I used fp=open() Command, it send Null to fp pointer.How can I store my integer data?

Thanks

13 Replies

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

    In addition to the fopen() call in Newlib, you need a file system behind it, and a block device (sd card) behind that. All of that hardware, software and data must be in place and integrated together before the fopen() call will actually do what you expect. Typically this is handled by an operating system (Linux, Windows embedded, VxWorks, etc). In a bare metal situation you need to get all that code and integrate it together. Usually it's easier to just use a UART if the data rate is slow enough.

    You can write binary bytes to your UART if instead of PuTTy etc or system console for the JTAG UART, you run a program or script on your PC to capture binary bytes. Watch out for garbage characters transmitted at power-up.

    Don't forget to account for the start and stop bits. You are actually sending 10 bits serially for every byte given to the UART. I don't know if the JTAG UART can keep up at that rate.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Altera supplies the "Host-Based File System" (altera_hostfs) that allows your NIOS HAL-based software to fopen()/fwrite() files that reside on your PC (while connected through JTAG, obviously). You can use this for the temporary kind of logging/debugging it sounds like you are trying to accomplish.

    The Altera System Console also provides services for transferring data to/from your target which may be better suited if you are trying to construct an in-hardware test environment. See http://www.alterawiki.com/wiki/system_console_byte_stream_example for one example.