- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Any idea what is wrong with the code below? The code failed to create the sample.txt file. Runtime error.
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <sys/types.h> #include <sys/stat.h> int main(void){ const void *str = "hello\n"; size_t count; FILE *fp = open("sample.txt", O_WRONLY); printf("Opening file sample.txt\n"); if(fp == null) {printf("Open failed");return EXIT_FAILURE; } else {printf("Open succeeded\n"); } printf("Writing to file ...\n"); count = write(fp, str, strlen(str)); // x, [/INDENT]printf("Writing completed \n"); close(fp); return EXIT_SUCCESS;}Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Where do you expect the file to be created? What operating system do you run the Nios on?
If you have installed a writeable filesystem, I guess you'd at least have to give an absolute path.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Em. I expect the file to be created in the same location as the source code (the .c file). Currently the Nios II IDE is run on a Windows machine. I am not sure how to give an absolute path in the windows machine. It doesn't seem to be working.
Thanks for replying.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It doesn't work that way. The code is executed on the Nios CPU, not on the PC, and the Nios system is not able to create a file on the PC. If you want to transfer data from the Nios system to your PC, you'll have to make your own protocol (or print text on the Jtag UART interface and copy-paste, if you don't have a lot to transfer).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oh. I figured that i will use the zip file system and program it to the flash. To open the file for reading i will use;
fopen("/mnt/rozipfs/sample.txt","r"); and to write to the sample.txt file i will use something like alt_write_flash_block ... I am trying this out. Not sure if it will work.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I managed to store my file (.txt) using the zip filesystem and then read from it. Apart from that, I also need to write to the file.
My question is: 1. How to store a .txt file in flash after writing to it? I am not sure if my understanding on the file operations of nios ii is correct. Thanks for the help.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The zip filesystem is read only, and I'm not sure there is a filesystem with write support available for the Altera HAL. You may have to move to ucLinux or eCos, or try to port a filesystem code you can find on the net (such as fatfs (http://code.google.com/p/minini/wiki/fatfs)) to Nios.
You can also use alt_write_flash_block to write, but it will be written as a bsoc, not as a filesystem entry. You would need to read it back with alt_read_flash_block.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oh. Is ucLinux/ eCos open source? Will look it up now.
How about MicroC/OS-II? Thanks for the hint, I was getting stuck and wasting time going around nowhere. Been a few days now.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I don't know if uc/OS-II has a filesystem with write. I know that uCLinux and eCos do, but they require more work (and time) before being usable. You need to get familiar with the environment and the building process.
What type of flash memory are you using and why do you need a file system? Depending on what you want to do, it could be a lot easier to just use the block i/o functions.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Actually my project takes in parameters and generates a bmp file. I am utilizing the hardware acceleration to compare the time taken to complete the bmp iterations.
The problem is how do i create the bmp file? Write the bit values to flash? And how do i retrieve it? I am at the stage where i am still finding out on how to implement it and exploring the options. I do not have a clear picture yet.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You'd probably have to create a protocol between your FPGA and a PC to retrieve the file. Anything between serial and Ethernet, depending on the file size and your speed requirements.
I think you could also use the altera console tools to directly access the Nios CPU's RAM but I've never done it and don't know how this works.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page