Help with external memory paged writes
average joe
Posts: 795
Here's my problem. I'm working on some code for external memory and got stumped. The memory is written to in 256 byte pages. If I want to write more than 256 bytes at a time, or start in the middle of the page and write past the end I need to do multiple transfers. I'm thinking detecting one of these cases should be easy. Something like this:
I just can't figure out the fastest way to handle the extended write. This probably isn't the best description but hopefully someone can point me in the right direction.
if (memoryaddress & $FF) + count > $100 ' do extended write
I just can't figure out the fastest way to handle the extended write. This probably isn't the best description but hopefully someone can point me in the right direction.
Comments
For determining how to do the extended write you need to determine what cases need to be handled. The cases may include full page, less than full page, more than full page, starting at beginning of page, and starting mid-page. That could be a lot of cases.
Perhaps you can buffer the data so it only gets written once you have a full page.
JonnyMac wrote some very nice objects that includes a method called Page_Num which returns the page number for an address and another one called Page_OK which tells you if an address range fits in one page. There is a method called Copy_To that writes a byte at a time and another called Copy_From that reads a byte at a time.
There are several notes in the Object saying, "-- be mindful of address/page size in device to prevent page wrap-around".
@kwinn - It would be nice to be able to call one method that covers every case you mentioned. I came here for ideas because that's a lot of edge cases to cover and I'm still troubleshooting other code.
@Genetix - I think I have JM's eeprom object somewhere. I'll look through it and see if anything sparks some ideas. I'm actually using several different memories, for several different purposes. I have a 1MB i2c boot eeprom (AT24CM01), 64MB SPI FLASH(W25Q64VSIG) and 256KB SPI nvSRAM (CY14B256Q2A). I have the flash (and of course EEPROM) working for normal writes (ie not wrapping pages)
I did have some difficulties with the FLASH and SRAM. Fried a bunch of chips (still scratching my head as to why) and waiting for more SRAMs before continuing breadboard testing.
Any help would be amazing!
This seems a bit bulky, considering it won't handle an entry that wraps twice. What am I missing?
I had initially thought about it but this project requires 0 data loss. The only edge case where data loss is acceptable is if the propeller loses power between receiving a packet and handling said packet. Also, I'm worried about memory overhead. I'm already close to 80% of propeller memory full and much code left to write. There is also the issue that I can't guarantee a full page will be written. There are several types of data, stored across multiple segments of memory. Speed is not too much of an issue but code density is.
Perhaps if you post a general description of how you are handling the incoming data we could provide better suggestions. I'm guessing here but it seems like you may be using the SRAM as a data buffer to hold the incoming data until the entire packet is received and then writing it to the 64MB flash chip. Is this the case?
Thanks Dave!
len := pagesize - (chipAddr & pagemask) <# number that's exactly what I was looking for!