Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12603 Discussions

How write a file to harddisk by nios IDE

Altera_Forum
Honored Contributor II
1,630 Views

I want to write some data to my PC harddisk or save a file to hard disk by NiosII£¬so I write a test program in IDE, but the "test" file cannot be found.  

 

my test program 

# include "stdio.h" 

 

 

//int main (void) __attribute__ ((weak, alias ("alt_main"))); 

 

//int alt_main (void) 

int main(void) 

 

float f; 

FILE *fp;  

 

f=12.69; 

fp=fopen("test","wr+"); 

 

if(fp==NULL) 

{  

printf("cannot open file\n"); 

return 1; 

 

if(fwrite(&f,sizeof(float),1,fp)!= 1) 

printf("file write error\n"); 

return 1; 

 

fclose(fp); 

 

 

return 0; 

}
0 Kudos
5 Replies
Altera_Forum
Honored Contributor II
440 Views

How do you run the program? Please take something that the program is running in the FPGA Target board in your mind.

0 Kudos
Altera_Forum
Honored Contributor II
440 Views

pal, 

 

If you're using >=5.0, then take a look at the zipfs example. It's got some hostfs filesystem stuff. That might be what you're looking for. 

 

Other than that, you could also just dump data out your jtag_uart or uart and use 'nios2-terminal' to capture this data, on the PC, like so: 

 

nios2-terminal > <filename> 

 

Cheers, 

 

- slacker
0 Kudos
Altera_Forum
Honored Contributor II
440 Views

 

--- Quote Start ---  

originally posted by slacker@Jul 28 2005, 12:37 AM 

pal, 

 

if you&#39;re using >=5.0, then take a look at the zipfs example.  it&#39;s got some hostfs filesystem stuff.  that might be what you&#39;re looking for. 

 

other than that, you could also just dump data out your jtag_uart or uart and use &#39;nios2-terminal&#39; to capture this data, on the pc, like so: 

 

nios2-terminal > <filename> 

 

cheers, 

 

- slacker 

--- Quote End ---  

 

slacker: 

 

Thank you firstly. But I want to save some variable in my program to PC hard disk,then I have some touble in how to use the File subsystems. In software handbook : " File subsystems register themselves as mount points within the global HAL file system. Attempts to access files below that mount point are directed to that file subsystem. For example, if a zip filing subsystem is mounted as /mount/zipfs0, a call to fopen() for /mount/zipfs0/myfile is handled by the associated zipfs file subsystem." But what is the mount point? how can I define the mount point? how to use the "fopen","fread" and "fwrite" ?
0 Kudos
Altera_Forum
Honored Contributor II
440 Views

Pal, 

 

Try the example, I mentioned, first. It would also be good to read the comments available in the code. There are examples of the usage of both zipfs and hostfs and their mount points, along with the ANSI C file functions, that you had questions about, as well. 

 

You could also try installing some higher level OS, like Ecos or uCLinux, if you can tolerate the memory footprints (Damn big for Linux, much less for Ecos). These would allow you to access your hard drive using either NFS or SMB (Samba) over ethernet. 

 

Best of luck. 

 

- slacker
0 Kudos
Altera_Forum
Honored Contributor II
440 Views

Hai slacker , 

 

as if u told , I tried to use HOSTFS in Window NT os , in NIOS II IDE 5.0v , 

 

as per the instruction i follow ,but i cant make it ... 

 

can u tell me is there any option to be enable in sopc builder while generating .bdf file(block diagram file).. 

 

 

pls reply soon ..
0 Kudos
Reply