- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
What is the meaning of 5000 in alt_read_flash(fd, 0, dest, 5000)? I cannot understand the arguments inside alt_read_flash. I read a few articles and notes but still cannot get its meaning. pls help. thanks!Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
int alt_read_flash( alt_flash_fd* fd,
int offset, void* dest_addr, int length ); In the "Using Flash Devices" section of the Nios II SW Developers Handbook. "A call to alt_read_flash() reads from the flash device with the handle fd, offset bytes from the beginning of the flash device. The function writes the data to location pointed to by dest_addr, and the amount of data read is length. For most flash devices, you can access the contents as standard memory, making it unnecessary to use alt_read_flash()."- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hi... thanks for the reply. i am quite confused with "length". what does it mean by "amount of data read" which is "length"? is it in bytes or the number of data to be read? example, i am writing 1Mb of data to flash and want to read it out. so what should be the length for alt_write_flash and alt_read_flash?
thanks!- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It is in bytes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So, it means, if my data is 1Mb, so the length is 1Mb?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Correct. You write however many bytes you would like to read out in that field. You can look at some of the memtest examples for their usage of it as well.
You do have to play nicely with the region size though if you are managing the file locations yourself. So, don't expect to write a partial block and not have the other contents of that block erased. But that is a whole other topic kinda.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- So, it means, if my data is 1Mb, so the length is 1Mb? --- Quote End --- Be careful about 1 Mb = 1 Mega bits 1 Mb = 1 mega Bytes (1 mega octet) = 8 megabits
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, mmTsuchi. I am transferring 1MB (1 Mega Byte) of data into flash. I am using alt_write_flash. So, what should be the length in alt_write_flash. pls help. I have been debugging the whole day but still cannot understand. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
1048576, or 0x100000
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, i put that before but the return value for alt_write_flash is an error. cannot write.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What is the error code? Have you tried writing a smaller value? is there a boundry that it appears to not write on? In all my use of it i write only block_size chunks at a time. Don't know if you have to do that or not, but all my code does. So, you would have to read the regions data structure, which
alt_flash_fd* fd;
int number_of_regions;
flash_region *regions;
fd = alt_flash_open_dev(flashName);
if (!fd)
return -EACCES;
retval = alt_get_flash_info(fd, ®ions, &number_of_regions);
if (retval) {
alt_flash_close_dev(fd);
return errno;
}
Then regions->block_size contains the size of the write blocks on the flash device. ::edited to include code tags.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yes, i tried for smaller value n it works fine. i dont quite understand regarding writing in block. please help. sorry, i am new. thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Flash is structured not as one large memory but as 1-N regions and each region has 1-N blocks of a paticular size. You can not usually erase just a single byte of flash, so you have to erase the whole block, and then make any changes you need. I know, poor explanation, but google may have a better one, or altera. Either way, you have to take that into account when making a change as you may inadvertently corrupt part of a block if you try and do a partial write. But, per your other thread, if you are just doing a single write then reading back and it is failing that should not be a corruption problem. But, try only writing a block at a time, and looping until you have written all of your data. The code to get the block size is above.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks! No, it is a good explanation! i will give it a try and if cant, i will leave a msg here again.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page