Forum Discussion
Altera_Forum
Honored Contributor
10 years agoHaving a quick look at your code I don't see anything wrong. Now let's look for less obvious bugs.
In epcs open, is the information returned by the function correct (number of blocks, block size) ? I see in epcs_open() that you close the flash device after being finished with it. Do you reopen it before the call to the next two functions ? If yes are you sure you are reopening it with the same path? It seems that "fd" in epcs_open() is a global variable, whereas it is a local variable in Write_flash and Read_flash. If all those functions are in the same file it can create a confusion, where a local variable takes precedence over the global one. I suggest removing the global variable and make fd local in epcs_open() (or make epcs_open return it if you don't want to close it). Could you show the result of your printf's? Do you get the same wrong values each time, or are they different ? What value are you using for the test_offset? Are you sure it is not out of bounds, given the size of the flash you are using? Try putting some printf's at the beginning of Write_flash and Read_flash to check that both functions are using the same values for fd and test_offset. Hope this helps...